* [PATCH 1/4] mm/damon/sysfs: implement refresh_ms file under kdamond directory
2025-07-17 5:54 [PATCH 0/4] mm/damon/sysfs: support periodic and automated stats update SeongJae Park
@ 2025-07-17 5:54 ` SeongJae Park
2025-07-17 5:54 ` [PATCH 2/4] mm/damon/sysfs: implement refresh_ms file internal work SeongJae Park
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-17 5:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm
Implement a new DAMON sysfs file named 'refresh_ms' under each kdamond
directory. The file will be used as a control knob of automatic refresh
of a few DAMON internal status files. This commit implements only
minimum file operations, though. The automatic refresh feature will be
implemented by the following commit.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index cce2c8a296e2..4296dc201f4d 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1155,6 +1155,7 @@ struct damon_sysfs_kdamond {
struct kobject kobj;
struct damon_sysfs_contexts *contexts;
struct damon_ctx *damon_ctx;
+ unsigned int refresh_ms;
};
static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc(void)
@@ -1690,6 +1691,30 @@ static ssize_t pid_show(struct kobject *kobj,
return sysfs_emit(buf, "%d\n", pid);
}
+static ssize_t refresh_ms_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_kdamond *kdamond = container_of(kobj,
+ struct damon_sysfs_kdamond, kobj);
+
+ return sysfs_emit(buf, "%u\n", kdamond->refresh_ms);
+}
+
+static ssize_t refresh_ms_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_kdamond *kdamond = container_of(kobj,
+ struct damon_sysfs_kdamond, kobj);
+ unsigned int nr;
+ int err = kstrtouint(buf, 0, &nr);
+
+ if (err)
+ return err;
+
+ kdamond->refresh_ms = nr;
+ return count;
+}
+
static void damon_sysfs_kdamond_release(struct kobject *kobj)
{
struct damon_sysfs_kdamond *kdamond = container_of(kobj,
@@ -1706,9 +1731,13 @@ static struct kobj_attribute damon_sysfs_kdamond_state_attr =
static struct kobj_attribute damon_sysfs_kdamond_pid_attr =
__ATTR_RO_MODE(pid, 0400);
+static struct kobj_attribute damon_sysfs_kdamond_refresh_ms_attr =
+ __ATTR_RW_MODE(refresh_ms, 0600);
+
static struct attribute *damon_sysfs_kdamond_attrs[] = {
&damon_sysfs_kdamond_state_attr.attr,
&damon_sysfs_kdamond_pid_attr.attr,
+ &damon_sysfs_kdamond_refresh_ms_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(damon_sysfs_kdamond);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] mm/damon/sysfs: implement refresh_ms file internal work
2025-07-17 5:54 [PATCH 0/4] mm/damon/sysfs: support periodic and automated stats update SeongJae Park
2025-07-17 5:54 ` [PATCH 1/4] mm/damon/sysfs: implement refresh_ms file under kdamond directory SeongJae Park
@ 2025-07-17 5:54 ` SeongJae Park
2025-07-17 5:54 ` [PATCH 3/4] Docs/admin-guide/mm/damon/usage: document refresh_ms file SeongJae Park
2025-07-17 5:54 ` [PATCH 4/4] Docs/ABI/damon: update for refresh_ms SeongJae Park
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-17 5:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm
Only minimum file operations for refresh_ms file is implemented.
Further implement its designed behavior, the periodic essential files
content update, using repeat mode damon_call().
If non-zero value is written to the file, update DAMON sysfs files for
auto-tuned monitoring intervals, DAMOS stats, and auto-tuned DAMOS quota
values, which are essential to be monitored in most DAMON use cases.
The user-written non-zero value becomes the time delay between the
update. If zero is written to the file, the periodic refresh is
disabled.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 4296dc201f4d..6d2b0dab50cb 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1509,6 +1509,32 @@ static struct damon_ctx *damon_sysfs_build_ctx(
return ctx;
}
+static int damon_sysfs_repeat_call_fn(void *data)
+{
+ struct damon_sysfs_kdamond *sysfs_kdamond = data;
+ static unsigned long next_update_jiffies;
+
+ if (!sysfs_kdamond->refresh_ms)
+ return 0;
+ if (time_before(jiffies, next_update_jiffies))
+ return 0;
+ next_update_jiffies = jiffies +
+ msecs_to_jiffies(sysfs_kdamond->refresh_ms);
+
+ if (!mutex_trylock(&damon_sysfs_lock))
+ return 0;
+ damon_sysfs_upd_tuned_intervals(sysfs_kdamond);
+ damon_sysfs_upd_schemes_stats(sysfs_kdamond);
+ damon_sysfs_upd_schemes_effective_quotas(sysfs_kdamond);
+ mutex_unlock(&damon_sysfs_lock);
+ return 0;
+}
+
+static struct damon_call_control damon_sysfs_repeat_call_control = {
+ .fn = damon_sysfs_repeat_call_fn,
+ .repeat = true,
+};
+
static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
{
struct damon_ctx *ctx;
@@ -1533,6 +1559,9 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
return err;
}
kdamond->damon_ctx = ctx;
+
+ damon_sysfs_repeat_call_control.data = kdamond;
+ damon_call(ctx, &damon_sysfs_repeat_call_control);
return err;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] Docs/admin-guide/mm/damon/usage: document refresh_ms file
2025-07-17 5:54 [PATCH 0/4] mm/damon/sysfs: support periodic and automated stats update SeongJae Park
2025-07-17 5:54 ` [PATCH 1/4] mm/damon/sysfs: implement refresh_ms file under kdamond directory SeongJae Park
2025-07-17 5:54 ` [PATCH 2/4] mm/damon/sysfs: implement refresh_ms file internal work SeongJae Park
@ 2025-07-17 5:54 ` SeongJae Park
2025-07-17 5:54 ` [PATCH 4/4] Docs/ABI/damon: update for refresh_ms SeongJae Park
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-17 5:54 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Jonathan Corbet, damon, kernel-team, linux-doc,
linux-kernel, linux-mm
Document the new DAMON sysfs file, refresh_ms, on the usage document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index fc5c962353ed..ff3a2dda1f02 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -59,7 +59,7 @@ comma (",").
:ref:`/sys/kernel/mm/damon <sysfs_root>`/admin
│ :ref:`kdamonds <sysfs_kdamonds>`/nr_kdamonds
- │ │ :ref:`0 <sysfs_kdamond>`/state,pid
+ │ │ :ref:`0 <sysfs_kdamond>`/state,pid,refresh_ms
│ │ │ :ref:`contexts <sysfs_contexts>`/nr_contexts
│ │ │ │ :ref:`0 <sysfs_context>`/avail_operations,operations
│ │ │ │ │ :ref:`monitoring_attrs <sysfs_monitoring_attrs>`/
@@ -123,8 +123,8 @@ kdamond.
kdamonds/<N>/
-------------
-In each kdamond directory, two files (``state`` and ``pid``) and one directory
-(``contexts``) exist.
+In each kdamond directory, three files (``state``, ``pid`` and ``refresh_ms``)
+and one directory (``contexts``) exist.
Reading ``state`` returns ``on`` if the kdamond is currently running, or
``off`` if it is not running.
@@ -161,6 +161,13 @@ Users can write below commands for the kdamond to the ``state`` file.
If the state is ``on``, reading ``pid`` shows the pid of the kdamond thread.
+Users can ask the kernel to periodically update files showing auto-tuned
+parameters and DAMOS stats instead of manually writing
+``update_tuned_intervals`` like keywords to ``state`` file. For this, users
+should write the desired update time interval in milliseconds to ``refresh_ms``
+file. If the interval is zero, the periodic update is disabled. Reading the
+file shows currently set time interval.
+
``contexts`` directory contains files for controlling the monitoring contexts
that this kdamond will execute.
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] Docs/ABI/damon: update for refresh_ms
2025-07-17 5:54 [PATCH 0/4] mm/damon/sysfs: support periodic and automated stats update SeongJae Park
` (2 preceding siblings ...)
2025-07-17 5:54 ` [PATCH 3/4] Docs/admin-guide/mm/damon/usage: document refresh_ms file SeongJae Park
@ 2025-07-17 5:54 ` SeongJae Park
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-07-17 5:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm
Document the new DAMON sysfs file, refresh_ms, on the ABI document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/ABI/testing/sysfs-kernel-mm-damon | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index e98974dfac7a..6791d879759e 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -44,6 +44,13 @@ Contact: SeongJae Park <sj@kernel.org>
Description: Reading this file returns the pid of the kdamond if it is
running.
+What: /sys/kernel/mm/damon/admin/kdamonds/<K>/refresh_ms
+Date: Jul 2025
+Contact: SeongJae Park <sj@kernel.org>
+Description: Writing a value to this file sets the time interval for
+ automatic DAMON status file contents update. Writing '0'
+ disables the update. Reading this file returns the value.
+
What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/nr_contexts
Date: Mar 2022
Contact: SeongJae Park <sj@kernel.org>
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread