mm/damon: preserve temporal quota state for unmeasured PSI goals
Subsystems (2)
v2 cover mm/damon: preserve temporal quota state for unmeasured PSI goals
A PSI quota goal without a previous sample is scored as achieved. This leaves the consist tuner's input unchanged but sets the temporal quota to zero. Preserve the temporal tuner's previous goal-achievement state using its effective quota, as SJ suggested [1], and test the helper with explicit PSI totals.
All 42 DAMON KUnit tests pass on x86-64 and i386. With the original scoring retained in the extracted helper, the new test fails on both. In a live damo test, a goals-only update changes a running 64 KiB quota to zero for an unmeasured round without the fix. With the fix, the effective quota stays at 64 KiB. A full damo tune also needs the separate quota-reset fix [3], so the context update preserves the running quota used for this decision.
DAMON selftests show no new failures (QEMU TCG guest; the wss_estimation test misses its accuracy bounds with and without the fix).
Changes since v1 [2]:
- Use the previous effective quota for the temporal decision, including when it is zero. Keep resetting last_psi_total for new and updated goals.
- Move the current-value calculation and last_psi_total update into a helper. Test both tuners with explicit samples and check last_psi_total after each call.
The series is based on mm-new as of September 20.
[1] https://lore.kernel.org/damon/[email protected]/
[2] https://lore.kernel.org/[email protected]/
[3] https://lore.kernel.org/[email protected]/
Karl Mehltretter (2):
mm/damon/core: keep the temporal tuner quota over an unmeasured PSI
round
mm/damon/tests/core-kunit: test PSI goal values with explicit samples
mm/damon/core.c | 30 ++++++++++++++++++++------ mm/damon/tests/core-kunit.h | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-)
base-commit: 185111f116aabf202d12ce440c0f6e9bae073514
Signature · 1 line
2.53.0
PATCH v2 1/2 mm/damon/core: keep the temporal tuner quota over an unmeasured PSI round
Commit b73198a47ffe ("mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total") scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.
Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.
Move the PSI current-value calculation and last_psi_total update into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.
---
The commit being fixed is still in mm-unstable, so its hash may change.
mm/damon/core.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
mm/damon/core.c +23 -7
@@ -2955,6 +2955,28 @@ static inline u64 damos_get_some_mem_psi_total(void)#endif /* CONFIG_PSI */ +static void damos_set_psi_current_val (u64 now_psi_total, +struct damos_quota_goal *goal,struct damos *s) +{ +u64 last_psi_total = goal->last_psi_total; + + goal->last_psi_total = now_psi_total; +if (last_psi_total !=U64_MAX ) { + goal->current_value = now_psi_total - last_psi_total; +return ; + } +/* uninitialized last_psi_total; make no effect this round */ +if (s->quota.goal_tuner ==DAMOS_QUOTA_GOAL_TUNER_CONSIST ) { + goal->current_value = goal->target_value; +return ; + } +/* let temporal tuner show the same achievement as in the last round */ +if (!s->quota.esz) + goal->current_value = goal->target_value; +else + goal->current_value =0 ; +} +#ifdef CONFIG_NUMA static bool invalid_mem_node (int nid) {
@@ -3207,13 +3229,7 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,break ;case DAMOS_QUOTA_SOME_MEM_PSI_US : now_psi_total =damos_get_some_mem_psi_total (); -/* uninitialized last_psi_total; make no effect this round */ -if (goal->last_psi_total ==U64_MAX ) - goal->current_value = goal->target_value; -else - goal->current_value = now_psi_total - - goal->last_psi_total; - goal->last_psi_total = now_psi_total; +damos_set_psi_current_val (now_psi_total, goal, s);break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP :
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 1/2] mm/damon/core: keep the temporal tuner quota over an unmeasured PSI round
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
Commit
b73198a47ffe("mm/damon/core: handle uninitializeddamos_quota_goal->last_psi_total") scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.
Move the PSI current-value calculation and
last_psi_totalupdate into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.
Quoted 6 lines
Fixes b73198a47ffe ("mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total")Cc <[email protected]> # 7.1.xSuggested-by SJ Park <[email protected]>Assisted-by LLMSigned-off-by Karl Mehltretter <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/2] mm/damon/core: keep the temporal tuner quota over an unmeasured PSI round
In reply to Karl MehltretterQuoted 13 lines · On Mon, 21 Sep 2026 04:00:12 +0200 Karl Mehltretter <[email protected]>…
Commit
b73198a47ffe("mm/damon/core: handle uninitializeddamos_quota_goal->last_psi_total") scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.
Quoted 4 lines
Move the PSI current-value calculation and
last_psi_totalupdate into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.
Looks good to me.
Quoted 3 lines
Fixes b73198a47ffe ("mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total")Cc <[email protected]> # 7.1.x
The broken commit (b73198a47ffe) is not in the mainline but mm-unstable. We should squash this to the broken commit before it is merged into the mainline. Or, maybe pointing the original broken fix (2dbb60f789cb) as 'Fixes:' is another option.
Do you have a preferrence?
Quoted 4 lines
Suggested-by SJ Park <[email protected]>Assisted-by LLMSigned-off-by Karl Mehltretter <[email protected]>
Other than the above,
Thanks,
SJ
[...]
PATCH v2 2/2 mm/damon/tests/core-kunit: test PSI goal values with explicit samples
In reply to Karl MehltretterTest 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.
--- mm/damon/tests/core-kunit.h | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
mm/damon/tests/core-kunit.h +43 -0
@@ -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),
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 2/2] mm/damon/tests/core-kunit: test PSI goal values with explicit samples
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
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_totalafter each call.With the old unmeasured-round behavior retained in the helper, the temporal check with a nonzero effective quota fails.
Assisted-by LLMSigned-off-by Karl Mehltretter <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/2] mm/damon/tests/core-kunit: test PSI goal values with explicit samples
In reply to Karl MehltretterQuoted 8 lines · On Mon, 21 Sep 2026 04:00:13 +0200 Karl Mehltretter <[email protected]>…
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_totalafter each call.With the old unmeasured-round behavior retained in the helper, the temporal check with a nonzero effective quota fails.
Thank you for contributing test!
Quoted 3 lines
Assisted-by LLMSigned-off-by Karl Mehltretter <[email protected]>
Thanks,
SJ
[...]
SJ Park
maintainerQuoted 25 lines · On Mon, 21 Sep 2026 04:00:11 +0200 Karl Mehltretter <[email protected]>…
A PSI quota goal without a previous sample is scored as achieved. This leaves the consist tuner's input unchanged but sets the temporal quota to zero. Preserve the temporal tuner's previous goal-achievement state using its effective quota, as SJ suggested [1], and test the helper with explicit PSI totals.
All 42 DAMON KUnit tests pass on x86-64 and i386. With the original scoring retained in the extracted helper, the new test fails on both. In a live damo test, a goals-only update changes a running 64 KiB quota to zero for an unmeasured round without the fix. With the fix, the effective quota stays at 64 KiB. A full damo tune also needs the separate quota-reset fix [3], so the context update preserves the running quota used for this decision.
DAMON selftests show no new failures (QEMU TCG guest; the
wss_estimationtest misses its accuracy bounds with and without the fix).Changes since v1 [2]:
- Use the previous effective quota for the temporal decision, including when it is zero. Keep resettinglast_psi_totalfor new and updated goals.
- Move the current-value calculation andlast_psi_totalupdate into a helper. Test both tuners with explicit samples and checklast_psi_totalafter each call.
Quoted 5 lines
The series is based on mm-new as of September 20.
[1] https://lore.kernel.org/damon/[email protected]/
[2] https://lore.kernel.org/[email protected]/
[3] https://lore.kernel.org/[email protected]/
The patch 1 has wrong Fixes: tag, as I replied to it with two options to path forward. Speculatively assuming your preferrence is option 2 (adding this series with fixed 'Fixes:' tag), I applied this series to damon/next [1] tree with the suggested Fixes: tag modification. Let me know if you want the options 1 (squash it into the incomplete fix [2] before it is merged into the mainline).
Unless you want option 1, and if this series is not added to mm.git in short term (~1 week?) with option 1 update, I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now unless you want option 1. If it seems I forgot doing that or you cannot wait for my action, please feel free to ping me or Andrew.
[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
[2] commit b73198a47ffe ("mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total")
Thanks,
SJ
[...]
Quoted 7 lines · SJ Park
The patch 1 has wrong Fixes: tag, as I replied to it with two options to path forward. Speculatively assuming your preferrence is option 2 (adding this series with fixed 'Fixes:' tag), I applied this series to damon/next [1] tree with the suggested Fixes: tag modification. Let me know if you want the options 1 (squash it into the incomplete fix [2] before it is merged into the mainline).
Quoted 6 lines
Unless you want option 1, and if this series is not added to mm.git in short term (~1 week?) with option 1 update, I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now unless you want option 1. If it seems I forgot doing that or you cannot wait for my action, please feel free to ping me or Andrew.
Hello SJ,
Thanks for reviewing both patches!
I used b73198a47ffe in Fixes because that commit introduced the problem with the temporal tuner.
I thought a Fixes tag could also point to a commit that is still in a maintainer tree. The tip handbook describes that for tip [1], though mm may handle it differently.
The hash can still change in mm-unstable, so the tag may need updating.
I also found this reply from Andrew [2]. He says he tracks these fixes by filename and folds them into the original patch before moving it to non-rebasing git.
Maybe squashing is indeed simpler here, also for backports.
So either option is fine with me. I'll leave that to you and Andrew.
[1] https://docs.kernel.org/process/maintainer-tip.html#ordering-of-commit-tags
[2] https://lore.kernel.org/r/[email protected]/
Thanks,
Karl
SJ Park
maintainerQuoted 17 lines · On Mon, 21 Sep 2026 20:39:27 +0200 Karl Mehltretter <[email protected]>…
Quoted 7 lines · SJ Park
The patch 1 has wrong Fixes: tag, as I replied to it with two options to path forward. Speculatively assuming your preferrence is option 2 (adding this series with fixed 'Fixes:' tag), I applied this series to damon/next [1] tree with the suggested Fixes: tag modification. Let me know if you want the options 1 (squash it into the incomplete fix [2] before it is merged into the mainline).
Quoted 6 lines
Unless you want option 1, and if this series is not added to mm.git in short term (~1 week?) with option 1 update, I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now unless you want option 1. If it seems I forgot doing that or you cannot wait for my action, please feel free to ping me or Andrew.
Hello SJ,
Quoted 8 lines
Thanks for reviewing both patches!
I used
b73198a47ffein Fixes because that commit introduced the problem with the temporal tuner.I thought a Fixes tag could also point to a commit that is still in a maintainer tree. The tip handbook describes that for tip [1], though mm may handle it differently.
You could do use a commit hash that is still in a maintainer tree. I also sometimes do so. But in the case it is better to explicitly mention it is for squashing on mm-unstable. And if it was the intention, in this patch series, you were better to split the kunit patch.
Quoted 10 lines
The hash can still change in mm-unstable, so the tag may need updating.
I also found this reply from Andrew [2]. He says he tracks these fixes by filename and folds them into the original patch before moving it to non-rebasing git.
Maybe squashing is indeed simpler here, also for backports.
So either option is fine with me. I'll leave that to you and Andrew.
Thank you for clarifying, Karl. I was initially tempted to keep what I did (option 2), but maybe that's only because I am too lazy. Let's do squash. Unless others raise other opinion, I will repost patch 1 with updated commit message tomorrow.
I will keep patch 2 in damon/next and repost for mm.git merge as I explained in the earlier reply.
Thanks,
SJ
[...]