mm/damon: update, optimize, and clean up doc, tests, and code
Subsystems (5)
SeongJae Park
maintainercover mm/damon: update, optimize, and clean up doc, tests, and code
Patches 1 and 2 update the design and ABI documents for recently added DAMON features. Patches 3-7 add or update more unit and self tests for DAMON to cover recently changed or added functions and sysfs files. Patch 8 optimizes damon_commit_target_regions() to skip unnecessary adjacent ranges setup. Patches 9-11 clean and fix up recently added DAMON sysfs interface code for readability.
Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
- Rebase directly to latest mm-new.
SeongJae Park (11):
Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP Docs/ABI/damon: document probe files mm/damon/tests/core-kunit: test damon_rand() selftests/damon/sysfs.sh: test multiple probe dirs creation selftests/damon/sysfs.sh: test {core,ops}_filters/ directories selftests/damon/sysfs.sh: test dests dir selftests/damon/sysfs.sh: test all files in quota goal dir mm/damon/core: reduce range setup in damon_commit_target_regions() mm/damon/sysfs: split probe setup function out mm/damon/sysfs: split out filters setup function mm/damon/sysfs: fix typos in probe_{add,rm}_dirs: s/attr/probe/
.../ABI/testing/sysfs-kernel-mm-damon | 40 +++++++ Documentation/mm/damon/design.rst | 2 + mm/damon/core.c | 22 +++- mm/damon/sysfs.c | 102 ++++++++++-------- mm/damon/tests/core-kunit.h | 21 ++++ tools/testing/selftests/damon/sysfs.sh | 70 +++++++++++- 6 files changed, 206 insertions(+), 51 deletions(-)
base-commit: 09ff70563340c38d31012044b9c6c18f225f4fbf
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 1/11 Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP
Commit 9138e27a3bc3 ("mm/damon: add node_eligible_mem_bp goal metric") introduced DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP but forgot updating the DAMON design document for that. Update.
--- Documentation/mm/damon/design.rst | 2 ++ 1 file changed, 2 insertions(+)
Documentation/mm/damon/design.rst +2 -0
@@ -686,6 +686,8 @@ mechanism tries to make ``current_value`` of ``target_metric`` be same to (1/10,000). - ``inactive_mem_bp``: Inactive to active + inactive (LRU) memory size ratio in bp (1/10,000). +- ``node_eligible_mem_bp``: Scheme target access pattern-eligible memory ratio + of a node in bp (1/10,000). ``nid`` is optionally required for only ``node_mem_used_bp``, ``node_mem_free_bp``, ``node_memcg_used_bp`` and ``node_memcg_free_bp`` to
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 2/11 Docs/ABI/damon: document probe files
In reply to SeongJae ParkDAMON ABI document is not updated for the DAMON probe sysfs files. Update.
--- .../ABI/testing/sysfs-kernel-mm-damon | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+)
Documentation/ABI/testing/sysfs-kernel-mm-damon +40 -0
@@ -157,6 +157,46 @@ Description: Writing a value to this file sets the maximum number of monitoring regions of the DAMON context as the value. Reading this file returns the value. +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/nr_probes +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: Writing a number 'N' to this file creates the number of + directories for each DAMON probe named '0' to 'N-1' under the + probes/ directory. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/nr_filters +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: Writing a number 'N' to this file creates the number of + directories for each DAMON probe filter named '0' to 'N-1' + under the filters/ directory. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/<F>/type +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: Writing to and reading from this file sets and gets the type of + the memory of the interest. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/<F>/path +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: If 'memmcg' is written to the 'type' file, writing to and + reading from this file sets and geets the path to the memory + cgroup of the interest. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/<F>/matching +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: Writing 'Y' or 'N' to this file sets whether the filter is for + the memory of the 'type', or all except the 'type'. + +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/<F>/allow +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: Writing 'Y' or 'N' to this file sets whether to allow or reject + hitting the probe for the memory that satisfies the 'type' and + the 'matching' of the directory. + What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/targets/nr_targets Date: Mar 2022 Contact: SeongJae Park <[email protected]>
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 3/11 mm/damon/tests/core-kunit: test damon_rand()
In reply to SeongJae ParkCommit 9012c4e647df ("mm/damon: replace damon_rand() with a per-ctx lockless PRNG") optimized DAMON for better performance. Add a kunit test for ensuring the pseudo randomness quality.
--- mm/damon/tests/core-kunit.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
mm/damon/tests/core-kunit.h +21 -0
@@ -1460,6 +1460,26 @@ static void damon_test_is_last_region(struct kunit *test)damon_free_target (t); } +static void damon_test_rand (struct kunit *test) +{ +struct damon_ctx ctx; +int counts[10 ] = {}; +int i; + +prandom_seed_state (&ctx.rnd_state,get_random_u64 ()); +for (i =0 ; i <10000 ; i++) { +unsigned long rnd =damon_rand (&ctx,0 ,10 ); + +KUNIT_EXPECT_GE (test, rnd,0 ); +KUNIT_EXPECT_LE (test, rnd,9 ); + counts[rnd]++; + } +for (i =0 ; i <10 ; i++) { +KUNIT_EXPECT_GE (test, counts[i],900 ); +KUNIT_EXPECT_LE (test, counts[i],1100 ); + } +} +static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_target),KUNIT_CASE (damon_test_regions),
@@ -1489,6 +1509,7 @@ static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_set_filters_default_reject),KUNIT_CASE (damon_test_apply_min_nr_regions),KUNIT_CASE (damon_test_is_last_region), + KUNIT_CASE(damon_test_rand), {}, };
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 4/11 selftests/damon/sysfs.sh: test multiple probe dirs creation
In reply to SeongJae ParkDAMON sysfs essential file operations test (sysfs.sh) was extended to test DAMON probes sysfs directory, by commit 14885da09b0f ("selftests/damon/sysfs.sh: test probes dir"). Unlike other DAMON sysfs files, it is testing only a single directory case. Extend it for multiple directories.
--- tools/testing/selftests/damon/sysfs.sh | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/damon/sysfs.sh +5 -0
@@ -346,8 +346,13 @@ test_probes() ensure_write_succ "$probes_dir/nr_probes" "1" "valid input" test_probe "$probes_dir/0" + ensure_write_succ "$probes_dir/nr_probes" "2" "valid input" + test_probe "$probes_dir/0" + test_probe "$probes_dir/1" + ensure_write_succ "$probes_dir/nr_probes" "0" "valid input" ensure_dir "$probes_dir/0" "not_exist" + ensure_dir "$probes_dir/1" "not_exist" } test_monitoring_attrs()
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 5/11 selftests/damon/sysfs.sh: test {core,ops}_filters/ directories
In reply to SeongJae ParkDAMON sysfs interface essential file operations test (sysf.sh) is not testing DAMOS {core,ops}_filters directories. Add the tests.
--- tools/testing/selftests/damon/sysfs.sh | 28 ++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
tools/testing/selftests/damon/sysfs.sh +24 -4
@@ -103,10 +103,28 @@ test_filter() { filter_dir=$1 ensure_file "$filter_dir/type" "exist" "600" - ensure_write_succ "$filter_dir/type" "anon" "valid input" - ensure_write_succ "$filter_dir/type" "memcg" "valid input" - ensure_write_succ "$filter_dir/type" "addr" "valid input" - ensure_write_succ "$filter_dir/type" "target" "valid input" + + local dir_name=$(basename "$(dirname "$filter_dir")") + if [ "$dir_name" = "filters" ] || [ "$dir_name" = "ops_filters" ] + then + ensure_write_succ "$filter_dir/type" "anon" "valid input" + ensure_write_succ "$filter_dir/type" "memcg" "valid input" + fi + if [ "$dir_name" = "filters" ] || [ "$dir_name" = "core_filters" ] + then + ensure_write_succ "$filter_dir/type" "addr" "valid input" + ensure_write_succ "$filter_dir/type" "target" "valid input" + fi + if [ "$dir_name" = "core_filters" ] + then + ensure_write_fail "$filter_dir/type" "anon" "ops type" + ensure_write_fail "$filter_dir/type" "memcg" "ops type" + fi + if [ "$dir_name" = "ops_filters" ] + then + ensure_write_fail "$filter_dir/type" "addr" "core type" + ensure_write_fail "$filter_dir/type" "target" "core type" + fi ensure_write_fail "$filter_dir/type" "foo" "invalid input" ensure_file "$filter_dir/matching" "exist" "600" ensure_file "$filter_dir/memcg_path" "exist" "600"
@@ -208,6 +226,8 @@ test_scheme() test_quotas "$scheme_dir/quotas" test_watermarks "$scheme_dir/watermarks" test_filters "$scheme_dir/filters" + test_filters "$scheme_dir/core_filters" + test_filters "$scheme_dir/ops_filters" test_stats "$scheme_dir/stats" test_tried_regions "$scheme_dir/tried_regions" }
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 6/11 selftests/damon/sysfs.sh: test dests dir
In reply to SeongJae ParkDAMON selftest interface essential file operations test (sysfs.sh) is not testing DAMOS dests/ directory. Add the test.
--- tools/testing/selftests/damon/sysfs.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tools/testing/selftests/damon/sysfs.sh +23 -0
@@ -99,6 +99,29 @@ test_stats() done } +test_dest() +{ + dest_dir=$1 + ensure_file "$dest_dir/id" "exist" + ensure_file "$dest_dir/weight" "exist" +} + +test_dests() +{ + dests_dir=$1 + ensure_file "$dests_dir/nr_dests" "exist" "600" + ensure_write_succ "$dests_dir/nr_dests" "1" "valid input" + test_dest "$dests_dir/0" + + ensure_write_succ "$dests_dir/nr_dests" "2" "valid input" + test_dest "$dests_dir/0" + test_dest "$dests_dir/1" + + ensure_write_succ "$dests_dir/nr_dests" "0" "valid input" + ensure_dir "$dests_dir/0" "not_exist" + ensure_dir "$dests_dir/1" "not_exist" +} + test_filter() { filter_dir=$1
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 7/11 selftests/damon/sysfs.sh: test all files in quota goal dir
In reply to SeongJae ParkDAMON sysfs interface for DAMOS quota has quite extended since its initial introduction. The test case for that in DAMON sysfs interface essential file operations test (sysfs.sh) has not accordingly extended, though. Extend the test case to test all existing files.
--- tools/testing/selftests/damon/sysfs.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/testing/selftests/damon/sysfs.sh +14 -0
@@ -199,6 +199,20 @@ test_goal() ensure_dir "$goal_dir" "exist" ensure_file "$goal_dir/target_value" "exist" "600" ensure_file "$goal_dir/current_value" "exist" "600" + ensure_file "$goal_dir/target_metric" "exist" "600" + local fpath="$goal_dir/target_metric" + ensure_write_succ "$fpath" "user_input" "valid input" + ensure_write_succ "$fpath" "some_mem_psi_us" "valid input" + ensure_write_succ "$fpath" "node_mem_used_bp" "valid input" + ensure_write_succ "$fpath" "node_mem_free_bp" "valid input" + ensure_write_succ "$fpath" "node_memcg_used_bp" "valid input" + ensure_write_succ "$fpath" "node_memcg_free_bp" "valid input" + ensure_write_succ "$fpath" "active_mem_bp" "valid input" + ensure_write_succ "$fpath" "inactive_mem_bp" "valid input" + ensure_write_succ "$fpath" "node_eligible_mem_bp" "valid input" + ensure_write_fail "$fpath" "foo" "invalid input" + ensure_file "$goal_dir/nid" "exist" "600" + ensure_file "$goal_dir/path" "exist" "600" } test_goals()
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 8/11 mm/damon/core: reduce range setup in damon_commit_target_regions()
In reply to SeongJae Parkdamon_commit_target_regions() calls damon_set_regions() for updating the destination target's monitoring target region boundaries. It sets the boundaries same to source target's monitoring regions, even if they are adjacent. Meanwhile, damon_set_region() sets the destination target regions exactly the same to the source, only when the target regions are empty. When there are existing target regions, only a few regions are expanded or shrunk to fit on only the boundaries for disjoint regions in the source. Hence the adjacent source ranges mean nothing in common cases. When there are many regions, such adjacent range setup is only a waste of time and space. We recently found [1] it is actually causing memory overhead. Setup the ranges for only distinct ranges.
[1] https://lore.kernel.org/[email protected]
--- mm/damon/core.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
mm/damon/core.c +17 -5
@@ -1349,21 +1349,33 @@ static struct damon_target *damon_nth_target(int n, struct damon_ctx *ctx)static int damon_commit_target_regions (struct damon_target *dst,struct damon_target *src,unsigned long src_min_region_sz) { -struct damon_region *src_region; +struct damon_region *src_region, *prev =NULL ;struct damon_addr_range *ranges;int i =0 , err; -damon_for_each_region (src_region, src) - i++; +damon_for_each_region (src_region, src) { +if (!prev || prev->ar.end != src_region->ar.start) + i++; + prev = src_region; + }if (!i)return 0 ; ranges =kmalloc_objs (*ranges, i,GFP_KERNEL | __GFP_NOWARN);if (!ranges)return -ENOMEM ; + prev =NULL ; i =0 ; -damon_for_each_region (src_region, src) - ranges[i++] = src_region->ar; +damon_for_each_region (src_region, src) { +if (!prev) { + ranges[i].start = src_region->ar.start; + }else if (prev->ar.end != src_region->ar.start) { + ranges[i++].end = prev->ar.end; + ranges[i].start = src_region->ar.start; + } + prev = src_region; + } + ranges[i++].end =damon_last_region (src)->ar.end; err =damon_set_regions (dst, ranges, i, src_min_region_sz);kfree (ranges);return err;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 9/11 mm/damon/sysfs: split probe setup function out
In reply to SeongJae Parkdamon_sysfs_set_probes() function is relatively long. It has two nested loop for setting two nested entities, namely probe and filter. Split out the probe level setup for readability.
--- mm/damon/sysfs.c | 80 ++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 34 deletions(-)
mm/damon/sysfs.c +46 -34
@@ -1899,47 +1899,59 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ctx,return damon_set_attrs (ctx, &attrs); } -static int damon_sysfs_set_probes (struct damon_ctx *ctx, -struct damon_sysfs_probes *sys_probes) +static int damon_sysfs_set_probe (struct damon_probe *probe, +struct damon_sysfs_probe *sys_probe) { +struct damon_sysfs_filters *sys_filters;int i; -for (i =0 ; i < sys_probes->nr; i++) { -struct damon_sysfs_filters *sys_filters = - sys_probes->probes_arr[i]->filters; -struct damon_probe *c; -int j; + sys_filters = sys_probe->filters; +if (!sys_filters) +return 0 ; -if (!sys_filters) -continue ; - c =damon_new_probe (); -if (!c) +for (i =0 ; i < sys_filters->nr; i++) { +struct damon_sysfs_filter *sys_filter = + sys_filters->filters_arr[i]; +struct damon_filter *filter; + + filter =damon_new_filter (sys_filter->type, + sys_filter->matching, + sys_filter->allow); +if (!filter)return -ENOMEM ; -damon_add_probe (ctx, c); - -for (j =0 ; j < sys_filters->nr; j++) { -struct damon_sysfs_filter *sys_filter = - sys_filters->filters_arr[j]; -struct damon_filter *filter; - - filter =damon_new_filter (sys_filter->type, - sys_filter->matching, - sys_filter->allow); -if (!filter) -return -ENOMEM ; -if (filter->type ==DAMON_FILTER_TYPE_MEMCG ) { -int err; - - err =damon_sysfs_memcg_path_to_id ( - sys_filter->path, - &filter->memcg_id); -if (err) { -damon_destroy_filter (filter); -return err; - } +if (filter->type ==DAMON_FILTER_TYPE_MEMCG ) { +int err; + + err =damon_sysfs_memcg_path_to_id ( + sys_filter->path, + &filter->memcg_id); +if (err) { +damon_destroy_filter (filter); +return err; } -damon_add_filter (c, filter); } +damon_add_filter (probe, filter); + } +return 0 ; +} + +static int damon_sysfs_set_probes (struct damon_ctx *ctx, +struct damon_sysfs_probes *sys_probes) +{ +int i, err; + +for (i =0 ; i < sys_probes->nr; i++) { +struct damon_sysfs_probe *sys_probe; +struct damon_probe *p; + + p =damon_new_probe (); +if (!p) +return -ENOMEM ; +damon_add_probe (ctx, p); + sys_probe = sys_probes->probes_arr[i]; + err =damon_sysfs_set_probe (p, sys_probe); +if (err) +return err; }return 0 ; }
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 10/11 mm/damon/sysfs: split out filters setup function
In reply to SeongJae Parkdamon_sysfs_set_probe() is doing not only probe setup but also filters setup. Split out filters setup for readability.
--- mm/damon/sysfs.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
mm/damon/sysfs.c +13 -7
@@ -1899,16 +1899,11 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ctx,return damon_set_attrs (ctx, &attrs); } -static int damon_sysfs_set_probe (struct damon_probe *probe, -struct damon_sysfs_probe *sys_probe) +static int damon_sysfs_set_filters (struct damon_probe *probe, +struct damon_sysfs_filters *sys_filters) { -struct damon_sysfs_filters *sys_filters;int i; - sys_filters = sys_probe->filters; -if (!sys_filters) -return 0 ; -for (i =0 ; i < sys_filters->nr; i++) {struct damon_sysfs_filter *sys_filter = sys_filters->filters_arr[i];
@@ -1935,6 +1930,17 @@ static int damon_sysfs_set_probe(struct damon_probe *probe,return 0 ; } +static int damon_sysfs_set_probe (struct damon_probe *probe, +struct damon_sysfs_probe *sys_probe) +{ +struct damon_sysfs_filters *sys_filters; + + sys_filters = sys_probe->filters; +if (!sys_filters) +return 0 ; +return damon_sysfs_set_filters (probe, sys_filters); +} +static int damon_sysfs_set_probes (struct damon_ctx *ctx,struct damon_sysfs_probes *sys_probes) {
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 11/11 mm/damon/sysfs: fix typos in probe_{add,rm}_dirs: s/attr/probe/
In reply to SeongJae Parkdamon_sysfs_probe_{add,rm}_dirs names a variable for damon_sysf_probe as 'attr'. Probably a trivial copy-pasta error, but it makes the code not pleasant to read. Fix those.
--- mm/damon/sysfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
mm/damon/sysfs.c +8 -8
@@ -1068,7 +1068,7 @@ static struct damon_sysfs_probe *damon_sysfs_probe_alloc(void) return kzalloc_obj(struct damon_sysfs_probe); } -static int damon_sysfs_probe_add_dirs (struct damon_sysfs_probe *attr) +static int damon_sysfs_probe_add_dirs (struct damon_sysfs_probe *probe) {struct damon_sysfs_filters *filters;int err;
@@ -1076,22 +1076,22 @@ static int damon_sysfs_probe_add_dirs(struct damon_sysfs_probe *attr) filters =damon_sysfs_filters_alloc ();if (!filters)return -ENOMEM ; - attr->filters = filters; + probe->filters = filters; err =kobject_init_and_add (&filters->kobj, &damon_sysfs_filters_ktype, - &attr->kobj,"filters" ); + &probe->kobj,"filters" );if (err) {kobject_put (&filters->kobj); - attr->filters =NULL ; + probe->filters =NULL ; }return err; } -static void damon_sysfs_probe_rm_dirs (struct damon_sysfs_probe *attr) +static void damon_sysfs_probe_rm_dirs (struct damon_sysfs_probe *probe) { -if (attr->filters) { -damon_sysfs_filters_rm_dirs (attr->filters); -kobject_put (&attr->filters->kobj); +if (probe->filters) { +damon_sysfs_filters_rm_dirs (probe->filters); +kobject_put (&probe->filters->kobj); } }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v1.1 01/11] Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP
In reply to SeongJae ParkThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The patch introduces an internal inconsistency in the design document by documenting the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces an internal inconsistency in the design document by documenting the node_eligible_mem_bp metric but failing to update the adjacent sentence that lists which metrics require the nid parameter. --
commit 77a1ee91d398d22fd9a42b16bbf085e55f72a94a
Author: SeongJae Park <[email protected]> Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP
This commit updates the DAMON design document to include the node_eligible_mem_bp goal metric that was introduced in an earlier commit.
Documentation/mm/damon/design.rst mechanism tries to make ``current_value`` of ``target_metric`` be same to · line 693
Quoted 12 lines
Documentation/mm/damon/design.rst +2
-0@@ -686,6 +686,8 @@ mechanism tries to make ``current_value`` of ``target_metric`` be same to (1/10,000). - ``inactive_mem_bp``: Inactive to active + inactive (LRU) memory size ratio in bp (1/10,000). +- ``node_eligible_mem_bp``: Scheme target access pattern-eligible memory ratio + of a node in bp (1/10,000). ``nid`` is optionally required for only ``node_mem_used_bp``, ``node_mem_free_bp``, ``node_memcg_used_bp`` and ``node_memcg_free_bp`` to
[Severity: Low]
Since node_eligible_mem_bp is a node-specific metric, should it also be added to this list of metrics that optionally require nid? As currently written, the use of the word "only" implies that node_eligible_mem_bp does not use an nid parameter, which could be misleading for users trying to configure this metric.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [RFC PATCH v1.1 03/11] mm/damon/tests/core-kunit: test damon_rand()
In reply to SeongJae ParkThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The KUnit test uses a non-deterministic seed with tight probability bounds, which will cause…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The KUnit test uses a non-deterministic seed with tight probability bounds, which will cause sporadic test failures. --
commit bc9f1073820b74c3fbb6ac52d5ca363629f99f3d
Author: SeongJae Park <[email protected]>
mm/damon/tests/core-kunit: test damon_rand()
Commit 9012c4e647df ("mm/damon: replace damon_rand() with a per-ctx lockless PRNG") optimized DAMON for better performance. Add a kunit test for ensuring the pseudo randomness quality.
Quoted 4 lines
mm/damon/tests/core-kunit.h +0
-0
[ ... ]
Quoted 11 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1460,6 +1460,26 @@ static void damon_test_is_last_region(struct kunit *test)damon_free_target (t); } +static void damon_test_rand (struct kunit *test) +{ +struct damon_ctx ctx; +int counts[10 ] = {}; +int i; + +prandom_seed_state (&ctx.rnd_state,get_random_u64 ());
mm/damon/tests/core-kunit.h static void damon_test_is_last_region(struct kunit *test) · line 1479
Quoted 10 lines
mm/damon/tests/core-kunit.h +10
-0+for (i =0 ; i <10000 ; i++) { +unsigned long rnd =damon_rand (&ctx,0 ,10 ); + +KUNIT_EXPECT_GE (test, rnd,0 ); +KUNIT_EXPECT_LE (test, rnd,9 ); + counts[rnd]++; + } +for (i =0 ; i <10 ; i++) { +KUNIT_EXPECT_GE (test, counts[i],900 ); +KUNIT_EXPECT_LE (test, counts[i],1100 );
[Severity: Medium]
The test uses a true random seed to initialize the PRNG state, making the test output non-deterministic. Is it possible that these tight expectation bounds will cause sporadic test failures in automated CI environments?
Statistically, a binomial distribution with n=10,000 and p=0.1 has a standard deviation of 30. The allowed variation of +/- 100 is roughly +/- 3.33 standard deviations. The probability of any single bin falling outside this range is around 0.086%.
Over 10 bins, does this mean the test could spuriously fail about 0.86% of the time (roughly 1 in 117 runs)?
Quoted 5 lines
mm/damon/tests/core-kunit.h +3
-0+ } +} +static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_target),
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [RFC PATCH v1.1 02/11] Docs/ABI/damon: document probe files
In reply to SeongJae ParkThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Incorrect sysfs value 'memmcg' and typographical errors in DAMON probe ABI documentation. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incorrect sysfs value 'memmcg' and typographical errors in DAMON probe ABI documentation. --
commit 0777dacf66fdc3cce9315b7348cc989aa1d048f8
Author: SeongJae Park <[email protected]>
Docs/ABI/damon: document probe files
This commit updates the DAMON ABI documentation to include the new DAMON probe sysfs files, defining directories for probes, filters, and attributes.
Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-mm-damon +0
-0
[ ... ]
Documentation/ABI/testing/sysfs-kernel-mm-damon Description: Writing a value to this file sets the maximum number of · line 185
Quoted 6 lines
Documentation/ABI/testing/sysfs-kernel-mm-damon +6
-0+What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/<F>/path +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: If 'memmcg' is written to the 'type' file, writing to and + reading from this file sets and geets the path to the memory + cgroup of the interest.
[Severity: Medium]
Is the expected type value documented correctly here? The documentation instructs users to write 'memmcg' to the type file, but the underlying kernel code strictly expects 'memcg'. If userspace follows this documentation, will the kernel reject the input with an -EINVAL error?
Also, this isn't a bug, but there is a typo in this sentence where "geets" is written instead of "gets".
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [RFC PATCH v1.1 06/11] selftests/damon/sysfs.sh: test dests dir
In reply to SeongJae ParkThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly added `test_dests()` function is never invoked, and its helper `test_dest()` omits a…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added test_dests() function is never invoked, and its helper test_dest() omits a required argument, causing the test to be both unexercised and structurally broken. --
commit 53579293376a979c6b9c9914d1d77ffa57418d36
Author: SeongJae Park <[email protected]>
selftests/damon/sysfs.sh: test dests dir
DAMON selftest interface essential file operations test (sysfs.sh) is not testing DAMOS dests/ directory. This commit adds a test for the dests directory.
tools/testing/selftests/damon/sysfs.sh test_stats() · line 106
Quoted 13 lines
tools/testing/selftests/damon/sysfs.sh +5
-0@@ -99,6 +99,29 @@ test_stats() done } +test_dest() +{ + dest_dir=$1 + ensure_file "$dest_dir/id" "exist" + ensure_file "$dest_dir/weight" "exist"
[Severity: Medium]
Does ensure_file() require a third argument for the expected permission? Without it, the underlying check might evaluate the file's permission against an empty string and unconditionally fail the test.
tools/testing/selftests/damon/sysfs.sh test_stats() · line 110
Quoted 4 lines
tools/testing/selftests/damon/sysfs.sh +4
-0+} + +test_dests() +{
[Severity: Medium]
Is test_dests() ever invoked? It looks like this function is defined here but remains unreferenced in the script. Should it be called from test_scheme() to verify the directory under each scheme?
Quoted 4 lines
tools/testing/selftests/damon/sysfs.sh +4
-0+ dests_dir=$1 + ensure_file "$dests_dir/nr_dests" "exist" "600" + ensure_write_succ "$dests_dir/nr_dests" "1" "valid input" + test_dest "$dests_dir/0"
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
SeongJae Park
maintainerRe: [RFC PATCH v1.1 01/11] Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP
In reply to [email protected]Quoted 21 lines · On Thu, 25 Jun 2026 05:13:50 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces an internal inconsistency in the design document by documenting thenode_eligible_mem_bpmetric but failing to update the adjacent sentence that lists which metrics require thenidparameter. --commit
77a1ee91d398d22fd9a42b16bbf085e55f72a94a
Author: SeongJae Park <[email protected]> Docs/mm/damon/design: update forDAMOS_QUOTA_NODE_ELIGIBLE_MEM_BPThis commit updates the DAMON design document to include the
node_eligible_mem_bpgoal metric that was introduced in an earlier commit.Quoted 10 lines
Documentation/mm/damon/design.rst +2
-0@@ -686,6 +686,8 @@ mechanism tries to make ``current_value`` of ``target_metric`` be same to (1/10,000). - ``inactive_mem_bp``: Inactive to active + inactive (LRU) memory size ratio in bp (1/10,000). +- ``node_eligible_mem_bp``: Scheme target access pattern-eligible memory ratio + of a node in bp (1/10,000).
Quoted 9 lines
Documentation/mm/damon/design.rst mechanism tries to make ``current_value`` of ``target_metric`` be same to · line 693
Quoted 2 lines
Documentation/mm/damon/design.rst +0
-0``nid`` is optionally required for only ``node_mem_used_bp``, ``node_mem_free_bp``, ``node_memcg_used_bp`` and ``node_memcg_free_bp`` to[Severity: Low]
Sincenode_eligible_mem_bpis a node-specific metric, should it also be added to this list of metrics that optionally require nid? As currently written, the use of the word "only" implies thatnode_eligible_mem_bpdoes not use an nid parameter, which could be misleading for users trying to configure this metric.
Good catch! I will do so in the next revision.
Thanks,
SJ
[...]
SeongJae Park
maintainerRe: [RFC PATCH v1.1 02/11] Docs/ABI/damon: document probe files
In reply to [email protected]Quoted 30 lines · On Thu, 25 Jun 2026 05:14:13 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incorrect sysfs value 'memmcg' and typographical errors in DAMON probe ABI documentation. --commit
0777dacf66fdc3cce9315b7348cc989aa1d048f8
Author: SeongJae Park <[email protected]>Docs/ABI/damon: document probe files
This commit updates the DAMON ABI documentation to include the new DAMON probe sysfs files, defining directories for probes, filters, and attributes.
Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-mm-damon +0
-0[ ... ]
Documentation/ABI/testing/sysfs-kernel-mm-damon Description: Writing a value to this file sets the maximum number of · line 185
Quoted 6 lines
Documentation/ABI/testing/sysfs-kernel-mm-damon +6
-0+What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/probes/<P>/filters/<F>/path +Date: May 2026 +Contact: SeongJae Park <[email protected]> +Description: If 'memmcg' is written to the 'type' file, writing to and + reading from this file sets and geets the path to the memory + cgroup of the interest.[Severity: Medium]
Is the expected type value documented correctly here? The documentation instructs users to write 'memmcg' to the type file, but the underlying kernel code strictly expects 'memcg'. If userspace follows this documentation, will the kernel reject the input with an-EINVALerror?
Quoted 2 lines
Also, this isn't a bug, but there is a typo in this sentence where "geets" is written instead of "gets".
Good catches. Those are typos. Somehow nowadays my computer shows lags at multiple things including BT keyboard input catch...
I will fix these in the next revision.
Thanks,
SJ
[...]
SeongJae Park
maintainerRe: [RFC PATCH v1.1 03/11] mm/damon/tests/core-kunit: test damon_rand()
In reply to [email protected]Quoted 47 lines · On Thu, 25 Jun 2026 05:13:51 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The KUnit test uses a non-deterministic seed with tight probability bounds, which will cause sporadic test failures. --commit
bc9f1073820b74c3fbb6ac52d5ca363629f99f3d
Author: SeongJae Park <[email protected]>
mm/damon/tests/core-kunit: testdamon_rand()Commit
9012c4e647df("mm/damon: replacedamon_rand()with a per-ctx lockless PRNG") optimized DAMON for better performance. Add a kunit test for ensuring the pseudo randomness quality.Quoted 4 lines
mm/damon/tests/core-kunit.h +0
-0[ ... ]
Quoted 11 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1460,6 +1460,26 @@ static void damon_test_is_last_region(struct kunit *test)damon_free_target (t); } +static void damon_test_rand (struct kunit *test) +{ +struct damon_ctx ctx; +int counts[10 ] = {}; +int i; + +prandom_seed_state (&ctx.rnd_state,get_random_u64 ());mm/damon/tests/core-kunit.h static void damon_test_is_last_region(struct kunit *test) · line 1479
Quoted 10 lines
mm/damon/tests/core-kunit.h +10
-0+for (i =0 ; i <10000 ; i++) { +unsigned long rnd =damon_rand (&ctx,0 ,10 ); + +KUNIT_EXPECT_GE (test, rnd,0 ); +KUNIT_EXPECT_LE (test, rnd,9 ); + counts[rnd]++; + } +for (i =0 ; i <10 ; i++) { +KUNIT_EXPECT_GE (test, counts[i],900 ); +KUNIT_EXPECT_LE (test, counts[i],1100 );[Severity: Medium]
The test uses a true random seed to initialize the PRNG state, making the test output non-deterministic. Is it possible that these tight expectation bounds will cause sporadic test failures in automated CI environments?
Quoted 7 lines
Statistically, a binomial distribution with n=10,000 and p=0.1 has a standard deviation of 30. The allowed variation of +/- 100 is roughly +/- 3.33 standard deviations. The probability of any single bin falling outside this range is around 0.086%.
Over 10 bins, does this mean the test could spuriously fail about 0.86% of the time (roughly 1 in 117 runs)?
Good catch. I will modify the test to widen the bound to [800, 1200].
Thanks,
SJ
[...]
SeongJae Park
maintainerRe: [RFC PATCH v1.1 06/11] selftests/damon/sysfs.sh: test dests dir
In reply to [email protected]Quoted 32 lines · On Thu, 25 Jun 2026 05:14:49 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly addedtest_dests()function is never invoked, and its helpertest_dest()omits a required argument, causing the test to be both unexercised and structurally broken. --commit
53579293376a979c6b9c9914d1d77ffa57418d36
Author: SeongJae Park <[email protected]>
selftests/damon/sysfs.sh: test dests dirDAMON selftest interface essential file operations test (
sysfs.sh) is not testing DAMOS dests/ directory. This commit adds a test for the dests directory.tools/testing/selftests/damon/sysfs.sh test_stats() · line 106
Quoted 13 lines
tools/testing/selftests/damon/sysfs.sh +5
-0@@ -99,6 +99,29 @@ test_stats() done } +test_dest() +{ + dest_dir=$1 + ensure_file "$dest_dir/id" "exist" + ensure_file "$dest_dir/weight" "exist"[Severity: Medium]
Doesensure_file()require a third argument for the expected permission? Without it, the underlying check might evaluate the file's permission against an empty string and unconditionally fail the test.
Quoted 9 lines
tools/testing/selftests/damon/sysfs.sh test_stats() · line 110
Quoted 4 lines
tools/testing/selftests/damon/sysfs.sh +4
-0+} + +test_dests() +{[Severity: Medium]
Istest_dests()ever invoked? It looks like this function is defined here but remains unreferenced in the script. Should it be called fromtest_scheme()to verify the directory under each scheme?
Good findings! I will fix those in the next revision.
Thanks,
SJ
[...]
SeongJae Park
maintainerRe: [RFC PATCH v1.1 03/11] mm/damon/tests/core-kunit: test damon_rand()
In reply to SeongJae ParkQuoted 54 lines · On Wed, 24 Jun 2026 22:38:06 -0700 SeongJae Park <[email protected]> wrote:
Quoted 52 lines · On Thu, 25 Jun 2026 05:13:51 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The KUnit test uses a non-deterministic seed with tight probability bounds, which will cause sporadic test failures. --commit
bc9f1073820b74c3fbb6ac52d5ca363629f99f3d
Author: SeongJae Park <[email protected]>
mm/damon/tests/core-kunit: testdamon_rand()Commit
9012c4e647df("mm/damon: replacedamon_rand()with a per-ctx lockless PRNG") optimized DAMON for better performance. Add a kunit test for ensuring the pseudo randomness quality.Quoted 4 lines
mm/damon/tests/core-kunit.h +0
-0[ ... ]
Quoted 11 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1460,6 +1460,26 @@ static void damon_test_is_last_region(struct kunit *test)damon_free_target (t); } +static void damon_test_rand (struct kunit *test) +{ +struct damon_ctx ctx; +int counts[10 ] = {}; +int i; + +prandom_seed_state (&ctx.rnd_state,get_random_u64 ());mm/damon/tests/core-kunit.h static void damon_test_is_last_region(struct kunit *test) · line 1479
Quoted 10 lines
mm/damon/tests/core-kunit.h +10
-0+for (i =0 ; i <10000 ; i++) { +unsigned long rnd =damon_rand (&ctx,0 ,10 ); + +KUNIT_EXPECT_GE (test, rnd,0 ); +KUNIT_EXPECT_LE (test, rnd,9 ); + counts[rnd]++; + } +for (i =0 ; i <10 ; i++) { +KUNIT_EXPECT_GE (test, counts[i],900 ); +KUNIT_EXPECT_LE (test, counts[i],1100 );[Severity: Medium]
The test uses a true random seed to initialize the PRNG state, making the test output non-deterministic. Is it possible that these tight expectation bounds will cause sporadic test failures in automated CI environments?Statistically, a binomial distribution with n=10,000 and p=0.1 has a standard deviation of 30. The allowed variation of +/- 100 is roughly +/- 3.33 standard deviations. The probability of any single bin falling outside this range is around 0.086%.
Quoted 4 lines
Quoted 2 lines
Over 10 bins, does this mean the test could spuriously fail about 0.86% of the time (roughly 1 in 117 runs)?
Good catch. I will modify the test to widen the bound to [800, 1200].
In my second thought, the logic is quite straightforward. I will simply drop the randomness test, and keep only the bound test.
Thanks,
SJ
[...]