mm/damon: misc improvements in tests and documents
Subsystems (5)
SJ Park
maintainercover mm/damon: misc improvements in tests and documents
Add various improvements to DAMON tests and documents.
Patch 1 and 2 from Zenghui Yu (Huawei) let DAMON selftest to clean up its state and output after running the tests. Patch 3 from Eva Kurchatova makes a few selftest be able to run with Python's safe path mode. Patch 4 from Kunwu Chan improves coverage of DAMON kunit tests. Finally, patches 5 and 6 from Liew Rui Yan clarify and fix typos on documents for DAMOS quota behaviors.
Below are notes that can be removed in the final commit message.
This is a batched repost of DAMON patches that were individually posted. Please refer to each patch for changelog.
Eva Kurchatova (1):
selftests/damon: add script dir to sys.path for PYTHONSAFEPATH
compatibility
Kunwu Chan (1):
mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
Liew Rui Yan (2):
Docs/mm/damon/design: clarify when qt_exceeds increases Docs/mm/damon/design: fix typos in temporal auto-tuning algorithm
section
Zenghui Yu (Huawei) (2):
selftests/damon: stop kdamond on error exits of no-op commit test selftests/damon: ignore test-generated damon_dump_output
Documentation/mm/damon/design.rst | 8 +++-- mm/damon/tests/core-kunit.h | 19 +++++++--- tools/testing/selftests/damon/.gitignore | 1 + .../selftests/damon/damon_nr_regions.py | 3 ++ .../selftests/damon/damos_apply_interval.py | 3 ++ tools/testing/selftests/damon/damos_quota.py | 3 ++ .../selftests/damon/damos_quota_goal.py | 3 ++ .../selftests/damon/damos_tried_regions.py | 3 ++ .../damon/sysfs_no_op_commit_break.py | 35 ++++++++++--------- ...sysfs_update_schemes_tried_regions_hang.py | 3 ++ ...te_schemes_tried_regions_wss_estimation.py | 3 ++ 11 files changed, 60 insertions(+), 24 deletions(-)
base-commit: d1153a22117b5c6171bdf24d32b7f6c314887d23
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 1/6 selftests/damon: stop kdamond on error exits of no-op commit test
From: "Zenghui Yu (Huawei)" <[email protected]>
The sysfs_no_op_commit_break test starts a kdamond via sysfs, but its error paths (e.g., drgn not installed) exit without stopping it. The leaked kdamond then makes subsequent tests, e.g. lru_sort.sh and reclaim.sh, skip with "Another kdamond is running".
Wrap the post-start logic in try-finally so that kdamonds.stop() is executed on every exit path.
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
.../damon/sysfs_no_op_commit_break.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-)
tools/testing/selftests/damon/sysfs_no_op_commit_break.py +18 -17
@@ -47,26 +47,27 @@ def main(): print('kdamond start failed: %s' % err) exit(1) - before_commit_status, err = \ - dump_damon_status_dict(kdamonds.kdamonds[0].pid) - if err is not None: - print('before-commit status dump failed: %s' % err) - exit(1) + try: + before_commit_status, err = \ + dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print('before-commit status dump failed: %s' % err) + exit(1) - kdamonds.kdamonds[0].commit() + kdamonds.kdamonds[0].commit() - after_commit_status, err = \ - dump_damon_status_dict(kdamonds.kdamonds[0].pid) - if err is not None: - print('after-commit status dump failed: %s' % err) - exit(1) - - if before_commit_status != after_commit_status: - print(f'before: {json.dumps(before_commit_status, indent=2)}') - print(f'after: {json.dumps(after_commit_status, indent=2)}') - exit(1) + after_commit_status, err = \ + dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print('after-commit status dump failed: %s' % err) + exit(1) - kdamonds.stop() + if before_commit_status != after_commit_status: + print(f'before: {json.dumps(before_commit_status, indent=2)}') + print(f'after: {json.dumps(after_commit_status, indent=2)}') + exit(1) + finally: + kdamonds.stop() if __name__ == '__main__': main()
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 1/6] selftests/damon: stop kdamond on error exits of no-op commit test
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
From: "Zenghui Yu (Huawei)" <[email protected]>
The
sysfs_no_op_commit_breaktest starts a kdamond via sysfs, but its error paths (e.g., drgn not installed) exit without stopping it. The leaked kdamond then makes subsequent tests, e.g.lru_sort.shandreclaim.sh, skip with "Another kdamond is running".
Quoted 8 lines
Wrap the post-start logic in try-finally so that
kdamonds.stop()is executed on every exit path.Fixes 10725cd2b09a ("selftests/damon: test no-op commit broke DAMON status")Assisted-by GLM-5.3 OpenCodeSigned-off-by Zenghui Yu (Huawei) <[email protected]>Reviewed-by SJ Park <[email protected]>Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerPATCH 2/6 selftests/damon: ignore test-generated damon_dump_output
In reply to SJ ParkFrom: "Zenghui Yu (Huawei)" <[email protected]>
sysfs.py and sysfs_no_op_commit_break.py dump the DAMON status collected via drgn_dump_damon_status.py into a damon_dump_output file in the working directory. Ignore it so that running the tests in-tree does not pollute git status.
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
tools/testing/selftests/damon/.gitignore | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/damon/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only access_memory access_memory_even +damon_dump_output
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/6] selftests/damon: ignore test-generated damon_dump_output
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
From: "Zenghui Yu (Huawei)" <[email protected]>
sysfs.pyandsysfs_no_op_commit_break.pydump the DAMON status collected viadrgn_dump_damon_status.pyinto adamon_dump_outputfile in the working directory. Ignore it so that running the tests in-tree does not pollute git status.Signed-off-by Zenghui Yu (Huawei) <[email protected]>Reviewed-by SJ Park <[email protected]>Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerPATCH 3/6 selftests/damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
In reply to SJ ParkFrom: Eva Kurchatova <[email protected]>
Running these tests under Python's safe path mode, either with -P on the interpreter command line or with PYTHONSAFEPATH set in the environment, stops the script's own directory being prepended to sys.path. Some distributions (RHEL, for example) build the tests with -P in the shebang.
This breaks all 7 DAMON Python selftests that import the _damon_sysfs helper module located in the same directory:
ModuleNotFoundError: No module named '_damon_sysfs'
Fix this by explicitly adding the script's directory to sys.path before importing _damon_sysfs, following the same pattern used in commit c3b3eb565bd7 ("tools: ynl: add script dir to sys.path") which fixed the identical issue for the YNL tools.
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
tools/testing/selftests/damon/damon_nr_regions.py | 3 +++ tools/testing/selftests/damon/damos_apply_interval.py | 3 +++ tools/testing/selftests/damon/damos_quota.py | 3 +++ tools/testing/selftests/damon/damos_quota_goal.py | 3 +++ tools/testing/selftests/damon/damos_tried_regions.py | 3 +++ .../selftests/damon/sysfs_update_schemes_tried_regions_hang.py | 3 +++ .../damon/sysfs_update_schemes_tried_regions_wss_estimation.py | 3 +++ 7 files changed, 21 insertions(+)
tools/testing/selftests/damon/damon_nr_regions.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def test_nr_regions(real_nr_regions, min_nr_regions, max_nr_regions):
tools/testing/selftests/damon/damos_apply_interval.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def main():
tools/testing/selftests/damon/damos_quota.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def main():
tools/testing/selftests/damon/damos_quota_goal.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def main():
tools/testing/selftests/damon/damos_tried_regions.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def main():
tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def main():
tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py +3 -0
@@ -1,9 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import os import subprocess +import sys import time +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import _damon_sysfs def pass_wss_estimation(sz_region):
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 3/6] selftests/damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch incompletely fixes PYTHONSAFEPATH compatibility by omitting 3 out of 10 DAMON Python…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch incompletely fixes PYTHONSAFEPATH compatibility by omitting 3 out of 10 DAMON Python selftests, creating an inconsistent state and a commit message mismatch. --
commit da82d013622fc33202048b811231e1ede806c92f
Author: Eva Kurchatova <[email protected]>
selftests/damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
This commit adds the script's directory to sys.path for seven DAMON Python selftests to ensure they can import the _damon_sysfs helper module when run under Python's safe path mode.
Quoted 2 lines
This breaks all 7 DAMON Python selftests that import the
_damon_sysfshelper module located in the same directory:
[Severity: Medium]
Are there additional DAMON Python selftests that also need this fix?
The commit message states there are 7 tests, but it appears 3 additional tests in the same directory also import _damon_sysfs and were omitted from this patch.
For example, in tools/testing/selftests/damon/sysfs.py:
import _damon_sysfs
And in tools/testing/selftests/damon/sysfs_refresh.py:
import _damon_sysfs
And in tools/testing/selftests/damon/sysfs_no_op_commit_break.py:
import _damon_sysfs
Will these scripts still fail with a ModuleNotFoundError when run in environments that enforce PYTHONSAFEPATH=1?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
SJ Park
maintainerRe: [PATCH 3/6] selftests/damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
Quoted 26 lines · On Mon, 14 Sep 2026 14:37:41 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch incompletely fixes PYTHONSAFEPATH compatibility by omitting 3 out of 10 DAMON Python selftests, creating an inconsistent state and a commit message mismatch. --commit
da82d013622fc33202048b811231e1ede806c92f
Author: Eva Kurchatova <[email protected]>selftests/damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
This commit adds the script's directory to sys.path for seven DAMON Python selftests to ensure they can import the
_damon_sysfshelper module when run under Python's safe path mode.Quoted 2 lines
This breaks all 7 DAMON Python selftests that import the
_damon_sysfshelper module located in the same directory:[Severity: Medium]
Are there additional DAMON Python selftests that also need this fix?The commit message states there are 7 tests, but it appears 3 additional tests in the same directory also import
_damon_sysfsand were omitted from this patch.For example, in
tools/testing/selftests/damon/sysfs.py:
import_damon_sysfs
Quoted 8 lines
And in
tools/testing/selftests/damon/sysfs_refresh.py:
import_damon_sysfsAnd in
tools/testing/selftests/damon/sysfs_no_op_commit_break.py:
import_damon_sysfsWill these scripts still fail with a ModuleNotFoundError when run in environments that enforce PYTHONSAFEPATH=1?
Agreed, but not necessarily a blocker of this patch. I will separately work on the other tests.
Quoted 3 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Thanks,
SJ
SJ Park
maintainerPATCH 4/6 mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
In reply to SJ ParkFrom: Kunwu Chan <[email protected]>
Test the zero sample interval case with a non-zero aggregation interval, and keep the zero/zero case to cover the zero-result fallback.
Also make the overflow case use an explicit sample interval so that it does not depend on the zero sample interval fallback.
---
Changes from v2
- v2: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Changes from v1
- v1: https://lore.kernel.org/damon/[email protected]/
- Use 0/0 for the zero-result case, consistent with damon_set_attrs().
- Update commit msg and add Reviewed-by tag.
mm/damon/tests/core-kunit.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
mm/damon/tests/core-kunit.h +15 -4
@@ -627,12 +627,20 @@ static void damon_test_set_regions(struct kunit *test)static void damon_test_nr_samples_per_aggr (struct kunit *test) { -struct damon_attrs attrs = { +struct damon_attrs attrs; + +/* Zero sample interval is treated as one. */ + attrs = (struct damon_attrs ){ .sample_interval =0 , - .aggr_interval =0 , + .aggr_interval =5000 , }; +KUNIT_EXPECT_EQ (test,damon_nr_samples_per_aggr (&attrs),5000 ); -/* Zero aggregation interval doesn't cause division by zero */ +/* Zero sample and aggregation intervals cover the zero-result fallback. */ + attrs = (struct damon_attrs ){ + .sample_interval =0 , + .aggr_interval =0 , + };KUNIT_EXPECT_EQ (test,damon_nr_samples_per_aggr (&attrs),1 );/*
@@ -640,7 +648,10 @@ static void damon_test_nr_samples_per_aggr(struct kunit *test)* overflow */ if (ULONG_MAX >UINT_MAX ) { - attrs.aggr_interval = (unsigned long )UINT_MAX +1 ; + attrs = (struct damon_attrs ){ + .sample_interval =1 , + .aggr_interval = (unsigned long )UINT_MAX +1 , + };KUNIT_EXPECT_EQ (test,damon_nr_samples_per_aggr (&attrs),UINT_MAX ); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 4/6] mm/damon/tests/core-kunit: improve nr_samples_per_aggr test isolation
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
From: Kunwu Chan <[email protected]>
Test the zero sample interval case with a non-zero aggregation interval, and keep the zero/zero case to cover the zero-result fallback.
Quoted 7 lines
Also make the overflow case use an explicit sample interval so that it does not depend on the zero sample interval fallback.
Signed-off-by Kunwu Chan <[email protected]>Reviewed-by Lian Wang <[email protected]>Reviewed-by SJ Park <[email protected]>Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerPATCH 5/6 Docs/mm/damon/design: clarify when qt_exceeds increases
In reply to SJ ParkFrom: Liew Rui Yan <[email protected]>
qt_exceeds counts how many times a scheme's quota has been exceeded.
When using the temporal auto-tuning algorithm, the effective size quota becomes zero once the goal is [over-]achieved. In this case, the quotas are still set, so qt_exceeds keeps increasing once per quota reset interval while the goal stays achieved.
Clarify this behavior in the design document.
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: From SJ.
- Rebase to latest mm-new.
Changes from RFC v1
- RFC v1: https://lore.kernel.org/damon/[email protected]
- Simplify the explanation. Do not provide a complete definition of qt_exceeds, but rather explain only the increment condition when using temporal auto-tuning algorithm, simply to prevent users from becoming confused and being unable to find any explanation.
Documentation/mm/damon/design.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/mm/damon/design.rst +3 -1
@@ -696,7 +696,9 @@ There are two such tuning algorithms that users can select as they need. fast as possible, using maximum allowed quota, but only for a temporal short time. When the quota is under-achieved, this algorithm keeps tuning quota to a maximum allowed one. Once the quota is [over]-achieved, this sets the - quota zero. Useful for deterministic control required environments. + quota zero. Useful for deterministic control required environments. Note + that the zero quota is a valid quota, and therefore ``qt_exceeds`` :ref:`stat + <damon_design_damos_stat>` will keep increasing in this case. The goal can be specified with five parameters, namely ``target_metric``, ``target_value``, ``current_value``, ``nid`` and ``path``. The auto-tuning
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 5/6] Docs/mm/damon/design: clarify when qt_exceeds increases
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
From: Liew Rui Yan <[email protected]>
qt_exceedscounts how many times a scheme's quota has been exceeded.When using the temporal auto-tuning algorithm, the effective size quota becomes zero once the goal is [over-]achieved. In this case, the quotas are still set, so
qt_exceedskeeps increasing once per quota reset interval while the goal stays achieved.
Quoted 5 lines
Clarify this behavior in the design document.
Signed-off-by Liew Rui Yan <[email protected]>Reviewed-by SJ Park <[email protected]>Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
SJ Park
maintainerPATCH 6/6 Docs/mm/damon/design: fix typos in temporal auto-tuning algorithm section
In reply to SJ ParkFrom: Liew Rui Yan <[email protected]>
Correct incorrect references of "quota" to "goal" in the temporal auto-tuning algorithm description and fix the square bracket formatting.
---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Documentation/mm/damon/design.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/mm/damon/design.rst +2 -2
@@ -694,8 +694,8 @@ There are two such tuning algorithms that users can select as they need. This is the default selection. If unsure, use this. - ``temporal``: More straightforward algorithm. Tries to achieve the goal as fast as possible, using maximum allowed quota, but only for a temporal short - time. When the quota is under-achieved, this algorithm keeps tuning quota to - a maximum allowed one. Once the quota is [over]-achieved, this sets the + time. When the goal is under-achieved, this algorithm keeps tuning quota to + a maximum allowed one. Once the goal is [over-]achieved, this sets the quota zero. Useful for deterministic control required environments. Note that the zero quota is a valid quota, and therefore ``qt_exceeds`` :ref:`stat <damon_design_damos_stat>` will keep increasing in this case.
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 6/6] Docs/mm/damon/design: fix typos in temporal auto-tuning algorithm section
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
From: Liew Rui Yan <[email protected]>
Correct incorrect references of "quota" to "goal" in the temporal auto-tuning algorithm description and fix the square bracket formatting.
Signed-off-by Liew Rui Yan <[email protected]>Reviewed-by SJ Park <[email protected]>Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
SJ Park
maintainerQuoted 1 line · On Mon, 14 Sep 2026 07:19:45 -0700 SJ Park <[email protected]> wrote:
Add various improvements to DAMON tests and documents.
Sashiko found no blocker for this series. Sashiko send its findings to damon@ mailing list [1], and I reply those if anything needs to be clarified. Please refer to those for details.
[1] https://lore.kernel.org/damon/
Thanks,
SJ
[...]
Andrew Morton
maintainerQuoted 9 lines · On Mon, 14 Sep 2026 07:19:45 -0700 SJ Park <[email protected]> wrote:
Add various improvements to DAMON tests and documents.
Patch 1 and 2 from Zenghui Yu (Huawei) let DAMON selftest to clean up its state and output after running the tests. Patch 3 from Eva Kurchatova makes a few selftest be able to run with Python's safe path mode. Patch 4 from Kunwu Chan improves coverage of DAMON kunit tests. Finally, patches 5 and 6 from Liew Rui Yan clarify and fix typos on documents for DAMOS quota behaviors.
Quoted 4 lines
Below are notes that can be removed in the final commit message.
This is a batched repost of DAMON patches that were individually posted. Please refer to each patch for changelog.
All queued, thanks,