[RFC PATCH 00/14] mm/damon: minor improvements for code readability and tests

0 views
Skip to first unread message

SeongJae Park

unread,
May 20, 2026, 2:29:10 AM (5 days ago) May 20
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
Implement minor improvements on code readability and tests for DAMON.

First seven patches are for DAMON code readability and resulting
maintenance. Patches 1 and 2 make damon_set_regions() safer and easier
to read. Patches 3 and 4 remove fragmented DAMON API use cases. Patches
5-7 hides unused core functions that are unnecessarily exposed to API
callers.

The following seven patches are for DAMON tests improvement. Patches 8
and 9 adds and removes DAMON_DEBUG_SANITY verifications to ensure
reasonable test coverage without too high overhead. Patch 10 adds a new
kunit test for damon_set_regions(). Patch 11 makes sysfs.py selftest
more gracefully finishes under test failures. Patches 12-13 adds simple
sysfs.sh test cases for the monitoring intervals goal directory, the
addr_unit file and the pause file.

SeongJae Park (14):
mm/damon/core: safely handle no region case in damon_set_regions()
mm/damon/core: do not use region out of a loop in damon_set_regions()
samples/damon/mtier: replace damon_add_region() with
damon_set_regions()
mm/damon/tests/vaddr-kunit: replace damon_add_region() with
damon_set_regions()
mm/damon/core: hide damon_add_region()
mm/damon/core: hide damon_insert_region()
mm/damon/core: hide damon_destroy_region()
mm/damon/core: add kdamond_call() debug_sanity check
mm/damon/core: remove damon_verify_nr_regions()
mm/damon/tests/core-kunit: add damon_set_regions() test cases
selftests/damon/sysfs.py: stop kdamonds before failing
selftests/damon/sysfs.sh: test monitoring intervals goal dir
selftests/damon/sysfs.sh: test addr_unit file existence
selftests/damon/sysfs.sh: test pause file existence

include/linux/damon.h | 13 ---
mm/damon/core.c | 92 ++++++++++++----
mm/damon/tests/core-kunit.h | 142 +++++++++++++++++++++----
mm/damon/tests/vaddr-kunit.h | 16 +--
samples/damon/mtier.c | 10 +-
tools/testing/selftests/damon/sysfs.py | 4 +
tools/testing/selftests/damon/sysfs.sh | 14 +++
7 files changed, 223 insertions(+), 68 deletions(-)


base-commit: 8b8727a18b7f247aed7e0476b92d07fc59c04cb8
--
2.47.3

SeongJae Park

unread,
May 20, 2026, 11:54:01 PM (4 days ago) May 20
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
Implement minor improvements on code readability and tests for DAMON.

First seven patches are for DAMON code readability and resulting
maintenance. Patches 1 and 2 make damon_set_regions() safer and easier
to read. Patches 3 and 4 remove fragmented DAMON API use cases. Patches
5-7 hides unused core functions that are unnecessarily exposed to API
callers.

The following seven patches are for DAMON tests improvement. Patches 8
and 9 adds and removes DAMON_DEBUG_SANITY verifications to ensure
reasonable test coverage without too high overhead. Patch 10 adds a new
kunit test for damon_set_regions(). Patch 11 makes sysfs.py selftest
more gracefully finishes under test failures. Patches 12-13 adds simple
sysfs.sh test cases for the monitoring intervals goal directory, the
addr_unit file and the pause file.

Changes from RFC v1
- RFC v1: https://lore.kernel.org/2026052006285...@kernel.org
- Handle damon_set_regions() failure in vaddr unit test.
- Free ranges array in vaddr unit test.
- Fix wrong region address verification.
- Fix typos in selftest: s/exit/exist/

SeongJae Park (14):
mm/damon/core: safely handle no region case in damon_set_regions()
mm/damon/core: do not use region out of a loop in damon_set_regions()
samples/damon/mtier: replace damon_add_region() with
damon_set_regions()
mm/damon/tests/vaddr-kunit: replace damon_add_region() with
damon_set_regions()
mm/damon/core: hide damon_add_region()
mm/damon/core: hide damon_insert_region()
mm/damon/core: hide damon_destroy_region()
mm/damon/core: add kdamond_call() debug_sanity check
mm/damon/core: remove damon_verify_nr_regions()
mm/damon/tests/core-kunit: add damon_set_regions() test cases
selftests/damon/sysfs.py: stop kdamonds before failing
selftests/damon/sysfs.sh: test monitoring intervals goal dir
selftests/damon/sysfs.sh: test addr_unit file existence
selftests/damon/sysfs.sh: test pause file existence

include/linux/damon.h | 13 ---
mm/damon/core.c | 92 ++++++++++++----
mm/damon/tests/core-kunit.h | 142 +++++++++++++++++++++----
mm/damon/tests/vaddr-kunit.h | 24 +++--
samples/damon/mtier.c | 10 +-
tools/testing/selftests/damon/sysfs.py | 4 +
tools/testing/selftests/damon/sysfs.sh | 14 +++
7 files changed, 230 insertions(+), 69 deletions(-)


base-commit: ae90ad6788e582af07da1b2ce81277d5a65f4f89
--
2.47.3

SeongJae Park

unread,
May 20, 2026, 11:54:03 PM (4 days ago) May 20
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
DAMON virtual address operation set (vaddr) unit tests is using
damon_add_region() for setup of DAMON monitoring target region
boundaries setup. But, damon_set_regions() is designed for exactly the
purpose. All other DAMON API callers use the function for the purpose.
Replace damon_add_region() usage in the unit tests with
damon_set_regions(), for unifying the use case and reducing the
maintenance cost.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/vaddr-kunit.h | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
index 98e734d77d517..de30db9b753e5 100644
--- a/mm/damon/tests/vaddr-kunit.h
+++ b/mm/damon/tests/vaddr-kunit.h
@@ -132,22 +132,32 @@ static void damon_do_test_apply_three_regions(struct kunit *test,
unsigned long *expected, int nr_expected)
{
struct damon_target *t;
+ struct damon_addr_range *ranges;
struct damon_region *r;
int i;

t = damon_new_target();
if (!t)
kunit_skip(test, "target alloc fail");
+
+ ranges = kmalloc_array(nr_regions / 2, sizeof(*ranges), GFP_KERNEL);
+ if (!ranges) {
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "ranges alloc fail");
+ }
for (i = 0; i < nr_regions / 2; i++) {
- r = damon_new_region(regions[i * 2], regions[i * 2 + 1]);
- if (!r) {
- damon_destroy_target(t, NULL);
- kunit_skip(test, "region alloc fail");
- }
- damon_add_region(r, t);
+ ranges[i].start = regions[i * 2];
+ ranges[i].end = regions[i * 2 + 1];
+ }
+ if (damon_set_regions(t, ranges, nr_regions / 2,
+ DAMON_MIN_REGION_SZ)) {
+ kfree(ranges);
+ kunit_skip(test, "damon_set_regions() fail");
}
+ kfree(ranges);

- damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ);
+ if (damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ))
+ kunit_skip(test, "second damon_set_regions() fail");

for (i = 0; i < nr_expected / 2; i++) {
r = __nth_region_of(t, i);
--
2.47.3

SeongJae Park

unread,
May 20, 2026, 11:54:06 PM (4 days ago) May 20
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
damon_set_regions() is one of the main DAMON kernel API functions that
set up the monitoring target memory region boundaries. Implement unit
tests for verifying its basic functionalities.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/core-kunit.h | 142 ++++++++++++++++++++++++++++++------
1 file changed, 120 insertions(+), 22 deletions(-)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 866f716e5760d..1cfb8c176b873 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -390,41 +390,139 @@ static void damon_test_ops_registration(struct kunit *test)
}
}

-static void damon_test_set_regions(struct kunit *test)
+static void damon_test_set_regions_for(struct kunit *test,
+ struct damon_addr_range *old_ranges, int sz_old_ranges,
+ struct damon_addr_range *new_ranges, int sz_new_ranges,
+ unsigned long min_region_sz,
+ struct damon_addr_range *expect_ranges, int sz_expect_ranges)
{
- struct damon_target *t = damon_new_target();
- struct damon_region *r1, *r2;
- struct damon_addr_range range = {.start = 8, .end = 28};
- unsigned long expects[] = {8, 16, 16, 24, 24, 28};
- int expect_idx = 0;
+ struct damon_target *t;
struct damon_region *r;
+ int i;

+ t = damon_new_target();
if (!t)
kunit_skip(test, "target alloc fail");
- r1 = damon_new_region(4, 16);
- if (!r1) {
- damon_free_target(t);
- kunit_skip(test, "region alloc fail");
- }
- r2 = damon_new_region(24, 32);
- if (!r2) {
- damon_free_target(t);
- damon_free_region(r1);
- kunit_skip(test, "second region alloc fail");
+ for (i = 0; i < sz_old_ranges; i++) {
+ r = damon_new_region(old_ranges[i].start, old_ranges[i].end);
+ if (!r) {
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "%d-th r alloc fail\n", i);
+ }
+ damon_add_region(r, t);
}

- damon_add_region(r1, t);
- damon_add_region(r2, t);
- damon_set_regions(t, &range, 1, 1);
+ damon_set_regions(t, new_ranges, sz_new_ranges, min_region_sz);

- KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 3);
+ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), sz_expect_ranges);
+ if (damon_nr_regions(t) != sz_expect_ranges) {
+ damon_destroy_target(t, NULL);
+ return;
+ }
+ i = 0;
damon_for_each_region(r, t) {
- KUNIT_EXPECT_EQ(test, r->ar.start, expects[expect_idx++]);
- KUNIT_EXPECT_EQ(test, r->ar.end, expects[expect_idx++]);
+ KUNIT_EXPECT_EQ(test, r->ar.start, expect_ranges[i].start);
+ KUNIT_EXPECT_EQ(test, r->ar.end, expect_ranges[i++].end);
}
+
damon_destroy_target(t, NULL);
}

+static void damon_test_set_regions(struct kunit *test)
+{
+ /* Initial build up on empty target. */
+ damon_test_set_regions_for(test,
+ (struct damon_addr_range[]){}, 0,
+ (struct damon_addr_range[]){
+ {.start = 5, .end = 15},
+ {.start = 15, .end = 25},
+ }, 2,
+ 1,
+ (struct damon_addr_range[]){
+ {.start = 5, .end = 15},
+ {.start = 15, .end = 25},
+ }, 2);
+ /* Un-intersecting regions should be removed. */
+ damon_test_set_regions_for(test,
+ (struct damon_addr_range[]){
+ {.start = 4, .end = 16},
+ {.start = 24, .end = 32},
+ }, 2,
+ (struct damon_addr_range[]){
+ {.start = 18, .end = 23},
+ }, 1,
+ 1,
+ (struct damon_addr_range[]){
+ {.start = 18, .end = 23},
+ }, 1);
+ /*
+ * Holes should be filled up with new regions.
+ *
+ * old: [4, 16) [24, 32)
+ * new: [8, 28)
+ * expect: [8, 16)[16,24),[24, 28)
+ */
+ damon_test_set_regions_for(test,
+ (struct damon_addr_range[]){
+ {.start = 4, .end = 16},
+ {.start = 24, .end = 32},
+ }, 2,
+ (struct damon_addr_range[]){
+ {.start = 8, .end = 28},
+ }, 1,
+ 1,
+ (struct damon_addr_range[]){
+ {.start = 8, .end = 16},
+ {.start = 16, .end = 24},
+ {.start = 24, .end = 28},
+ }, 3);
+ /*
+ * New regions should be able to be appended.
+ *
+ * old: [0, 4)[4, 17)
+ * new: [0, 15) [25, 40)
+ * expect: [0, 4)[4, 15) [25, 40)
+ */
+ damon_test_set_regions_for(test,
+ (struct damon_addr_range[]){
+ {.start = 0, .end = 4},
+ {.start = 4, .end = 17},
+ }, 2,
+ (struct damon_addr_range[]){
+ {.start = 0, .end = 15},
+ {.start = 25, .end = 40},
+ }, 2,
+ 1,
+ (struct damon_addr_range[]){
+ {.start = 0, .end = 4},
+ {.start = 4, .end = 15},
+ {.start = 25, .end = 40},
+ }, 3);
+ /*
+ * New regions should be able to be inserted.
+ *
+ * old: [0, 4) [42, 52)
+ * new: [0, 15) [25, 40) [44, 50)
+ * expect: [0, 15) [25, 40) [44, 50)
+ */
+ damon_test_set_regions_for(test,
+ (struct damon_addr_range[]){
+ {.start = 0, .end = 4},
+ {.start = 42, .end = 52},
+ }, 2,
+ (struct damon_addr_range[]){
+ {.start = 0, .end = 15},
+ {.start = 25, .end = 40},
+ {.start = 44, .end = 50},
+ }, 3,
+ 1,
+ (struct damon_addr_range[]){
+ {.start = 0, .end = 15},
+ {.start = 25, .end = 40},
+ {.start = 44, .end = 50},
+ }, 3);
+}
+
static void damon_test_nr_accesses_to_accesses_bp(struct kunit *test)
{
struct damon_attrs attrs = {
--
2.47.3

SeongJae Park

unread,
May 21, 2026, 10:34:39 AM (4 days ago) May 21
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
Implement minor improvements on code readability and tests for DAMON.

First seven patches are for DAMON code readability and resulting
maintenance. Patches 1 and 2 make damon_set_regions() safer and easier
to read. Patches 3 and 4 remove fragmented DAMON API use cases. Patches
5-7 hides unused core functions that are unnecessarily exposed to API
callers.

The following seven patches are for DAMON tests improvement. Patches 8
and 9 adds and removes DAMON_DEBUG_SANITY verifications to ensure
reasonable test coverage without too high overhead. Patch 10 adds a new
kunit test for damon_set_regions(). Patch 11 makes sysfs.py selftest
more gracefully finishes under test failures. Patches 12-13 adds simple
sysfs.sh test cases for the monitoring intervals goal directory, the
addr_unit file and the pause file.

Changes from RFC v1.1
- RFC v1.1: https://lore.kernel.org/202605210353...@kernel.org
- Free DAMON target in vaddr unit test fail-out path.
mm/damon/tests/vaddr-kunit.h | 27 +++--
samples/damon/mtier.c | 10 +-
tools/testing/selftests/damon/sysfs.py | 4 +
tools/testing/selftests/damon/sysfs.sh | 14 +++
7 files changed, 233 insertions(+), 69 deletions(-)


base-commit: ac6b83c7bf3671e8ff0d541cf03e6eaeed00a79e
--
2.47.3

SeongJae Park

unread,
May 21, 2026, 10:34:40 AM (4 days ago) May 21
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
DAMON virtual address operation set (vaddr) unit tests is using
damon_add_region() for setup of DAMON monitoring target region
boundaries setup. But, damon_set_regions() is designed for exactly the
purpose. All other DAMON API callers use the function for the purpose.
Replace damon_add_region() usage in the unit tests with
damon_set_regions(), for unifying the use case and reducing the
maintenance cost.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/vaddr-kunit.h | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
index 98e734d77d517..563fbc7e3f448 100644
--- a/mm/damon/tests/vaddr-kunit.h
+++ b/mm/damon/tests/vaddr-kunit.h
@@ -132,22 +132,35 @@ static void damon_do_test_apply_three_regions(struct kunit *test,
unsigned long *expected, int nr_expected)
{
struct damon_target *t;
+ struct damon_addr_range *ranges;
struct damon_region *r;
int i;

t = damon_new_target();
if (!t)
kunit_skip(test, "target alloc fail");
+
+ ranges = kmalloc_array(nr_regions / 2, sizeof(*ranges), GFP_KERNEL);
+ if (!ranges) {
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "ranges alloc fail");
+ }
for (i = 0; i < nr_regions / 2; i++) {
- r = damon_new_region(regions[i * 2], regions[i * 2 + 1]);
- if (!r) {
- damon_destroy_target(t, NULL);
- kunit_skip(test, "region alloc fail");
- }
- damon_add_region(r, t);
+ ranges[i].start = regions[i * 2];
+ ranges[i].end = regions[i * 2 + 1];
}
+ if (damon_set_regions(t, ranges, nr_regions / 2,
+ DAMON_MIN_REGION_SZ)) {
+ kfree(ranges);
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "damon_set_regions() fail");
+ }
+ kfree(ranges);

- damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ);
+ if (damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ)) {
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "second damon_set_regions() fail");
+ }

SeongJae Park

unread,
May 21, 2026, 10:34:43 AM (4 days ago) May 21
to SeongJae Park, Andrew Morton, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
damon_set_regions() is one of the main DAMON kernel API functions that
set up the monitoring target memory region boundaries. Implement unit
tests for verifying its basic functionalities.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/core-kunit.h | 142 ++++++++++++++++++++++++++++++------
1 file changed, 120 insertions(+), 22 deletions(-)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 866f716e5760d..1cfb8c176b873 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -390,41 +390,139 @@ static void damon_test_ops_registration(struct kunit *test)
}
}

-static void damon_test_set_regions(struct kunit *test)
+static void damon_test_set_regions_for(struct kunit *test,
+ struct damon_addr_range *old_ranges, int sz_old_ranges,
+ struct damon_addr_range *new_ranges, int sz_new_ranges,
+ unsigned long min_region_sz,
+ struct damon_addr_range *expect_ranges, int sz_expect_ranges)
{
- struct damon_target *t = damon_new_target();
- struct damon_region *r1, *r2;
- struct damon_addr_range range = {.start = 8, .end = 28};
- unsigned long expects[] = {8, 16, 16, 24, 24, 28};
- int expect_idx = 0;
+ struct damon_target *t;
struct damon_region *r;
+ int i;

+ t = damon_new_target();
if (!t)
kunit_skip(test, "target alloc fail");
- r1 = damon_new_region(4, 16);
- if (!r1) {
- damon_free_target(t);
- kunit_skip(test, "region alloc fail");
- }
- r2 = damon_new_region(24, 32);
- if (!r2) {
- damon_free_target(t);
- damon_free_region(r1);
- kunit_skip(test, "second region alloc fail");
+ for (i = 0; i < sz_old_ranges; i++) {
+ r = damon_new_region(old_ranges[i].start, old_ranges[i].end);
+ if (!r) {
+ damon_destroy_target(t, NULL);

SeongJae Park

unread,
May 22, 2026, 11:40:37 AM (3 days ago) May 22
to Andrew Morton, SeongJae Park, Brendan Higgins, David Gow, Shuah Khan, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
Implement minor improvements on code readability and tests for DAMON.

First seven patches are for DAMON code readability and resulting
maintenance. Patches 1 and 2 make damon_set_regions() safer and easier
to read. Patches 3 and 4 remove fragmented DAMON API use cases. Patches
5-7 hides unused core functions that are unnecessarily exposed to API
callers.

The following seven patches are for DAMON tests improvement. Patches 8
and 9 adds and removes DAMON_DEBUG_SANITY verifications to ensure
reasonable test coverage without too high overhead. Patch 10 adds a new
kunit test for damon_set_regions(). Patch 11 makes sysfs.py selftest
more gracefully finishes under test failures. Patches 12-13 adds simple
sysfs.sh test cases for the monitoring intervals goal directory, the
addr_unit file and the pause file.

Chagens from RFC v1.2
- RFC v1.2: https://lore.kernel.org/202605211434...@kernel.org
- Drop RFC.
- Rebase to latest mm-new.
base-commit: 712074729b7852a468166a84b131ca9f12680629
--
2.47.3

SeongJae Park

unread,
May 22, 2026, 11:40:38 AM (3 days ago) May 22
to Andrew Morton, SeongJae Park, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
DAMON virtual address operation set (vaddr) unit tests is using
damon_add_region() for setup of DAMON monitoring target region
boundaries setup. But, damon_set_regions() is designed for exactly the
purpose. All other DAMON API callers use the function for the purpose.
Replace damon_add_region() usage in the unit tests with
damon_set_regions(), for unifying the use case and reducing the
maintenance cost.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/vaddr-kunit.h | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
index 98e734d77d517..563fbc7e3f448 100644
--- a/mm/damon/tests/vaddr-kunit.h
+++ b/mm/damon/tests/vaddr-kunit.h
@@ -132,22 +132,35 @@ static void damon_do_test_apply_three_regions(struct kunit *test,
unsigned long *expected, int nr_expected)
{
struct damon_target *t;
+ struct damon_addr_range *ranges;
struct damon_region *r;
int i;

t = damon_new_target();
if (!t)
kunit_skip(test, "target alloc fail");
+
+ ranges = kmalloc_array(nr_regions / 2, sizeof(*ranges), GFP_KERNEL);
+ if (!ranges) {
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "ranges alloc fail");
+ }
for (i = 0; i < nr_regions / 2; i++) {
- r = damon_new_region(regions[i * 2], regions[i * 2 + 1]);
- if (!r) {
- damon_destroy_target(t, NULL);
- kunit_skip(test, "region alloc fail");
- }
- damon_add_region(r, t);
+ ranges[i].start = regions[i * 2];
+ ranges[i].end = regions[i * 2 + 1];
}
+ if (damon_set_regions(t, ranges, nr_regions / 2,
+ DAMON_MIN_REGION_SZ)) {
+ kfree(ranges);
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "damon_set_regions() fail");
+ }
+ kfree(ranges);

- damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ);
+ if (damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ)) {
+ damon_destroy_target(t, NULL);
+ kunit_skip(test, "second damon_set_regions() fail");
+ }

SeongJae Park

unread,
May 22, 2026, 11:40:40 AM (3 days ago) May 22
to Andrew Morton, SeongJae Park, Brendan Higgins, David Gow, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
damon_set_regions() is one of the main DAMON kernel API functions that
set up the monitoring target memory region boundaries. Implement unit
tests for verifying its basic functionalities.

Signed-off-by: SeongJae Park <s...@kernel.org>
---
mm/damon/tests/core-kunit.h | 142 ++++++++++++++++++++++++++++++------
1 file changed, 120 insertions(+), 22 deletions(-)

diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 866f716e5760d..1cfb8c176b873 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -390,41 +390,139 @@ static void damon_test_ops_registration(struct kunit *test)
}
}

-static void damon_test_set_regions(struct kunit *test)
+static void damon_test_set_regions_for(struct kunit *test,
+ struct damon_addr_range *old_ranges, int sz_old_ranges,
+ struct damon_addr_range *new_ranges, int sz_new_ranges,
+ unsigned long min_region_sz,
+ struct damon_addr_range *expect_ranges, int sz_expect_ranges)
{
- struct damon_target *t = damon_new_target();
- struct damon_region *r1, *r2;
- struct damon_addr_range range = {.start = 8, .end = 28};
- unsigned long expects[] = {8, 16, 16, 24, 24, 28};
- int expect_idx = 0;
+ struct damon_target *t;
struct damon_region *r;
+ int i;

+ t = damon_new_target();
if (!t)
kunit_skip(test, "target alloc fail");
- r1 = damon_new_region(4, 16);
- if (!r1) {
- damon_free_target(t);
- kunit_skip(test, "region alloc fail");
- }
- r2 = damon_new_region(24, 32);
- if (!r2) {
- damon_free_target(t);
- damon_free_region(r1);
- kunit_skip(test, "second region alloc fail");
+ for (i = 0; i < sz_old_ranges; i++) {
+ r = damon_new_region(old_ranges[i].start, old_ranges[i].end);
+ if (!r) {
+ damon_destroy_target(t, NULL);

SeongJae Park

unread,
May 22, 2026, 4:13:57 PM (2 days ago) May 22
to SeongJae Park, Andrew Morton, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org
Dropped individual recipients except Andrew.

On Fri, 22 May 2026 08:40:11 -0700 SeongJae Park <s...@kernel.org> wrote:

> Implement minor improvements on code readability and tests for DAMON.

Sashiko failed reviewing this completely, but found no blockers. Also it
didn't find a blocker from the previous version of this series, which is same
to this version except the baseline commit.

[1] https://sashiko.dev/#/patchset/20260522154026.80546-1-sj%40kernel.org


Thanks,
SJ

[...]

Andrew Morton

unread,
May 22, 2026, 4:22:03 PM (2 days ago) May 22
to SeongJae Park, da...@lists.linux.dev, kuni...@googlegroups.com, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, linu...@kvack.org, Brendan Higgins, David Gow, Shuah Khan
On Fri, 22 May 2026 13:13:52 -0700 SeongJae Park <s...@kernel.org> wrote:

> Dropped individual recipients except Andrew.

Re-added them ;)

> On Fri, 22 May 2026 08:40:11 -0700 SeongJae Park <s...@kernel.org> wrote:
>
> > Implement minor improvements on code readability and tests for DAMON.
>
> Sashiko failed reviewing this completely, but found no blockers. Also it
> didn't find a blocker from the previous version of this series, which is same
> to this version except the baseline commit.
>
> [1] https://sashiko.dev/#/patchset/20260522154026.80546-1-sj%40kernel.org

OK, thanks for checking - I'll add this series to mm.git's mm-new
branch.
Reply all
Reply to author
Forward
0 new messages