selftests/damon: test kdamond refresh_ms
Subsystems (3)
cover selftests/damon: test kdamond refresh_ms
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
Signature · 1 line
2.43.0
PATCH 1/2 selftests/damon/_damon_sysfs: support kdamond refresh_ms
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.
--- tools/testing/selftests/damon/_damon_sysfs.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/damon/_damon_sysfs.py +8 -1
@@ -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
Signature · 1 line
2.43.0
PATCH 2/2 selftests/damon/sysfs_refresh: test kdamond refresh_ms
In reply to Ruslan ValiyevWriting 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.
--- 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
tools/testing/selftests/damon/Makefile +1 -0
@@ -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)
tools/testing/selftests/damon/sysfs_refresh.py new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 1/2] selftests/damon/_damon_sysfs: support kdamond refresh_ms
In reply to Ruslan ValiyevQuoted 9 lines · On Tue, 2 Jun 2026 15:12:16 +0200 Ruslan Valiyev <[email protected]> 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!
Quoted 2 lines
Signed-off-by Ruslan Valiyev <[email protected]>
Thanks,
SJ
[...]
Re: [PATCH 2/2] selftests/damon/sysfs_refresh: test kdamond refresh_ms
In reply to Ruslan ValiyevQuoted 11 lines · On Tue, 2 Jun 2026 15:12:17 +0200 Ruslan Valiyev <[email protected]> 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_msset 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 confirmsrefresh_msworks; withrefresh_msdisabled the stat stays zero and the test fails.
Thank you for adding this nice test!
Quoted 2 lines
Signed-off-by Ruslan Valiyev <[email protected]>
Thanks,
SJ
[...]
SeongJae Park
maintainerQuoted 6 lines · On Tue, 2 Jun 2026 15:12:15 +0200 Ruslan Valiyev <[email protected]> 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.
Quoted 7 lines
The first patch adds
refresh_mssupport to the_damon_sysfs.pytest control module. The second adds a test that setsrefresh_msand confirms a scheme's stats are updated under sysfs without an explicit update request; the test skips on kernels that predate therefresh_msfile.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
[...]
Andrew Morton
maintainerQuoted 3 lines · On Tue, 2 Jun 2026 07:28:03 -0700 SeongJae Park <[email protected]> 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.
SeongJae Park
maintainerQuoted 7 lines · On Tue, 2 Jun 2026 10:03:08 -0700 Andrew Morton <[email protected]>…
Quoted 3 lines · On Tue, 2 Jun 2026 07:28:03 -0700 SeongJae Park <[email protected]> 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