* [PATCH 0/3] mm/damon: strictly respect min_nr_regions
@ 2026-02-28 22:28 SeongJae Park
2026-02-28 22:28 ` [PATCH 3/3] mm/damon/test/core-kunit: add damon_apply_min_nr_regions() test SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: SeongJae Park @ 2026-02-28 22:28 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Brendan Higgins, David Gow, damon, kunit-dev,
linux-kernel, linux-kselftest, linux-mm
DAMON core respects min_nr_regions only at merge operation. DAMON API
callers are therefore responsible to respect or ignore that. Only vaddr
ops is respecting that, but only for initial start time. DAMON sysfs
interface allows users to setup the initial regions that DAMON core also
respects. But, again, it works for only the initial time. Users
setting the regions for min_nr_regions can be difficult and inefficient,
when the min_nr_regions value is high. There was actually a report [1]
from a user. The use case was page granular access monitoring with a
large aggregation interval.
Make the following three changes for resolving the issue. First (patch
1), make DAMON core split regions at the beginning and every aggregation
interval, to respect the min_nr_regions. Second (patch 2), drop the
vaddr's split operations and related code that are no more needed.
Third (patch 3), add a kunit test for the newly introduced function.
[1] https://lore.kernel.org/CAC5umyjmJE9SBqjbetZZecpY54bHpn2AvCGNv3aF6J=1cfoPXQ@mail.gmail.com
Revision History
================
Changes from RFC v2
(https://lore.kernel.org/20260221180341.10313-1-sj@kernel.org)
- Drop RFC
- Rebase to latest mm-new
Changes from RFC v1
(https://lore.kernel.org/20260217000400.69056-1-sj@kernel.org)
- Split regions every aggregation interval
SeongJae Park (3):
mm/damon/core: split regions for min_nr_regions
mm/damon/vaddr: do not split regions for min_nr_regions
mm/damon/test/core-kunit: add damon_apply_min_nr_regions() test
mm/damon/core.c | 45 ++++++++++++++++++---
mm/damon/tests/core-kunit.h | 52 ++++++++++++++++++++++++
mm/damon/tests/vaddr-kunit.h | 76 ------------------------------------
mm/damon/vaddr.c | 70 +--------------------------------
4 files changed, 93 insertions(+), 150 deletions(-)
base-commit: e4506bd63542dc58b2913cd374c518526c008a2c
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 3/3] mm/damon/test/core-kunit: add damon_apply_min_nr_regions() test
2026-02-28 22:28 [PATCH 0/3] mm/damon: strictly respect min_nr_regions SeongJae Park
@ 2026-02-28 22:28 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2026-02-28 22:28 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Brendan Higgins, David Gow, damon, kunit-dev,
linux-kernel, linux-kselftest, linux-mm
Add a kunit test for the functionality of damon_apply_min_nr_regions().
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 52 +++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 596f33ec2d810..fcc1336b234c0 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1239,6 +1239,57 @@ static void damon_test_set_filters_default_reject(struct kunit *test)
damos_free_filter(target_filter);
}
+static void damon_test_apply_min_nr_regions_for(struct kunit *test,
+ unsigned long sz_regions, unsigned long min_region_sz,
+ unsigned long min_nr_regions,
+ unsigned long max_region_sz_expect,
+ unsigned long nr_regions_expect)
+{
+ struct damon_ctx *ctx;
+ struct damon_target *t;
+ struct damon_region *r;
+ unsigned long max_region_size;
+
+ ctx = damon_new_ctx();
+ if (!ctx)
+ kunit_skip(test, "ctx alloc fail\n");
+ t = damon_new_target();
+ if (!t) {
+ damon_destroy_ctx(ctx);
+ kunit_skip(test, "target alloc fail\n");
+ }
+ damon_add_target(ctx, t);
+ r = damon_new_region(0, sz_regions);
+ if (!r) {
+ damon_destroy_ctx(ctx);
+ kunit_skip(test, "region alloc fail\n");
+ }
+ damon_add_region(r, t);
+
+ ctx->min_region_sz = min_region_sz;
+ ctx->attrs.min_nr_regions = min_nr_regions;
+ max_region_size = damon_apply_min_nr_regions(ctx);
+
+ KUNIT_EXPECT_EQ(test, max_region_size, max_region_sz_expect);
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), nr_regions_expect);
+
+ damon_destroy_ctx(ctx);
+}
+
+static void damon_test_apply_min_nr_regions(struct kunit *test)
+{
+ /* common, expected setup */
+ damon_test_apply_min_nr_regions_for(test, 10, 1, 10, 1, 10);
+ /* no zero size limit */
+ damon_test_apply_min_nr_regions_for(test, 10, 1, 15, 1, 10);
+ /* max size should be aligned by min_region_sz */
+ damon_test_apply_min_nr_regions_for(test, 10, 2, 2, 6, 2);
+ /*
+ * when min_nr_regions and min_region_sz conflicts, min_region_sz wins.
+ */
+ damon_test_apply_min_nr_regions_for(test, 10, 2, 10, 2, 5);
+}
+
static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_target),
KUNIT_CASE(damon_test_regions),
@@ -1265,6 +1316,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damos_test_filter_out),
KUNIT_CASE(damon_test_feed_loop_next_input),
KUNIT_CASE(damon_test_set_filters_default_reject),
+ KUNIT_CASE(damon_test_apply_min_nr_regions),
{},
};
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-28 22:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-28 22:28 [PATCH 0/3] mm/damon: strictly respect min_nr_regions SeongJae Park
2026-02-28 22:28 ` [PATCH 3/3] mm/damon/test/core-kunit: add damon_apply_min_nr_regions() test SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox