From: Song Hu <husong@kylinos.cn>
To: sj@kernel.org
Cc: akpm@linux-foundation.org, shu17az@gmail.com,
jiayuan.chen@shopee.com, damon@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Song Hu <husong@kylinos.cn>
Subject: [PATCH] mm/damon/tests/core-kunit: test damon_nr_accesses_mvsum()
Date: Fri, 10 Jul 2026 12:15:30 +0800 [thread overview]
Message-ID: <20260710041530.557455-1-husong@kylinos.cn> (raw)
damon_nr_accesses_mvsum() wraps damon_mvsum() with the monitoring
intervals of the context to compute the pseudo moving sum of a region's
access frequency, with a special case for when the whole aggregation
window remains. damon_mvsum() itself is already covered by
damon_test_mvsum(), but the wrapper is not.
Add a table-driven KUnit test that exercises the full-window-remaining
boundary (with both reset and not-yet-reset nr_accesses), partially
elapsed windows, and the no-window-remaining case.
Signed-off-by: Song Hu <husong@kylinos.cn>
---
mm/damon/tests/core-kunit.h | 49 +++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 0124f83b39b8..8c030282a638 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -683,6 +683,54 @@ static void damon_test_mvsum(struct kunit *test)
}
}
+/*
+ * Test damon_nr_accesses_mvsum(), which wraps damon_mvsum() with the monitoring
+ * intervals of the context. With a sample interval of 1 and an aggregation
+ * interval of 10, an aggregation window is 10 sample intervals long. Each row
+ * below specifies the passed sample intervals, the next aggregation time in
+ * sample intervals, the current and last nr_accesses of a region, and the
+ * expected return value.
+ */
+static void damon_test_nr_accesses_mvsum(struct kunit *test)
+{
+ unsigned long input_expects[] = {
+ /* passed, next_aggr, nr_accesses, last_nr_accesses, expect */
+ 0, 10, 5, 3, 3, /* bp=10000: unreset nr_accesses ignored */
+ 0, 10, 0, 7, 7, /* bp=10000: reset nr_accesses */
+ 5, 10, 3, 10, 8, /* bp=5000: half window left */
+ 8, 10, 3, 10, 5, /* bp=2000: 20% window left */
+ 10, 10, 42, 49, 42, /* bp=0: no window left */
+ };
+ struct damon_ctx *c = damon_new_ctx();
+ struct damon_region *r;
+ int i;
+
+ if (!c)
+ kunit_skip(test, "ctx alloc fail");
+
+ r = damon_new_region(0, 4096);
+ if (!r) {
+ damon_destroy_ctx(c);
+ kunit_skip(test, "region alloc fail");
+ }
+
+ c->attrs.sample_interval = 1;
+ c->attrs.aggr_interval = 10;
+
+ for (i = 0; i < ARRAY_SIZE(input_expects); i += 5) {
+ c->passed_sample_intervals = input_expects[i];
+ c->next_aggregation_sis = input_expects[i + 1];
+ r->nr_accesses = input_expects[i + 2];
+ r->last_nr_accesses = input_expects[i + 3];
+
+ KUNIT_EXPECT_EQ(test, (unsigned int)input_expects[i + 4],
+ damon_nr_accesses_mvsum(r, c));
+ }
+
+ damon_free_region(r);
+ damon_destroy_ctx(c);
+}
+
static void damos_test_new_filter(struct kunit *test)
{
struct damos_filter *filter;
@@ -1576,6 +1624,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_update_monitoring_result),
KUNIT_CASE(damon_test_set_attrs),
KUNIT_CASE(damon_test_mvsum),
+ KUNIT_CASE(damon_test_nr_accesses_mvsum),
KUNIT_CASE(damos_test_new_filter),
KUNIT_CASE(damos_test_commit_quota_goal),
KUNIT_CASE(damos_test_commit_quota_goals),
--
2.43.0
next reply other threads:[~2026-07-10 4:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 4:15 Song Hu [this message]
2026-07-10 14:02 ` [PATCH] mm/damon/tests/core-kunit: test damon_nr_accesses_mvsum() SJ Park
2026-07-11 5:11 ` Song Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260710041530.557455-1-husong@kylinos.cn \
--to=husong@kylinos.cn \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shu17az@gmail.com \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox