]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/damon/stat: add a parameter for reading kdamond pid
authorSeongJae Park <sj@kernel.org>
Sat, 2 May 2026 02:05:03 +0000 (19:05 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:05:08 +0000 (21:05 -0700)
Patch series "mm/damon/stat: add kdamond_pid parameter".

DAMON_STAT doesn't provide the pid of its kdamond, unlike DAMON_RECLAIM
and DAMON_LRU_SORT.  This makes user-space management of DAMON_STAT
unnecessarily complicated.  Provide the information via a new parameter,
namely kdamond_pid, and document it.

This patch (of 2):

Knowing the pid of the kdamonds can help user-space management including
monitoring of DAMON's system resource consumption.  To make it easier,
DAMON_SYSFS, DAMON_RECLAIM and DAMON_LRU_SORT provide the pid information.
DAMON_STAT is not providing it, though.  Expose the pid of DAMON_STAT
kdamond via a new read-only module parameter, namely kdamond_pid.  This
also makes DAMON modules usage more standardized, because DAMON_RECLAIM
and DAMON_LRU_SORT also provide the information via their read-only
parameters of the same name.

Link: https://lore.kernel.org/20260502020505.80822-1-sj@kernel.org
Link: https://lore.kernel.org/20260502020505.80822-2-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/stat.c

index f4d3203e92639a9fc83fac1ee1f8ba7d797206b9..0e14f5bb8f75d9ff7386d93c34aa88c1def3390d 100644 (file)
@@ -266,6 +266,45 @@ static int damon_stat_enabled_load(char *buffer, const struct kernel_param *kp)
        return sprintf(buffer, "%c\n", damon_stat_enabled() ? 'Y' : 'N');
 }
 
+static int damon_stat_kdamond_pid_store(
+               const char *val, const struct kernel_param *kp)
+{
+       /*
+        * kdamond_pid is read-only, but kernel command line could write it.
+        * Do nothing here.
+        */
+       return 0;
+}
+
+static int damon_stat_kdamond_pid_load(
+               char *buffer, const struct kernel_param *kp)
+{
+       int pid;
+
+       if (!damon_stat_context) {
+               pid = -1;
+       } else {
+               pid = damon_kdamond_pid(damon_stat_context);
+               if (pid < 1)
+                       pid = -1;
+       }
+       return sprintf(buffer, "%d\n", pid);
+}
+
+static const struct kernel_param_ops kdamond_pid_param_ops = {
+       .set = damon_stat_kdamond_pid_store,
+       .get = damon_stat_kdamond_pid_load,
+};
+
+/*
+ * PID of the DAMON thread
+ *
+ * If DAMON_STAT is enabled, this becomes the PID of the worker thread.
+ * Else, -1.
+ */
+module_param_cb(kdamond_pid, &kdamond_pid_param_ops, NULL, 0400);
+MODULE_PARM_DESC(kdamond_pid, "pid of the kdamond");
+
 static int __init damon_stat_init(void)
 {
        int err = 0;