* [PATCH 0/2] selftests/damon: test kdamond refresh_ms
@ 2026-06-02 13:12 Ruslan Valiyev
2026-06-02 13:12 ` [PATCH 1/2] selftests/damon/_damon_sysfs: support " Ruslan Valiyev
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Ruslan Valiyev @ 2026-06-02 13:12 UTC (permalink / raw)
To: SeongJae Park
Cc: Shuah Khan, damon, linux-mm, linux-kselftest, linux-kernel,
linuxoid
The kdamond 'refresh_ms' sysfs file makes DAMON periodically update its
read-only sysfs files (DAMOS stats, tuned monitoring intervals and the
kdamond pid) on its own, so users don't have to write update keywords
such as 'update_schemes_stats' to the 'state' file. It has no selftest
coverage.
The first patch adds refresh_ms support to the _damon_sysfs.py test
control module. The second adds a test that sets refresh_ms and confirms
a scheme's stats are updated under sysfs without an explicit update
request; the test skips on kernels that predate the refresh_ms file.
Tested on current mainline under a DAMON-enabled kernel: the new test
passes and the existing DAMON selftests show no new failures.
Ruslan Valiyev (2):
selftests/damon/_damon_sysfs: support kdamond refresh_ms
selftests/damon/sysfs_refresh: test kdamond refresh_ms
tools/testing/selftests/damon/Makefile | 1 +
tools/testing/selftests/damon/_damon_sysfs.py | 9 ++-
.../testing/selftests/damon/sysfs_refresh.py | 75 +++++++++++++++++++
3 files changed, 84 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/damon/sysfs_refresh.py
base-commit: 174914ea551314c52a61713b9c4bde9e42d48073
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] selftests/damon/_damon_sysfs: support kdamond refresh_ms
2026-06-02 13:12 [PATCH 0/2] selftests/damon: test kdamond refresh_ms Ruslan Valiyev
@ 2026-06-02 13:12 ` Ruslan Valiyev
2026-06-02 14:13 ` SeongJae Park
2026-06-02 13:12 ` [PATCH 2/2] selftests/damon/sysfs_refresh: test " Ruslan Valiyev
2026-06-02 14:28 ` [PATCH 0/2] selftests/damon: " SeongJae Park
2 siblings, 1 reply; 8+ messages in thread
From: Ruslan Valiyev @ 2026-06-02 13:12 UTC (permalink / raw)
To: SeongJae Park
Cc: Shuah Khan, damon, linux-mm, linux-kselftest, linux-kernel,
linuxoid
The Kdamond class has no way to set the kdamond-level 'refresh_ms' sysfs
file, which makes DAMON periodically update the read-only sysfs files
(DAMOS stats, tuned monitoring intervals and the kdamond pid) on its own.
Add a 'refresh_ms' parameter to Kdamond. When it is set (including to
zero, to disable the periodic update), write it before turning the
kdamond on, so tests can exercise the auto-update behavior. Leaving it
unset keeps the previous behavior of not touching the file, so callers
running against kernels without the feature are unaffected.
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
---
tools/testing/selftests/damon/_damon_sysfs.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index 2b4df655d9fd0..1a498c78a4149 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -667,12 +667,14 @@ class DamonCtx:
class Kdamond:
state = None
pid = None
+ refresh_ms = None
contexts = None
idx = None # index of this kdamond between siblings
kdamonds = None # parent
- def __init__(self, contexts=[]):
+ def __init__(self, contexts=[], refresh_ms=None):
self.contexts = contexts
+ self.refresh_ms = refresh_ms
for idx, context in enumerate(self.contexts):
context.idx = idx
context.kdamond = self
@@ -695,6 +697,11 @@ class Kdamond:
err = context.stage()
if err is not None:
return err
+ if self.refresh_ms is not None:
+ err = write_file(os.path.join(self.sysfs_dir(), 'refresh_ms'),
+ '%d' % self.refresh_ms)
+ if err is not None:
+ return err
err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on')
if err is not None:
return err
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] selftests/damon/sysfs_refresh: test kdamond refresh_ms
2026-06-02 13:12 [PATCH 0/2] selftests/damon: test kdamond refresh_ms Ruslan Valiyev
2026-06-02 13:12 ` [PATCH 1/2] selftests/damon/_damon_sysfs: support " Ruslan Valiyev
@ 2026-06-02 13:12 ` Ruslan Valiyev
2026-06-02 14:23 ` SeongJae Park
2026-06-02 14:28 ` [PATCH 0/2] selftests/damon: " SeongJae Park
2 siblings, 1 reply; 8+ messages in thread
From: Ruslan Valiyev @ 2026-06-02 13:12 UTC (permalink / raw)
To: SeongJae Park
Cc: Shuah Khan, damon, linux-mm, linux-kselftest, linux-kernel,
linuxoid
Writing a non-zero value to a kdamond's 'refresh_ms' sysfs file should
make DAMON periodically update the read-only sysfs files on its own,
without the user writing update keywords such as 'update_schemes_stats'
to the 'state' file. This behavior has no test coverage.
Add a test that starts a kdamond with refresh_ms set and a 'stat' scheme
whose default access pattern matches every monitored region, then polls
the scheme's 'nr_tried' stats file directly, without requesting an
update. The value can become non-zero only via the periodic refresh, so
the test confirms refresh_ms works; with refresh_ms disabled the stat
stays zero and the test fails.
Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
---
tools/testing/selftests/damon/Makefile | 1 +
.../testing/selftests/damon/sysfs_refresh.py | 75 +++++++++++++++++++
2 files changed, 76 insertions(+)
create mode 100755 tools/testing/selftests/damon/sysfs_refresh.py
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 2180c328a8252..ece244e5c5b95 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -13,6 +13,7 @@ TEST_PROGS += sysfs.py
TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py
TEST_PROGS += damos_quota.py damos_quota_goal.py damos_apply_interval.py
TEST_PROGS += damos_tried_regions.py damon_nr_regions.py
+TEST_PROGS += sysfs_refresh.py
TEST_PROGS += reclaim.sh lru_sort.sh
# regression tests (reproducers of previously found bugs)
diff --git a/tools/testing/selftests/damon/sysfs_refresh.py b/tools/testing/selftests/damon/sysfs_refresh.py
new file mode 100755
index 0000000000000..012b7e8f509f5
--- /dev/null
+++ b/tools/testing/selftests/damon/sysfs_refresh.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import subprocess
+import time
+
+import _damon_sysfs
+
+def main():
+ # Continuously access a memory region for far longer than the test needs,
+ # so the kdamond always has a live target to monitor while we poll.
+ sz_region = 10 * 1024 * 1024
+ proc = subprocess.Popen(
+ ['./access_memory', '1', '%d' % sz_region, '60000', 'repeat'])
+
+ # A 'stat' scheme with the default (maximally wide) access pattern matches
+ # every monitored region, so its 'nr_tried' stat increases as the kdamond
+ # runs. refresh_ms should make DAMON update the schemes' stats files under
+ # sysfs on its own, without a manual 'update_schemes_stats' request.
+ kdamond = _damon_sysfs.Kdamond(
+ refresh_ms=100,
+ contexts=[_damon_sysfs.DamonCtx(
+ ops='vaddr',
+ targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
+ schemes=[_damon_sysfs.Damos(action='stat')],
+ )])
+ kdamonds = _damon_sysfs.Kdamonds([kdamond])
+
+ err = kdamonds.start()
+ if err is not None:
+ # Kernels older than the refresh_ms feature have no such file; treat
+ # that as unsupported rather than a failure.
+ if not os.path.exists(os.path.join(kdamond.sysfs_dir(), 'refresh_ms')):
+ proc.terminate()
+ proc.wait()
+ print('kdamond has no refresh_ms file; skipping')
+ exit(_damon_sysfs.ksft_skip)
+ proc.terminate()
+ proc.wait()
+ print('kdamond start failed: %s' % err)
+ exit(1)
+
+ scheme = kdamond.contexts[0].schemes[0]
+ nr_tried_path = os.path.join(scheme.sysfs_dir(), 'stats', 'nr_tried')
+
+ try:
+ # Poll the stat file directly. We never request an update (e.g.
+ # 'update_schemes_stats'), so 'nr_tried' can become non-zero only
+ # through the periodic refresh that refresh_ms enables.
+ nr_tried = 0
+ deadline = time.monotonic() + 10
+ while time.monotonic() < deadline:
+ if proc.poll() is not None:
+ print('the access_memory target exited unexpectedly')
+ exit(1)
+ content, err = _damon_sysfs.read_file(nr_tried_path)
+ if err is not None:
+ print('reading %s failed: %s' % (nr_tried_path, err))
+ exit(1)
+ nr_tried = int(content)
+ if nr_tried > 0:
+ break
+ time.sleep(0.1)
+ finally:
+ kdamonds.stop()
+ proc.terminate()
+ proc.wait()
+
+ if nr_tried == 0:
+ print('refresh_ms did not auto-update the schemes stats')
+ exit(1)
+
+if __name__ == '__main__':
+ main()
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] selftests/damon/_damon_sysfs: support kdamond refresh_ms
2026-06-02 13:12 ` [PATCH 1/2] selftests/damon/_damon_sysfs: support " Ruslan Valiyev
@ 2026-06-02 14:13 ` SeongJae Park
0 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2026-06-02 14:13 UTC (permalink / raw)
To: Ruslan Valiyev
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
On Tue, 2 Jun 2026 15:12:16 +0200 Ruslan Valiyev <linuxoid@gmail.com> wrote:
> The Kdamond class has no way to set the kdamond-level 'refresh_ms' sysfs
> file, which makes DAMON periodically update the read-only sysfs files
> (DAMOS stats, tuned monitoring intervals and the kdamond pid) on its own.
>
> Add a 'refresh_ms' parameter to Kdamond. When it is set (including to
> zero, to disable the periodic update), write it before turning the
> kdamond on, so tests can exercise the auto-update behavior. Leaving it
> unset keeps the previous behavior of not touching the file, so callers
> running against kernels without the feature are unaffected.
Nice addition of the feature, thank you!
>
> Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] selftests/damon/sysfs_refresh: test kdamond refresh_ms
2026-06-02 13:12 ` [PATCH 2/2] selftests/damon/sysfs_refresh: test " Ruslan Valiyev
@ 2026-06-02 14:23 ` SeongJae Park
0 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2026-06-02 14:23 UTC (permalink / raw)
To: Ruslan Valiyev
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
On Tue, 2 Jun 2026 15:12:17 +0200 Ruslan Valiyev <linuxoid@gmail.com> wrote:
> Writing a non-zero value to a kdamond's 'refresh_ms' sysfs file should
> make DAMON periodically update the read-only sysfs files on its own,
> without the user writing update keywords such as 'update_schemes_stats'
> to the 'state' file. This behavior has no test coverage.
>
> Add a test that starts a kdamond with refresh_ms set and a 'stat' scheme
> whose default access pattern matches every monitored region, then polls
> the scheme's 'nr_tried' stats file directly, without requesting an
> update. The value can become non-zero only via the periodic refresh, so
> the test confirms refresh_ms works; with refresh_ms disabled the stat
> stays zero and the test fails.
Thank you for adding this nice test!
>
> Signed-off-by: Ruslan Valiyev <linuxoid@gmail.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] selftests/damon: test kdamond refresh_ms
2026-06-02 13:12 [PATCH 0/2] selftests/damon: test kdamond refresh_ms Ruslan Valiyev
2026-06-02 13:12 ` [PATCH 1/2] selftests/damon/_damon_sysfs: support " Ruslan Valiyev
2026-06-02 13:12 ` [PATCH 2/2] selftests/damon/sysfs_refresh: test " Ruslan Valiyev
@ 2026-06-02 14:28 ` SeongJae Park
2026-06-02 17:03 ` Andrew Morton
2 siblings, 1 reply; 8+ messages in thread
From: SeongJae Park @ 2026-06-02 14:28 UTC (permalink / raw)
To: Ruslan Valiyev
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel, Andrew Morton
On Tue, 2 Jun 2026 15:12:15 +0200 Ruslan Valiyev <linuxoid@gmail.com> wrote:
> The kdamond 'refresh_ms' sysfs file makes DAMON periodically update its
> read-only sysfs files (DAMOS stats, tuned monitoring intervals and the
> kdamond pid) on its own, so users don't have to write update keywords
> such as 'update_schemes_stats' to the 'state' file. It has no selftest
> coverage.
>
> The first patch adds refresh_ms support to the _damon_sysfs.py test
> control module. The second adds a test that sets refresh_ms and confirms
> a scheme's stats are updated under sysfs without an explicit update
> request; the test skips on kernels that predate the refresh_ms file.
>
> Tested on current mainline under a DAMON-enabled kernel: the new test
> passes and the existing DAMON selftests show no new failures.
Thank you for this great contribution, Ruslan! :)
All patches look good. I therefore added this sereis to damon/next [1] tree.
If this series is not added to mm.git in short term (~1 week?), I will ask
mm.git maintainer (Andrew Morton) to pick this.
Andrew might want us to wait until next rc1 release, though, as
apparently now we want to keep more time on stabilizing mm.git for the next
merge window. Andrew, please let me know if so.
So, no action from your side is needed for now. If it seems I
also forgot doing that or you cannot wait for my action, please feel free to
directly ask that to Andrew.
[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] selftests/damon: test kdamond refresh_ms
2026-06-02 14:28 ` [PATCH 0/2] selftests/damon: " SeongJae Park
@ 2026-06-02 17:03 ` Andrew Morton
2026-06-03 0:50 ` SeongJae Park
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2026-06-02 17:03 UTC (permalink / raw)
To: SeongJae Park
Cc: Ruslan Valiyev, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
On Tue, 2 Jun 2026 07:28:03 -0700 SeongJae Park <sj@kernel.org> wrote:
> Andrew might want us to wait until next rc1 release, though, as
> apparently now we want to keep more time on stabilizing mm.git for the next
> merge window. Andrew, please let me know if so.
Yes, awaiting -rc1 would be preferred please.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] selftests/damon: test kdamond refresh_ms
2026-06-02 17:03 ` Andrew Morton
@ 2026-06-03 0:50 ` SeongJae Park
0 siblings, 0 replies; 8+ messages in thread
From: SeongJae Park @ 2026-06-03 0:50 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Ruslan Valiyev, Shuah Khan, damon, linux-mm,
linux-kselftest, linux-kernel
On Tue, 2 Jun 2026 10:03:08 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> On Tue, 2 Jun 2026 07:28:03 -0700 SeongJae Park <sj@kernel.org> wrote:
>
> > Andrew might want us to wait until next rc1 release, though, as
> > apparently now we want to keep more time on stabilizing mm.git for the next
> > merge window. Andrew, please let me know if so.
>
> Yes, awaiting -rc1 would be preferred please.
Thank you for letting me know. I will hold reposting of this until the -rc1.
Ruslan, please let us know if you think this series cannot wait.
Thanks,
SJ
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-06-03 0:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 13:12 [PATCH 0/2] selftests/damon: test kdamond refresh_ms Ruslan Valiyev
2026-06-02 13:12 ` [PATCH 1/2] selftests/damon/_damon_sysfs: support " Ruslan Valiyev
2026-06-02 14:13 ` SeongJae Park
2026-06-02 13:12 ` [PATCH 2/2] selftests/damon/sysfs_refresh: test " Ruslan Valiyev
2026-06-02 14:23 ` SeongJae Park
2026-06-02 14:28 ` [PATCH 0/2] selftests/damon: " SeongJae Park
2026-06-02 17:03 ` Andrew Morton
2026-06-03 0:50 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox