Skip to contentSkip to conversation

mm/damon/stat: add kdamond_pid parameter

RFC PATCH In review SeongJae Park 2 participants 5 messages Apr 14 – Apr 15

Subsystems (4)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover 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.

Changes from RFC
- rfc: https://lore.kernel.org/[email protected]
- Fix damon_kdamond_pid() failure handling.

SeongJae Park (2):
mm/damon/stat: add a parameter for reading kdamond pid Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter

 Documentation/admin-guide/mm/damon/stat.rst |  7 +++++++
 mm/damon/stat.c                             | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)

base-commit: 02784c37a710fa3c8c3e7be4f27a5cfa3356dc00

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

RFC PATCH 1/2 mm/damon/stat: add a parameter for reading kdamond pid

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.

---
 mm/damon/stat.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
mm/damon/stat.c +17 -0
index 99ba346f9e325..510c593a313b8 100644
@@ -44,6 +44,15 @@ module_param(aggr_interval_us, ulong, 0400);
 MODULE_PARM_DESC(aggr_interval_us,
 		"Current tuned aggregation interval in microseconds");
 
+/*
+ * PID of the DAMON thread
+ *
+ * If DAMON_STAT is enabled, this becomes the PID of the worker thread.
+ * Else, -1.
+ */
+static int kdamond_pid __read_mostly = -1;
+module_param(kdamond_pid, int, 0400);
+
 static struct damon_ctx *damon_stat_context;
 
 static unsigned long damon_stat_last_refresh_jiffies;
@@ -260,6 +269,13 @@ static int damon_stat_start(void)
 		damon_stat_context = NULL;
 		return err;
 	}
+	kdamond_pid = damon_kdamond_pid(damon_stat_context);
+	if (kdamond_pid < 0) {
+		err = kdamond_pid;
+		kdamond_pid = -1;
+		damon_destroy_ctx(damon_stat_context);
+		damon_stat_context = NULL;
+		return err;
 
 	damon_stat_last_refresh_jiffies = jiffies;
 	call_control.data = damon_stat_context;
@@ -269,6 +285,7 @@ static int damon_stat_start(void)
 static void damon_stat_stop(void)
 {
 	damon_stop(&damon_stat_context, 1);
+	kdamond_pid = -1;
 	damon_destroy_ctx(damon_stat_context);
 	damon_stat_context = NULL;
 }
Signature · 1 line
2.47.3
#2 lore raw

Re: [RFC PATCH v1.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid

Sashiko AI review found 1 potential issue(s): - [Low] Missing closing brace `}` in `damon_stat_start()` error path causes compilation failure. --

Sashiko AI review found 1 potential issue(s):
- [Low] Missing closing brace } in damon_stat_start() error path causes compilation failure. --

commit 04b7136ae6b7cd907673996f57f0a613de1984b9
Author: SeongJae Park <[email protected]>

mm/damon/stat: add a parameter for reading kdamond pid

This commit exposes the pid of the DAMON_STAT kdamond via a new read-only module parameter named kdamond_pid to help user-space management and monitoring.

Quoted 3 lines
mm/damon/stat.c +0 -0

[ ... ]

mm/damon/stat.c static int damon_stat_start(void) · line 278

Quoted 11 lines
mm/damon/stat.c +7 -0
@@ -260,6 +269,13 @@ static int damon_stat_start(void)
 		damon_stat_context = NULL;
 		return err;
 	}
+	kdamond_pid = damon_kdamond_pid(damon_stat_context);
+	if (kdamond_pid < 0) {
+		err = kdamond_pid;
+		kdamond_pid = -1;
+		damon_destroy_ctx(damon_stat_context);
+		damon_stat_context = NULL;
+		return err;

Is there a missing closing brace for the if (kdamond_pid < 0) block here? It looks like the omission will swallow the rest of the function into the error path and cause a compilation failure.

Quoted 3 lines
mm/damon/stat.c +0 -0
 	damon_stat_last_refresh_jiffies = jiffies;
 	call_control.data = damon_stat_context;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

Re: [RFC PATCH v1.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid

Quoted 19 lines · On Wed, 15 Apr 2026 00:16:14 +0000 [email protected] wrote:

Sashiko AI review found 1 potential issue(s):
- [Low] Missing closing brace } in damon_stat_start() error path causes compilation failure. --

commit 04b7136ae6b7cd907673996f57f0a613de1984b9
Author: SeongJae Park <[email protected]>

mm/damon/stat: add a parameter for reading kdamond pid

This commit exposes the pid of the DAMON_STAT kdamond via a new read-only module parameter named kdamond_pid to help user-space management and monitoring.

Quoted 3 lines
mm/damon/stat.c +0 -0

[ ... ]

Quoted 15 lines

mm/damon/stat.c static int damon_stat_start(void) · line 278

Quoted 11 lines
mm/damon/stat.c +7 -0
@@ -260,6 +269,13 @@ static int damon_stat_start(void)
 		damon_stat_context = NULL;
 		return err;
 	}
+	kdamond_pid = damon_kdamond_pid(damon_stat_context);
+	if (kdamond_pid < 0) {
+		err = kdamond_pid;
+		kdamond_pid = -1;
+		damon_destroy_ctx(damon_stat_context);
+		damon_stat_context = NULL;
+		return err;

Is there a missing closing brace for the if (kdamond_pid < 0) block here? It looks like the omission will swallow the rest of the function into the error path and cause a compilation failure.

Good eye. I will fix this in the next revision.

Thanks,
SJ

[...]

author maintainer
#4 lore raw

RFC PATCH 2/2 Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter

In reply to SeongJae Park

Update DAMON_STAT usage document for newly added kdamond_pid parameter.

---
 Documentation/admin-guide/mm/damon/stat.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/admin-guide/mm/damon/stat.rst +7 -0
index c4b14daeb2dd6..46c5dd96aa2ed 100644
@@ -89,3 +89,10 @@ percentiles of the idle time values via this read-only parameter.  Reading the
 parameter returns 101 idle time values in milliseconds, separated by comma.
 Each value represents 0-th, 1st, 2nd, 3rd, ..., 99th and 100th percentile idle
 times.
+
+kdamond_pid
+-----------
+
+PID of the DAMON thread.
+
+If DAMON_STAT is enabled, this becomes the PID of the worker thread.  Else, -1.
Signature · 1 line
2.47.3