From: Karl Mehltretter <kmehltretter@gmail.com>
To: SJ Park <sj@kernel.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Lian Wang <lianux.mm@gmail.com>,
Kunwu Chan <kunwu.chan@gmail.com>,
damon@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] mm/damon/tests/core-kunit: test PSI goal values with explicit samples
Date: Mon, 21 Sep 2026 04:00:13 +0200 [thread overview]
Message-ID: <20260921020013.33105-3-kmehltretter@gmail.com> (raw)
In-Reply-To: <20260921020013.33105-1-kmehltretter@gmail.com>
Test the PSI current-value helper with explicit totals so the result does
not depend on the test system's memory pressure. Cover an unmeasured
consist goal, unmeasured temporal goals with zero and nonzero effective
quotas, and measured rounds for both tuners. Check last_psi_total after
each call.
With the old unmeasured-round behavior retained in the helper, the
temporal check with a nonzero effective quota fails.
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
mm/damon/tests/core-kunit.h | 43 +++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 5ff0436c58441..a30040826874e 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -910,6 +910,48 @@ static void damos_test_commit_quota_goal(struct kunit *test)
});
}
+static void damos_test_set_psi_current_val(struct kunit *test)
+{
+ struct damos s = {
+ .quota.goal_tuner = DAMOS_QUOTA_GOAL_TUNER_CONSIST,
+ };
+ struct damos_quota_goal goal = {
+ .metric = DAMOS_QUOTA_SOME_MEM_PSI_US,
+ .target_value = 100,
+ .last_psi_total = U64_MAX,
+ };
+
+ /* uninitialized last_psi_total keeps the consist tuner quota */
+ damos_set_psi_current_val(1000, &goal, &s);
+ KUNIT_EXPECT_EQ(test, goal.current_value, 100ul);
+ KUNIT_EXPECT_EQ(test, goal.last_psi_total, 1000ull);
+
+ /* initialized last_psi_total gives the delta */
+ damos_set_psi_current_val(1030, &goal, &s);
+ KUNIT_EXPECT_EQ(test, goal.current_value, 30ul);
+ KUNIT_EXPECT_EQ(test, goal.last_psi_total, 1030ull);
+
+ /* temporal tuner keeps a zero quota */
+ s.quota.goal_tuner = DAMOS_QUOTA_GOAL_TUNER_TEMPORAL;
+ s.quota.esz = 0;
+ goal.last_psi_total = U64_MAX;
+ damos_set_psi_current_val(2000, &goal, &s);
+ KUNIT_EXPECT_EQ(test, goal.current_value, 100ul);
+ KUNIT_EXPECT_EQ(test, goal.last_psi_total, 2000ull);
+
+ /* temporal tuner keeps a non-zero quota */
+ s.quota.esz = SZ_64K;
+ goal.last_psi_total = U64_MAX;
+ damos_set_psi_current_val(3000, &goal, &s);
+ KUNIT_EXPECT_EQ(test, goal.current_value, 0ul);
+ KUNIT_EXPECT_EQ(test, goal.last_psi_total, 3000ull);
+
+ /* temporal tuner uses the measured PSI delta */
+ damos_set_psi_current_val(3250, &goal, &s);
+ KUNIT_EXPECT_EQ(test, goal.current_value, 250ul);
+ KUNIT_EXPECT_EQ(test, goal.last_psi_total, 3250ull);
+}
+
static void damos_test_commit_quota_goals_for(struct kunit *test,
struct damos_quota_goal *dst_goals, int nr_dst_goals,
struct damos_quota_goal *src_goals, int nr_src_goals)
@@ -1947,6 +1989,7 @@ static struct kunit_case damon_test_cases[] = {
KUNIT_CASE(damon_test_nr_accesses_mvsum),
KUNIT_CASE(damos_test_new_filter),
KUNIT_CASE(damos_test_commit_quota_goal),
+ KUNIT_CASE(damos_test_set_psi_current_val),
KUNIT_CASE(damos_test_commit_quota_goals),
KUNIT_CASE(damos_test_commit_quota),
KUNIT_CASE(damos_test_commit_dests),
--
2.53.0
next prev parent reply other threads:[~2026-09-21 2:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 2:00 [PATCH v2 0/2] mm/damon: preserve temporal quota state for unmeasured PSI goals Karl Mehltretter
2026-09-21 2:00 ` [PATCH v2 1/2] mm/damon/core: keep the temporal tuner quota over an unmeasured PSI round Karl Mehltretter
2026-09-21 16:36 ` SJ Park
2026-09-21 2:00 ` Karl Mehltretter [this message]
2026-09-21 16:40 ` [PATCH v2 2/2] mm/damon/tests/core-kunit: test PSI goal values with explicit samples SJ Park
2026-09-21 16:47 ` [PATCH v2 0/2] mm/damon: preserve temporal quota state for unmeasured PSI goals SJ Park
2026-09-21 18:39 ` Karl Mehltretter
2026-09-22 6:28 ` SJ Park
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=20260921020013.33105-3-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=kunwu.chan@gmail.com \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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
all inboxes | Powered by JetHome®