* [PATCH v3 0/2] mm/damon/core: detect internal variation above max_nr_regions/2
@ 2026-06-29 14:56 SJ Park
2026-06-29 14:56 ` [PATCH v3 2/2] mm/damon/tests/core-kunit: test split " SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: SJ Park @ 2026-06-29 14:56 UTC (permalink / raw)
To: Andrew Morton
Cc: SJ Park, Brendan Higgins, David Gow, Jiayuan Chen, Shu Anzai,
damon, kunit-dev, linux-kernel, linux-kselftest, linux-mm
kdamond_split_regions() bails out early when nr_regions is already
above max_nr_regions / 2. A large region that picks up new internal
variation after that point never gets split, so we lose visibility
into its hot/cold structure.
We hit this with damon-paddr on hugepage workloads and damon-vaddr
on processes that mmap a large anonymous range.
Example with max_nr_regions == 1500. A target ends up with 799
small hot/cold regions plus one big region (an earlier merge
collapsed a uniformly-accessed range into a single piece):
H:hot
C:cold
r1 r2 r3 r800
HHHHHH|CCCCCC|HHHHHH|...|HHHHHH..........................|
nr_regions = 800 > max_nr_regions / 2 = 750
Now a cold subarea shows up inside r800:
r1 r2 r3 r800
HHHHHH|CCCCCC|HHHHHH|...|HHHHHH........CCCCCC.............|
The small regions can't merge with each other (their access counts
differ), so budget never frees up. r800 can't be split because
nr_regions > max_nr_regions / 2 returns early. The cold subarea
stays invisible.
Patch 1 keeps refining on this path: when nr_regions is above
max_nr_regions / 2 but still under the maximum, it splits a fraction
of the regions instead of returning. The fraction shrinks as the
remaining budget shrinks, so the count approaches max_nr_regions
smoothly. A useless split is undone by the next merge cycle.
Patch 2 adds a KUnit test for the case where nr_regions is already
above max_nr_regions / 2.
Thanks to SJ for the suggestion to drive the split fraction
from the remaining budget rather than an age-based filter.
Changes from v2
- v2: https://lore.kernel.org/20260626085851.70754-1-jiayuan.chen@linux.dev
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Changes from v1
- v1: https://lore.kernel.org/damon/20260521045236.115749-1-jiayuan.chen@linux.dev/
- Some feedback from SJ.
Jiayuan Chen (2):
mm/damon/core: split a fraction of regions when nr_regions exceeds
max/2
mm/damon/tests/core-kunit: test split above max_nr_regions/2
mm/damon/core.c | 49 +++++++++++++++++++++++++---
mm/damon/tests/core-kunit.h | 64 +++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 5 deletions(-)
base-commit: 86100fb7e27ebb5da22fc8a2810eebcf8cc897e8
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v3 2/2] mm/damon/tests/core-kunit: test split above max_nr_regions/2
2026-06-29 14:56 [PATCH v3 0/2] mm/damon/core: detect internal variation above max_nr_regions/2 SJ Park
@ 2026-06-29 14:56 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-06-29 14:56 UTC (permalink / raw)
To: Andrew Morton
Cc: Jiayuan Chen, Brendan Higgins, David Gow, Jiayuan Chen, SJ Park,
Shu Anzai, damon, kunit-dev, linux-kernel, linux-kselftest,
linux-mm
From: Jiayuan Chen <jiayuan.chen@shopee.com>
Add a test that exercises kdamond_split_regions() when the total
region count is already above max_nr_regions / 2, asserting that the
function still splits a fraction of the regions (makes progress) and
does not overshoot max_nr_regions.
The region size and min_region_sz are picked so the split arithmetic
does not depend on the page size.
All tests pass:
damon: pass:31 fail:0 skip:0 total:31
Totals: pass:31 fail:0 skip:0 total:31
Link: https://lore.kernel.org/20260626085851.70754-3-jiayuan.chen@linux.dev
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>
Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
Reviewed-by: SJ Park <sj@kernel.org>
Cc: SJ Park <sj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Shu Anzai <shu17az@gmail.com>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 64 +++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index c5f5124c3d1f4..a00168730445d 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -335,6 +335,69 @@ static void damon_test_split_regions_of(struct kunit *test)
damon_destroy_ctx(c);
}
+/*
+ * When the total region count is already above max_nr_regions / 2,
+ * kdamond_split_regions() must keep refining the resolution by splitting a
+ * fraction of the regions (making progress), without exceeding
+ * max_nr_regions.
+ */
+static void damon_test_split_above_half_progresses(struct kunit *test)
+{
+ struct damon_ctx *c;
+ struct damon_target *t;
+ struct damon_region *r;
+ unsigned long start;
+ unsigned int nr_before, nr_after, i;
+ const unsigned int nr_init = 760;
+ const unsigned long region_sz = 100;
+
+ c = damon_new_ctx();
+ if (!c)
+ kunit_skip(test, "ctx alloc fail");
+
+ /* Keep the split arithmetic independent of the page size */
+ c->min_region_sz = 1;
+ c->attrs.min_nr_regions = 10;
+ c->attrs.max_nr_regions = 1500;
+
+ t = damon_new_target();
+ if (!t) {
+ damon_destroy_ctx(c);
+ kunit_skip(test, "target alloc fail");
+ }
+
+ for (i = 0; i < nr_init; i++) {
+ start = i * region_sz;
+ r = damon_new_region(start, start + region_sz);
+ if (!r) {
+ damon_free_target(t);
+ damon_destroy_ctx(c);
+ kunit_skip(test, "region alloc fail");
+ }
+ r->nr_accesses = (i & 1) ? 0 : 100;
+ r->age = 5;
+ damon_add_region(r, t);
+ }
+
+ damon_add_target(c, t);
+
+ nr_before = damon_nr_regions(t);
+ /* Above max_nr_regions / 2, so the blanket-split path is skipped */
+ KUNIT_EXPECT_GT(test, (unsigned long)nr_before,
+ c->attrs.max_nr_regions / 2);
+
+ kdamond_split_regions(c);
+
+ nr_after = damon_nr_regions(t);
+ /* Still made progress ... */
+ KUNIT_EXPECT_GT(test, nr_after, nr_before);
+ /* ... but did not overshoot the configured maximum */
+ KUNIT_EXPECT_LE(test, (unsigned long)nr_after,
+ c->attrs.max_nr_regions);
+
+ damon_destroy_ctx(c);
+}
+
static void damon_test_ops_registration(struct kunit *test)
{
struct damon_ctx *c = damon_new_ctx();
@@ -1491,6 +1554,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_merge_two),
KUNIT_CASE(damon_test_merge_regions_of),
KUNIT_CASE(damon_test_split_regions_of),
+ KUNIT_CASE(damon_test_split_above_half_progresses),
KUNIT_CASE(damon_test_ops_registration),
KUNIT_CASE(damon_test_set_regions),
KUNIT_CASE(damon_test_nr_accesses_to_accesses_bp),
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-29 14:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 14:56 [PATCH v3 0/2] mm/damon/core: detect internal variation above max_nr_regions/2 SJ Park
2026-06-29 14:56 ` [PATCH v3 2/2] mm/damon/tests/core-kunit: test split " SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox