DAMON development mailing list
 help / color / mirror / Atom feed
* [RFC PATCH v2.1 0/2] mm/damon/stat: add kdamond_pid parameter
@ 2026-04-30 14:20 SeongJae Park
  2026-04-30 14:20 ` [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid SeongJae Park
  2026-04-30 14:20 ` [RFC PATCH v2.1 2/2] Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter SeongJae Park
  0 siblings, 2 replies; 5+ messages in thread
From: SeongJae Park @ 2026-04-30 14:20 UTC (permalink / raw)
  Cc: SeongJae Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
	Jonathan Corbet, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, damon, linux-doc,
	linux-kernel, linux-mm

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 v2
- v2: https://lore.kernel.org/20260425203309.108879-1-sj@kernel.org
- Rebase to latest mm-new.
Changes from RFC v1.2
- rfc v1.2: https://lore.kernel.org/20260416002149.87090-1-sj@kernel.org
- Detect and use fresh kdamond pid.
Changes from RFC v1.1
- rfc v1.1: https://lore.kernel.org/20260414235912.98174-1-sj@kernel.org
- Close the parentheses of error handling block.
Changes from RFC
- rfc: https://lore.kernel.org/20260414053742.90296-1-sj@kernel.org
- 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                             | 38 +++++++++++++++++++++
 2 files changed, 45 insertions(+)


base-commit: b8e00b62c650b2aa471195f663301118fde889c2
-- 
2.47.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid
  2026-04-30 14:20 [RFC PATCH v2.1 0/2] mm/damon/stat: add kdamond_pid parameter SeongJae Park
@ 2026-04-30 14:20 ` SeongJae Park
  2026-04-30 15:14   ` sashiko-bot
  2026-04-30 14:20 ` [RFC PATCH v2.1 2/2] Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter SeongJae Park
  1 sibling, 1 reply; 5+ messages in thread
From: SeongJae Park @ 2026-04-30 14:20 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, linux-kernel, linux-mm

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.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/stat.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/mm/damon/stat.c b/mm/damon/stat.c
index f4d3203e92639..37964683839d0 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -266,6 +266,44 @@ 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);
+
 static int __init damon_stat_init(void)
 {
 	int err = 0;
-- 
2.47.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH v2.1 2/2] Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter
  2026-04-30 14:20 [RFC PATCH v2.1 0/2] mm/damon/stat: add kdamond_pid parameter SeongJae Park
  2026-04-30 14:20 ` [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid SeongJae Park
@ 2026-04-30 14:20 ` SeongJae Park
  1 sibling, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2026-04-30 14:20 UTC (permalink / raw)
  Cc: SeongJae Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
	Jonathan Corbet, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, damon, linux-doc,
	linux-kernel, linux-mm

Update DAMON_STAT usage document for newly added kdamond_pid parameter.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/admin-guide/mm/damon/stat.rst | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/admin-guide/mm/damon/stat.rst b/Documentation/admin-guide/mm/damon/stat.rst
index c4b14daeb2dd6..46c5dd96aa2ed 100644
--- a/Documentation/admin-guide/mm/damon/stat.rst
+++ b/Documentation/admin-guide/mm/damon/stat.rst
@@ -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.
-- 
2.47.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid
  2026-04-30 14:20 ` [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid SeongJae Park
@ 2026-04-30 15:14   ` sashiko-bot
  2026-05-01  1:04     ` SeongJae Park
  0 siblings, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-04-30 15:14 UTC (permalink / raw)
  To: SeongJae Park; +Cc: damon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added `kdamond_pid` module parameter lacks a `MODULE_PARM_DESC` declaration.
--

commit d56734720ba3e7838cd85a1ac6661cf5e54d9a3b
Author: SeongJae Park <sj@kernel.org>

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

Expose the pid of DAMON_STAT kdamond via a new read-only module parameter
named kdamond_pid. This standardizes DAMON module usage, as DAMON_RECLAIM
and DAMON_LRU_SORT also provide this information.

> diff --git a/mm/damon/stat.c b/mm/damon/stat.c
> index f4d3203e92639..37964683839d0 100644
> --- a/mm/damon/stat.c
> +++ b/mm/damon/stat.c
[ ... ]
> +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);

This isn't a bug, but should this module parameter include a MODULE_PARM_DESC()
declaration?

Other parameters in mm/damon/stat.c like enabled, estimated_memory_bandwidth,
and memory_idle_ms_percentiles have corresponding MODULE_PARM_DESC()
declarations.

> +
>  static int __init damon_stat_init(void)
>  {
>  	int err = 0;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260430142013.80993-1-sj@kernel.org?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid
  2026-04-30 15:14   ` sashiko-bot
@ 2026-05-01  1:04     ` SeongJae Park
  0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2026-05-01  1:04 UTC (permalink / raw)
  To: sashiko-bot; +Cc: SeongJae Park, damon

On Thu, 30 Apr 2026 15:14:18 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] The newly added `kdamond_pid` module parameter lacks a `MODULE_PARM_DESC` declaration.
> --
> 
> commit d56734720ba3e7838cd85a1ac6661cf5e54d9a3b
> Author: SeongJae Park <sj@kernel.org>
> 
> mm/damon/stat: add a parameter for reading kdamond pid
> 
> Expose the pid of DAMON_STAT kdamond via a new read-only module parameter
> named kdamond_pid. This standardizes DAMON module usage, as DAMON_RECLAIM
> and DAMON_LRU_SORT also provide this information.
> 
> > diff --git a/mm/damon/stat.c b/mm/damon/stat.c
> > index f4d3203e92639..37964683839d0 100644
> > --- a/mm/damon/stat.c
> > +++ b/mm/damon/stat.c
> [ ... ]
> > +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);
> 
> This isn't a bug, but should this module parameter include a MODULE_PARM_DESC()
> declaration?
> 
> Other parameters in mm/damon/stat.c like enabled, estimated_memory_bandwidth,
> and memory_idle_ms_percentiles have corresponding MODULE_PARM_DESC()
> declarations.

Good finding, I will add that.


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-01  1:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 14:20 [RFC PATCH v2.1 0/2] mm/damon/stat: add kdamond_pid parameter SeongJae Park
2026-04-30 14:20 ` [RFC PATCH v2.1 1/2] mm/damon/stat: add a parameter for reading kdamond pid SeongJae Park
2026-04-30 15:14   ` sashiko-bot
2026-05-01  1:04     ` SeongJae Park
2026-04-30 14:20 ` [RFC PATCH v2.1 2/2] Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox