]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/damon/sysfs: use DAMON core API damon_is_running()
authorSeongJae Park <sj@kernel.org>
Sat, 5 Jul 2025 17:49:58 +0000 (10:49 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 20 Jul 2025 01:59:44 +0000 (18:59 -0700)
DAMON core implements a static function to see if a given DAMON context is
running.  DAMON sysfs interface is implementing the same one on its own.
Make the core function non-static and reuse it from the DAMON sysfs
interface.

Link: https://lkml.kernel.org/r/20250705175000.56259-5-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/damon.h
mm/damon/core.c
mm/damon/sysfs.c

index bb58e36f019e63d477d28366ff42ac84740868e2..e1fea3119538ff53576392d91524c55690729d30 100644 (file)
@@ -934,6 +934,7 @@ static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs
 
 int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive);
 int damon_stop(struct damon_ctx **ctxs, int nr_ctxs);
+bool damon_is_running(struct damon_ctx *ctx);
 
 int damon_call(struct damon_ctx *ctx, struct damon_call_control *control);
 int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control);
index e8036254cc987c30c4043279f27dece1cc7c3777..c66583869e95c9d9bd946a5ac12c4c6989517fdd 100644 (file)
@@ -1311,7 +1311,13 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs)
        return err;
 }
 
-static bool damon_is_running(struct damon_ctx *ctx)
+/**
+ * damon_is_running() - Returns if a given DAMON context is running.
+ * @ctx:       The DAMON context to see if running.
+ *
+ * Return: true if @ctx is running, false otherwise.
+ */
+bool damon_is_running(struct damon_ctx *ctx)
 {
        bool running;
 
index 1b1476b79cdbada707736818f02689285c422dbb..79d65dcc9dd03a940624b765d67795983bb55560 100644 (file)
@@ -1189,16 +1189,6 @@ static void damon_sysfs_kdamond_rm_dirs(struct damon_sysfs_kdamond *kdamond)
        kobject_put(&kdamond->contexts->kobj);
 }
 
-static bool damon_sysfs_ctx_running(struct damon_ctx *ctx)
-{
-       bool running;
-
-       mutex_lock(&ctx->kdamond_lock);
-       running = ctx->kdamond != NULL;
-       mutex_unlock(&ctx->kdamond_lock);
-       return running;
-}
-
 /*
  * enum damon_sysfs_cmd - Commands for a specific kdamond.
  */
@@ -1275,7 +1265,7 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
        if (!ctx)
                running = false;
        else
-               running = damon_sysfs_ctx_running(ctx);
+               running = damon_is_running(ctx);
 
        return sysfs_emit(buf, "%s\n", running ?
                        damon_sysfs_cmd_strs[DAMON_SYSFS_CMD_ON] :
@@ -1429,7 +1419,7 @@ static inline bool damon_sysfs_kdamond_running(
                struct damon_sysfs_kdamond *kdamond)
 {
        return kdamond->damon_ctx &&
-               damon_sysfs_ctx_running(kdamond->damon_ctx);
+               damon_is_running(kdamond->damon_ctx);
 }
 
 static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,