* [PATCH v2 1/2] mm/damon/core-kunit: test probe_hits handling at region split and merge
2026-08-31 15:06 [PATCH v2 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation SJ Park
@ 2026-08-31 15:06 ` SJ Park
2026-08-31 18:10 ` sashiko-bot
2026-08-31 15:06 ` [PATCH v2 2/2] mm/damon/core-kunit: test damon_valid_probe_params() SJ Park
1 sibling, 1 reply; 5+ messages in thread
From: SJ Park @ 2026-08-31 15:06 UTC (permalink / raw)
To: Andrew Morton
Cc: Jason Angelov, Brendan Higgins, David Gow, SJ Park, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
From: Jason Angelov <jasonangelov@ucla.edu>
damon_split_region_at() copies probe_hits[] and last_probe_hits[] to
the new split region.
damon_merge_two_regions() sets probe_hits[] to the size-weighted
average of the merged regions.
Extend damon_test_split_at() and damon_test_merge_two() tests to
cover those fields.
Signed-off-by: Jason Angelov <jasonangelov@ucla.edu>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index ec7260a3bfea8..68591ca99a4f7 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -152,6 +152,8 @@ static void damon_test_split_at(struct kunit *test)
}
r->nr_accesses = 42;
r->last_nr_accesses = 15;
+ r->probe_hits[0] = 7;
+ r->last_probe_hits[0] = 3;
r->age = 10;
damon_add_region(r, t);
damon_split_region_at(t, r, 25);
@@ -168,6 +170,8 @@ static void damon_test_split_at(struct kunit *test)
KUNIT_EXPECT_EQ(test, r->nr_accesses, r_new->nr_accesses);
KUNIT_EXPECT_EQ(test, r->last_nr_accesses, r_new->last_nr_accesses);
+ KUNIT_EXPECT_EQ(test, r->probe_hits[0], r_new->probe_hits[0]);
+ KUNIT_EXPECT_EQ(test, r->last_probe_hits[0], r_new->last_probe_hits[0]);
KUNIT_EXPECT_EQ(test, r->age, r_new->age);
out:
@@ -189,6 +193,7 @@ static void damon_test_merge_two(struct kunit *test)
kunit_skip(test, "region alloc fail");
}
r->nr_accesses = 10;
+ r->probe_hits[0] = 6;
r->age = 9;
damon_add_region(r, t);
r2 = damon_new_region(100, 300);
@@ -197,6 +202,7 @@ static void damon_test_merge_two(struct kunit *test)
kunit_skip(test, "second region alloc fail");
}
r2->nr_accesses = 20;
+ r2->probe_hits[0] = 14;
r2->age = 21;
damon_add_region(r2, t);
@@ -204,6 +210,7 @@ static void damon_test_merge_two(struct kunit *test)
KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
KUNIT_EXPECT_EQ(test, r->ar.end, 300ul);
KUNIT_EXPECT_EQ(test, r->nr_accesses, 16u);
+ KUNIT_EXPECT_EQ(test, r->probe_hits[0], 11);
KUNIT_EXPECT_EQ(test, r->age, 17u);
i = 0;
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] mm/damon/core-kunit: test damon_valid_probe_params()
2026-08-31 15:06 [PATCH v2 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation SJ Park
2026-08-31 15:06 ` [PATCH v2 1/2] mm/damon/core-kunit: test probe_hits handling at region split and merge SJ Park
@ 2026-08-31 15:06 ` SJ Park
2026-08-31 18:15 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: SJ Park @ 2026-08-31 15:06 UTC (permalink / raw)
To: Andrew Morton
Cc: Jason Angelov, Brendan Higgins, David Gow, SJ Park, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
From: Jason Angelov <jasonangelov@ucla.edu>
damon_valid_probe_params() makes damon_commit_ctx() reject probe
configurations that could overflow a probe_hits counter, a single
(weight * probe_hits) product, or the sum of those products.
Add a kunit test covering each rejection at its boundary:
- samples per aggregation interval: U8_MAX is allowed, one more could
overflow a probe_hits counter
- single weight: the largest whose product fits in unsigned int is
allowed, one larger is rejected
- multiple probes: each product fits, but their sum overflows
- no weight set: the validation is skipped
Signed-off-by: Jason Angelov <jasonangelov@ucla.edu>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 57 +++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 68591ca99a4f7..af26b3d60957b 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1341,6 +1341,62 @@ static void damon_test_commit_ctx(struct kunit *test)
damon_destroy_ctx(dst);
}
+static void damon_test_valid_probe_params(struct kunit *test)
+{
+ struct damon_ctx *ctx;
+ struct damon_probe *probe, *probe2;
+
+ ctx = damon_new_ctx();
+ if (!ctx)
+ kunit_skip(test, "ctx alloc fail");
+ probe = damon_new_probe();
+ if (!probe) {
+ damon_destroy_ctx(ctx);
+ kunit_skip(test, "probe alloc fail");
+ }
+ damon_add_probe(ctx, probe);
+
+ /* Parameters are validated only if any probe weight is set. */
+ ctx->attrs.sample_interval = 1;
+ ctx->attrs.aggr_interval = 1000000;
+ KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx));
+
+ /* Up to U8_MAX samples per aggregation interval are allowed. */
+ probe->weight = 100;
+ ctx->attrs.aggr_interval = 255;
+ KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx));
+
+ /* More samples could overflow the probe_hits counters. */
+ ctx->attrs.aggr_interval = 256;
+ KUNIT_EXPECT_FALSE(test, damon_valid_probe_params(ctx));
+
+ /* The largest weight whose weighted hit count fits in unsigned int. */
+ ctx->attrs.aggr_interval = 255;
+ probe->weight = UINT_MAX / 255;
+ KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx));
+
+ /* Any larger weight could overflow its weighted hit count. */
+ probe->weight = UINT_MAX / 255 + 1;
+ KUNIT_EXPECT_FALSE(test, damon_valid_probe_params(ctx));
+
+ /* With one sample per aggregation, even the largest weight fits. */
+ ctx->attrs.aggr_interval = 1;
+ probe->weight = UINT_MAX;
+ KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx));
+
+ /* The sum of all probes' weighted hit counts could also overflow. */
+ probe2 = damon_new_probe();
+ if (!probe2) {
+ damon_destroy_ctx(ctx);
+ kunit_skip(test, "probe2 alloc fail");
+ }
+ probe2->weight = 1;
+ damon_add_probe(ctx, probe2);
+ KUNIT_EXPECT_FALSE(test, damon_valid_probe_params(ctx));
+
+ damon_destroy_ctx(ctx);
+}
+
static void damos_test_filter_out(struct kunit *test)
{
struct damon_target *t;
@@ -1667,6 +1723,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damos_test_commit_migrate_hot),
KUNIT_CASE(damon_test_commit_target_regions),
KUNIT_CASE(damon_test_commit_ctx),
+ KUNIT_CASE(damon_test_valid_probe_params),
KUNIT_CASE(damos_test_filter_out),
KUNIT_CASE(damon_test_feed_loop_next_input),
KUNIT_CASE(damon_test_set_filters_default_reject),
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread