* [RFC PATCH 03/11] mm/damon/tests/core-kunit: test damon_rand()
2026-06-24 14:19 [RFC PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
@ 2026-06-24 14:19 ` SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 04/11] selftests/damon/sysfs.sh: test multiple probe dirs creation SeongJae Park
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2026-06-24 14:19 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index df16cc070eeb0..a1ba807d59a13 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1488,6 +1488,26 @@ static void damon_test_walk_control_obsolete(struct kunit *test)
damon_destroy_ctx(ctx);
}
+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),
@@ -1518,6 +1538,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_apply_min_nr_regions),
KUNIT_CASE(damon_test_is_last_region),
KUNIT_CASE(damon_test_walk_control_obsolete),
+ KUNIT_CASE(damon_test_rand),
{},
};
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [RFC PATCH 04/11] selftests/damon/sysfs.sh: test multiple probe dirs creation
2026-06-24 14:19 [RFC PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
2026-06-24 14:19 ` [RFC PATCH 03/11] mm/damon/tests/core-kunit: test damon_rand() SeongJae Park
@ 2026-06-24 14:20 ` SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 05/11] selftests/damon/sysfs.sh: test {core,ops}_filters/ directories SeongJae Park
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2026-06-24 14:20 UTC (permalink / raw)
Cc: SeongJae Park, Shuah Khan, damon, linux-kernel, linux-kselftest,
linux-mm
DAMON 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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/sysfs.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh
index 2eaaa5ae3c5ed..d528dfea44c3b 100755
--- a/tools/testing/selftests/damon/sysfs.sh
+++ b/tools/testing/selftests/damon/sysfs.sh
@@ -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()
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [RFC PATCH 05/11] selftests/damon/sysfs.sh: test {core,ops}_filters/ directories
2026-06-24 14:19 [RFC PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
2026-06-24 14:19 ` [RFC PATCH 03/11] mm/damon/tests/core-kunit: test damon_rand() SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 04/11] selftests/damon/sysfs.sh: test multiple probe dirs creation SeongJae Park
@ 2026-06-24 14:20 ` SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 06/11] selftests/damon/sysfs.sh: test dests dir SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 07/11] selftests/damon/sysfs.sh: test all files in quota goal dir SeongJae Park
4 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2026-06-24 14:20 UTC (permalink / raw)
Cc: SeongJae Park, Shuah Khan, damon, linux-kernel, linux-kselftest,
linux-mm
DAMON sysfs interface essential file operations test (sysf.sh) is not
testing DAMOS {core,ops}_filters directories. Add the tests.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/sysfs.sh | 28 ++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh
index d528dfea44c3b..78eea0d13c271 100755
--- a/tools/testing/selftests/damon/sysfs.sh
+++ b/tools/testing/selftests/damon/sysfs.sh
@@ -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"
}
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [RFC PATCH 06/11] selftests/damon/sysfs.sh: test dests dir
2026-06-24 14:19 [RFC PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
` (2 preceding siblings ...)
2026-06-24 14:20 ` [RFC PATCH 05/11] selftests/damon/sysfs.sh: test {core,ops}_filters/ directories SeongJae Park
@ 2026-06-24 14:20 ` SeongJae Park
2026-06-24 14:20 ` [RFC PATCH 07/11] selftests/damon/sysfs.sh: test all files in quota goal dir SeongJae Park
4 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2026-06-24 14:20 UTC (permalink / raw)
Cc: SeongJae Park, Shuah Khan, damon, linux-kernel, linux-kselftest,
linux-mm
DAMON selftest interface essential file operations test (sysfs.sh) is
not testing DAMOS dests/ directory. Add the test.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/sysfs.sh | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh
index 78eea0d13c271..cbfababa0bf31 100755
--- a/tools/testing/selftests/damon/sysfs.sh
+++ b/tools/testing/selftests/damon/sysfs.sh
@@ -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
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [RFC PATCH 07/11] selftests/damon/sysfs.sh: test all files in quota goal dir
2026-06-24 14:19 [RFC PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
` (3 preceding siblings ...)
2026-06-24 14:20 ` [RFC PATCH 06/11] selftests/damon/sysfs.sh: test dests dir SeongJae Park
@ 2026-06-24 14:20 ` SeongJae Park
4 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2026-06-24 14:20 UTC (permalink / raw)
Cc: SeongJae Park, Shuah Khan, damon, linux-kernel, linux-kselftest,
linux-mm
DAMON 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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/sysfs.sh | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh
index cbfababa0bf31..ad3aab240b360 100755
--- a/tools/testing/selftests/damon/sysfs.sh
+++ b/tools/testing/selftests/damon/sysfs.sh
@@ -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()
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread