* [PATCH 1/2] mm/damon/core-kunit: test probe_hits handling at region split and merge
2026-08-18 3:45 [PATCH 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation Jason Angelov
@ 2026-08-18 3:45 ` Jason Angelov
2026-08-18 4:50 ` SJ Park
2026-08-18 3:45 ` [PATCH 2/2] mm/damon/core-kunit: test damon_valid_probe_params() Jason Angelov
2026-08-18 4:58 ` [PATCH 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation SJ Park
2 siblings, 1 reply; 6+ messages in thread
From: Jason Angelov @ 2026-08-18 3:45 UTC (permalink / raw)
To: sj, akpm
Cc: shu17az, jiayuan.chen, damon, linux-mm, linux-kernel,
Jason Angelov
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>
---
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 4a536d41cdb2..2db94d49c9ba 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.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] mm/damon/core-kunit: test damon_valid_probe_params()
2026-08-18 3:45 [PATCH 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation Jason Angelov
2026-08-18 3:45 ` [PATCH 1/2] mm/damon/core-kunit: test probe_hits handling at region split and merge Jason Angelov
@ 2026-08-18 3:45 ` Jason Angelov
2026-08-18 4:55 ` SJ Park
2026-08-18 4:58 ` [PATCH 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation SJ Park
2 siblings, 1 reply; 6+ messages in thread
From: Jason Angelov @ 2026-08-18 3:45 UTC (permalink / raw)
To: sj, akpm
Cc: shu17az, jiayuan.chen, damon, linux-mm, linux-kernel,
Jason Angelov
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>
---
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 2db94d49c9ba..b1ca4c8e03f0 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1338,6 +1338,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;
@@ -1664,6 +1720,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.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] mm/damon/core-kunit: test damon_valid_probe_params()
2026-08-18 3:45 ` [PATCH 2/2] mm/damon/core-kunit: test damon_valid_probe_params() Jason Angelov
@ 2026-08-18 4:55 ` SJ Park
0 siblings, 0 replies; 6+ messages in thread
From: SJ Park @ 2026-08-18 4:55 UTC (permalink / raw)
To: Jason Angelov
Cc: SJ Park, akpm, shu17az, jiayuan.chen, damon, linux-mm,
linux-kernel
On Tue, 18 Aug 2026 03:45:52 +0000 Jason Angelov <jasonangelov@ucla.edu> wrote:
> 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
Thank you for adding these tests.
>
> Signed-off-by: Jason Angelov <jasonangelov@ucla.edu>
Reviewed-by: SJ Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation
2026-08-18 3:45 [PATCH 0/2] mm/damon: add kunit tests for probe_hits handling and probe params validation Jason Angelov
2026-08-18 3:45 ` [PATCH 1/2] mm/damon/core-kunit: test probe_hits handling at region split and merge Jason Angelov
2026-08-18 3:45 ` [PATCH 2/2] mm/damon/core-kunit: test damon_valid_probe_params() Jason Angelov
@ 2026-08-18 4:58 ` SJ Park
2 siblings, 0 replies; 6+ messages in thread
From: SJ Park @ 2026-08-18 4:58 UTC (permalink / raw)
To: Jason Angelov
Cc: SJ Park, akpm, shu17az, jiayuan.chen, damon, linux-mm,
linux-kernel
On Tue, 18 Aug 2026 03:45:50 +0000 Jason Angelov <jasonangelov@ucla.edu> wrote:
> DAMON recently introduced probes and probe weights. Add kunit tests
> for the propagation of probe_hits at region split and merge, and the
> rejection of invalid probe parameters by damon_valid_probe_params().
Thank you for this patch, Jason. All patches look good to me.
I applied this series to damon/next [1] tree. If this patch is not added to
mm.git in short term (a few weeks), I will ask mm.git maintainer (Andrew
Morton) to pick this. So, no action from your side is needed for now.
Note that we are in the middle of the merge window for 7.3-rc1. Andrew may be
too busy to pick this until the end of the merge window. I will make the
action only after the end of the merge window.
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
[...]
^ permalink raw reply [flat|nested] 6+ messages in thread