mm/damon: fix misc bugs in kunit, quota goals and sysfs refresh_ms
Subsystems (4)
SJ Park
maintainercover mm/damon: fix misc bugs in kunit, quota goals and sysfs refresh_ms
DAMOS quota goals commit unit test is mistakenly not testing a test case that was designed to test. DAMOS quota goals and DAMON sysfs refresh_ms file have bugs that can produce non critical but still unexpected behaviors. Fix the bugs.
Patch 1 fixes the DAMOS quota goals commit unit test to cover a mistakenly uncovered case. Patches 2 and 3 fix the bugs in DAMOS PSI goal initialization and eligible_mem_bp online commit, respectively. Patch 4 fixes the bug in DAMON sysfs refresh_ms file handling.
Changes from RFC v1.3
- RFC v1.3: https://lore.kernel.org/[email protected]
- Drop RFC tag.
- Rebase to latest mm-new.
Changes from RFC v1.2
- RFC v1.2: https://lore.kernel.org/[email protected]
- Fix last_psi_total underflow.
Changes from RFC v1.1
- RFC v1.1: https://lore.kernel.org/[email protected]
- Fix quota goals commit unit test that was mistakenly missing a test case.
- Initialize last_psi_total as uninitialized at the beginning.
- Correct kunit test for changed last_psi_total initialization behavior. Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
(Mistakenly missed RFC tag)
- Fix build error.
- Add eligible_mem_bp nid commit fix.
SJ Park (4):
mm/damon/tests/core-kunit: test committing psi goal to psi goal mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit mm/damon/sysfs: set next refresh jiffies per sysfs context
mm/damon/core.c | 16 ++++++++++++++-- mm/damon/sysfs.c | 11 +++++------ mm/damon/tests/core-kunit.h | 16 ++++++++++------ 3 files changed, 29 insertions(+), 14 deletions(-)
base-commit: ee125db0b1f24a2f6b04e3143ffe1a14324176fe
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 1/4 mm/damon/tests/core-kunit: test committing psi goal to psi goal
damon_test_commit_quota_goal_for() is set to test committing a new psi goal on an existing psi goal. However, damon_test_commit_quota_goal() is mistakenly not covering the test case. Add the test case.
--- mm/damon/tests/core-kunit.h | 7 +++++++ 1 file changed, 7 insertions(+)
mm/damon/tests/core-kunit.h +7 -0
@@ -793,6 +793,13 @@ static void damos_test_commit_quota_goal(struct kunit *test) .last_psi_total = 456, }; +damos_test_commit_quota_goal_for (test, &dst, + &(struct damos_quota_goal ) { + .metric =DAMOS_QUOTA_SOME_MEM_PSI_US , + .target_value =234 , + .current_value =345 , + .last_psi_total =567 , + }); damos_test_commit_quota_goal_for(test, &dst, &(struct damos_quota_goal){ .metric = DAMOS_QUOTA_USER_INPUT,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 1/4] mm/damon/tests/core-kunit: test committing psi goal to psi goal
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
damon_test_commit_quota_goal_for()is set to test committing a new psi goal on an existing psi goal. However,damon_test_commit_quota_goal()is mistakenly not covering the test case. Add the test case.Fixes 99f89debafc5 ("mm/damon/tests/core-kunit: add damos_commit_quota_goal() test")Cc <[email protected]> # 6.19.xSigned-off-by SJ Park <[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 1/4] mm/damon/tests/core-kunit: test committing psi goal to psi goal
In reply to SJ ParkQuoted 32 lines · On Tue, 1 Sep 2026 17:27:20 -0700 SJ Park <[email protected]> wrote:
damon_test_commit_quota_goal_for()is set to test committing a new psi goal on an existing psi goal. However,damon_test_commit_quota_goal()is mistakenly not covering the test case. Add the test case.Fixes 99f89debafc5 ("mm/damon/tests/core-kunit: add damos_commit_quota_goal() test")Cc <[email protected]> # 6.19.xSigned-off-by SJ Park <[email protected]>--- mm/damon/tests/core-kunit.h | 7 +++++++ 1 file changed, 7 insertions(+)mm/damon/tests/core-kunit.h +7
-0@@ -793,6 +793,13 @@ static void damos_test_commit_quota_goal(struct kunit *test) .last_psi_total = 456, }; +damos_test_commit_quota_goal_for (test, &dst, + &(struct damos_quota_goal ) { + .metric =DAMOS_QUOTA_SOME_MEM_PSI_US , + .target_value =234 , + .current_value =345 , + .last_psi_total =567 , + }); damos_test_commit_quota_goal_for(test, &dst, &(struct damos_quota_goal){ .metric = DAMOS_QUOTA_USER_INPUT,Signature · 1 line
2.47.3
Thanks SJ. The added case correctly exercises the PSI -> PSI commit path before the existing tests change the destination metric.
Thanks,
Kunwu
Sent using hkml (https://github.com/sjp38/hackermail)
SJ Park
maintainerPATCH 2/4 mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
In reply to SJ ParkWhen DAMOS_QUOTA_SOME_MEM_PSI_US metric damos quota goal is set, the PSI delta for the feedback loop is calculated using damos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.
The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Check last_psi_total initialization and skip the tuning round when it is not initialized. For this, initialize last_psi_total with U64_MAX in the goal creation and the goal commit time. U64_MAX means the field is not initialized. The tuning round shows the value and adjusts it to guarantee the current quota is maintained for the round, and last_psi_total is correctly initialized on the next round.
Before this change, committing a new PSI goal on an existing PSI goal with goal-only DAMON sysfs command (commit_schemes_quota_goals) just worked. After this change, the tuning round right after the commit will be unnecessarily skipped, because last_psi_total is unconditionally marked as not initialized in the damos_commit_quota_goal_union(). This is an intended tradeoff for simplicity. Skipping just one round of tuning is no problem. Meanwhile it makes both the code and the behavior simple to understand.
Also update the quota goal commit unit test for changed last_psi_total setup behavior.
The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/[email protected]
--- mm/damon/core.c | 13 +++++++++++-- mm/damon/tests/core-kunit.h | 9 +++------ 2 files changed, 14 insertions(+), 8 deletions(-)
mm/damon/core.c +11 -2
@@ -636,6 +636,8 @@ struct damos_quota_goal *damos_new_quota_goal(return NULL ; goal->metric = metric; goal->target_value = target_value; +if (metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) + goal->last_psi_total =U64_MAX ;INIT_LIST_HEAD (&goal->list);return goal; }
@@ -1129,6 +1131,9 @@ static void damos_commit_quota_goal_union( struct damos_quota_goal *dst, struct damos_quota_goal *src) {switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : + dst->last_psi_total =U64_MAX ; +break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;
@@ -1150,7 +1155,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric ==DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }
@@ -3039,7 +3043,12 @@ 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 (); - goal->current_value = now_psi_total - goal->last_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;break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :
mm/damon/tests/core-kunit.h +3 -6
@@ -757,19 +757,16 @@ static void damos_test_commit_quota_goal_for(struct kunit *test,struct damos_quota_goal *dst, struct damos_quota_goal *src) { - u64 dst_last_psi_total = 0; - -if (dst->metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) - dst_last_psi_total = dst->last_psi_total;damos_commit_quota_goal (dst ,src );KUNIT_EXPECT_EQ (test, dst->metric, src->metric);KUNIT_EXPECT_EQ (test, dst->target_value, src->target_value);if (src->metric ==DAMOS_QUOTA_USER_INPUT )KUNIT_EXPECT_EQ (test, dst->current_value, src->current_value); -if (dst_last_psi_total && src->metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) -KUNIT_EXPECT_EQ (test, dst->last_psi_total, dst_last_psi_total);switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : +KUNIT_EXPECT_EQ (test, dst->last_psi_total,U64_MAX ); +break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP :KUNIT_EXPECT_EQ (test, dst->nid, src->nid);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/4] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
When
DAMOS_QUOTA_SOME_MEM_PSI_USmetric damos quota goal is set, the PSI delta for the feedback loop is calculated usingdamos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Quoted 6 lines
[ ... ]
[1] https://lore.kernel.org/[email protected]Fixes 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal")Cc <[email protected]> # 6.9.xSigned-off-by SJ Park <[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 2/4] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
In reply to SJ ParkQuoted 105 lines · On Tue, 1 Sep 2026 17:27:21 -0700 SJ Park <[email protected]> wrote:
When
DAMOS_QUOTA_SOME_MEM_PSI_USmetric damos quota goal is set, the PSI delta for the feedback loop is calculated usingdamos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Check
last_psi_totalinitialization and skip the tuning round when it is not initialized. For this, initializelast_psi_totalwithU64_MAXin the goal creation and the goal commit time.U64_MAXmeans the field is not initialized. The tuning round shows the value and adjusts it to guarantee the current quota is maintained for the round, andlast_psi_totalis correctly initialized on the next round.Before this change, committing a new PSI goal on an existing PSI goal with goal-only DAMON sysfs command (
commit_schemes_quota_goals) just worked. After this change, the tuning round right after the commit will be unnecessarily skipped, becauselast_psi_totalis unconditionally marked as not initialized in thedamos_commit_quota_goal_union(). This is an intended tradeoff for simplicity. Skipping just one round of tuning is no problem. Meanwhile it makes both the code and the behavior simple to understand.Also update the quota goal commit unit test for changed
last_psi_totalsetup behavior.The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/[email protected]
Fixes 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal")Cc <[email protected]> # 6.9.xSigned-off-by SJ Park <[email protected]>--- mm/damon/core.c | 13 +++++++++++-- mm/damon/tests/core-kunit.h | 9 +++------ 2 files changed, 14 insertions(+), 8 deletions(-)mm/damon/core.c +11
-2@@ -636,6 +636,8 @@ struct damos_quota_goal *damos_new_quota_goal(return NULL ; goal->metric = metric; goal->target_value = target_value; +if (metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) + goal->last_psi_total =U64_MAX ;INIT_LIST_HEAD (&goal->list);return goal; }@@ -1129,6 +1131,9 @@ static void damos_commit_quota_goal_union( struct damos_quota_goal *dst, struct damos_quota_goal *src) {switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : + dst->last_psi_total =U64_MAX ; +break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;@@ -1150,7 +1155,6 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric ==DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src); }@@ -3039,7 +3043,12 @@ 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 (); - goal->current_value = now_psi_total - goal->last_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;break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :mm/damon/tests/core-kunit.h +0
-4@@ -757,19 +757,16 @@ static void damos_test_commit_quota_goal_for(struct kunit *test,struct damos_quota_goal *dst, struct damos_quota_goal *src) { - u64 dst_last_psi_total = 0; - -if (dst->metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) - dst_last_psi_total = dst->last_psi_total;damos_commit_quota_goal (dst ,src );
mm/damon/tests/core-kunit.h static void damos_test_commit_quota_goal_for(struct kunit *test, · line 769
Quoted 10 lines
mm/damon/tests/core-kunit.h +3
-2KUNIT_EXPECT_EQ (test, dst->metric, src->metric);KUNIT_EXPECT_EQ (test, dst->target_value, src->target_value);if (src->metric ==DAMOS_QUOTA_USER_INPUT )KUNIT_EXPECT_EQ (test, dst->current_value, src->current_value); -if (dst_last_psi_total && src->metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) -KUNIT_EXPECT_EQ (test, dst->last_psi_total, dst_last_psi_total);switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : +KUNIT_EXPECT_EQ (test, dst->last_psi_total,U64_MAX ); +break ;
The U64_MAX sentinel approach looks correct to me.
In the first feedback iteration, setting current_value to target_value gives the PSI goal a score of 10000, so the uninitialized PSI delta does not affect the quota score. The current PSI total is then recorded, allowing subsequent iterations to calculate the delta normally.
I also checked the commit path: the PSI goal is reset to U64_MAX when committed, which intentionally skips one tuning round when replacing an existing PSI goal.
Thanks,
Kunwu
Quoted 6 lines
mm/damon/tests/core-kunit.h +0
-0case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP :KUNIT_EXPECT_EQ (test, dst->nid, src->nid);Signature · 1 line
2.47.3
Sent using hkml (https://github.com/sjp38/hackermail)
SJ Park
maintainerPATCH 3/4 mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
In reply to SJ Parkdamos_commit_quota_goal_union() is not updating the ->nid union field when the goal metric is DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness. Do the update.
The user impact is not catastrophic. No leak or crash happens. Doing the quota goal online commit that can reproduce the issue is expected to be not common. This issue was not found by real users but the AI review. That said, the issue can reliably be reproduced.
This issue was discovered [1] by Sashiko.
[1] https://lore.kkernel.org/[email protected]
--- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+)
mm/damon/core.c +3 -0
@@ -1143,6 +1143,9 @@ static void damos_commit_quota_goal_union( dst->nid = src->nid; dst->memcg_id = src->memcg_id;break ; +case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP : + dst->nid = src->nid; +break ;default :break ; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Inconsistent state handling in damon_commit_ctx() on memory allocation failure. --
commit c0fdc35d2fb6726e726ba0e857811cbaefc34918
Author: SJ Park <[email protected]>
mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
damos_commit_quota_goal_union() is not updating the ->nid union field when the goal metric is DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness.
Quoted 2 lines
damos_commit_quota_goal_union()is not updating the ->nid union field when the goal metric isDAMOS_QUITA_NODE_ELIGIBLE_MEM_BP.
This isn't a bug, but there's a typo (DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP) in the commit message.
Quoted 5 lines
mm/damon/core.c +0
-0
mm/damon/core.c static void damos_commit_quota_goal_union( · line 1151
Quoted 9 lines
mm/damon/core.c +3
-0@@ -1143,6 +1143,9 @@ static void damos_commit_quota_goal_union( dst->nid = src->nid; dst->memcg_id = src->memcg_id;break ; +case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP : + dst->nid = src->nid; +break ;default :break ; }
[Severity: High]
This isn't a bug introduced by this patch, but is a pre-existing logic flaw in the core DAMON commit mechanism on memory allocation failure.
In mm/damon/core.c:damon_commit_ctx():
err = __damon_commit_ctx(test_ctx, src); if (err) goto out; err = __damon_commit_ctx(dst, src);
If the second call to __damon_commit_ctx() fails with -ENOMEM, won't it leave the active dst context corrupted?
For example, an OOM condition can occur here in
mm/damon/core.c:damon_commit_schemes():
new_scheme = damon_new_scheme(&src_scheme->pattern, src_scheme->action, src_scheme->apply_interval_us, &src_scheme->quota, &src_scheme->wmarks, NUMA_NO_NODE); if (!new_scheme) return -ENOMEM;
A failure here exits the commit process without rolling back prior scheme updates, leaving the active dst context partially updated.
The kernel handles this by setting dst->maybe_corrupted = true, which forces the kdamond monitoring thread to terminate gracefully but permanently.
Could this be triggered by a user-initiated online parameter update encountering an OOM condition during the second __damon_commit_ctx() invocation?
Does this violate the atomic nature of damon_commit_ctx() (which uses test_ctx precisely to avoid partial updates on the active context) and cause an unintended loss of the running context?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
SJ Park
maintainerRe: [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
Quoted 18 lines · On Wed, 02 Sep 2026 00:39:50 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Inconsistent state handling indamon_commit_ctx()on memory allocation failure. --commit
c0fdc35d2fb6726e726ba0e857811cbaefc34918
Author: SJ Park <[email protected]>
mm/damon/core: copy nid foreligible_mem_bpdamos quota goal commit
damos_commit_quota_goal_union()is not updating the ->nid union field when the goal metric isDAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness.
Quoted 5 lines
Quoted 2 lines
damos_commit_quota_goal_union()is not updating the ->nid union field when the goal metric isDAMOS_QUITA_NODE_ELIGIBLE_MEM_BP.This isn't a bug, but there's a typo (
DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP) in the commit message.
Good catch. I will ask Andrew if he could fix this while picking this.
Quoted 47 lines
Quoted 6 lines
mm/damon/core.c +0
-0mm/damon/core.c static void damos_commit_quota_goal_union( · line 1151
Quoted 9 lines
mm/damon/core.c +3
-0@@ -1143,6 +1143,9 @@ static void damos_commit_quota_goal_union( dst->nid = src->nid; dst->memcg_id = src->memcg_id;break ; +case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP : + dst->nid = src->nid; +break ;default :break ; }[Severity: High]
This isn't a bug introduced by this patch, but is a pre-existing logic flaw in the core DAMON commit mechanism on memory allocation failure.In mm/damon/core.c:damon_commit_ctx():
err = __damon_commit_ctx(test_ctx, src); if (err) goto out; err = __damon_commit_ctx(dst, src);If the second call to
__damon_commit_ctx()fails with-ENOMEM, won't it leave the active dst context corrupted?For example, an OOM condition can occur here in
mm/damon/core.c:damon_commit_schemes():new_scheme = damon_new_scheme(&src_scheme->pattern, src_scheme->action, src_scheme->apply_interval_us, &src_scheme->quota, &src_scheme->wmarks, NUMA_NO_NODE); if (!new_scheme) return -ENOMEM;A failure here exits the commit process without rolling back prior scheme updates, leaving the active dst context partially updated.
The kernel handles this by setting
dst->maybe_corrupted= true, which forces the kdamond monitoring thread to terminate gracefully but permanently.
Quoted 7 lines
Could this be triggered by a user-initiated online parameter update encountering an OOM condition during the second
__damon_commit_ctx()invocation?Does this violate the atomic nature of
damon_commit_ctx()(which usestest_ctxprecisely to avoid partial updates on the active context) and cause an unintended loss of the running context?
Such user would need to have sysfs write permission first. With the permission, the user could do whatever, even worse than stopping DAMON.
So no issue in my opinion.
Quoted 3 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Thanks,
SJ
SJ Park
maintainerRe: [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
In reply to SJ ParkQuoted 2 lines · On Tue, 1 Sep 2026 17:27:22 -0700 SJ Park <[email protected]> wrote:
damos_commit_quota_goal_union()is not updating the ->nid union field when the goal metric isDAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a
Sashiko found the above typo. It needs 's/QUITA/QUOTA/'. Andrew, could you please do that when you pick this patch? Please feel free to let me know if you prefer repositing.
Thanks,
SJ
[...]
Re: [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
In reply to SJ ParkQuoted 7 lines · On Tue, 1 Sep 2026 17:27:22 -0700 SJ Park <[email protected]> wrote:
damos_commit_quota_goal_union()is not updating the ->nid union field when the goal metric isDAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness. Do the update.
Quoted 8 lines
The user impact is not catastrophic. No leak or crash happens. Doing the quota goal online commit that can reproduce the issue is expected to be not common. This issue was not found by real users but the AI review. That said, the issue can reliably be reproduced.
This issue was discovered [1] by Sashiko.
Hi SJ,
The fix is consistent with the other node-based quota metrics. I also checked that damos_get_node_eligible_mem_bp() directly uses goal->nid when calculating the current value.
One minor typo: the [1] has an extra k (kkernel should be kernel).
Thanks,
Kunwu
Quoted 25 lines
Fixes 9138e27a3bc3 ("mm/damon: add node_eligible_mem_bp goal metric")Cc <[email protected]> # 7.2.xSigned-off-by SJ Park <[email protected]>--- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+)mm/damon/core.c +3
-0@@ -1143,6 +1143,9 @@ static void damos_commit_quota_goal_union( dst->nid = src->nid; dst->memcg_id = src->memcg_id;break ; +case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP : + dst->nid = src->nid; +break ;default :break ; }Signature · 1 line
2.47.3
Sent using hkml (https://github.com/sjp38/hackermail)
SJ Park
maintainerRe: [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
Quoted 1 line · On Thu, 3 Sep 2026 16:45:45 +0800 Kunwu Chan <[email protected]> wrote:
On Tue, 1 Sep 2026 17:27:22 -0700 SJ Park <[email protected]> wrote:
[...]
Quoted 11 lines
Quoted 3 lines
This issue was discovered [1] by Sashiko.
Hi SJ,
The fix is consistent with the other node-based quota metrics. I also checked that
damos_get_node_eligible_mem_bp()directly usesgoal->nidwhen calculating the current value.One minor typo: the [1] has an extra k (kkernel should be kernel).
Nice catch, thank you Kunwu! Andrew, could you please fix this when you pick this series up? Let me know if you prefer reposting the series with the fix.
Quoted 2 lines
Reviewed-by Kunwu Chan <[email protected]>
Appreciate all the reviews, Kunwu!
Thanks,
SJ
[...]
SJ Park
maintainerPATCH 4/4 mm/damon/sysfs: set next refresh jiffies per sysfs context
In reply to SJ ParkWhen 'refresh_ms' is set, DAMON sysfs interface periodically updates auto-tuned parameters and DAMOS stats. The timestamp for the next refresh is initialized when a DAMON context starts, and updated in its damon_call() callback function. That is, each DAMON context updates it. However, the timestamp is a global variable that is shared with all the contexts. When there are multiple DAMON contexts having different refresh_ms, the update frequency will be changed, depending on the order of the contexts. When there are multiple kdamonds, it will be even more chaotic. Fix the problem by having the timestamp per each context.
The user impact is not very critical. It does not leak, corrupt or crash. The update will not be faster or slower than the lowest and largest refresh_ms values of the contexts, respectively. The user can also manually ask the updates on demand using kdamond state commands. That said, clearly this is a bug and can easily be reproduced.
--- mm/damon/sysfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
mm/damon/sysfs.c +5 -6
@@ -1788,6 +1788,7 @@ struct damon_sysfs_kdamond {struct damon_sysfs_contexts *contexts;struct damon_ctx *damon_ctx;unsigned int refresh_ms; +unsigned long next_refresh_jiffies; };static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc (void )
@@ -2213,17 +2214,15 @@ static struct damon_ctx *damon_sysfs_build_ctx(return ctx; } -static unsigned long damon_sysfs_next_update_jiffies; -static int damon_sysfs_repeat_call_fn (void *data) {struct damon_sysfs_kdamond *sysfs_kdamond = data;if (!sysfs_kdamond->refresh_ms)return 0 ; -if (time_before (jiffies, damon_sysfs_next_update_jiffies)) +if (time_before (jiffies, sysfs_kdamond->next_refresh_jiffies))return 0 ; - damon_sysfs_next_update_jiffies = jiffies + + sysfs_kdamond->next_refresh_jiffies = jiffies +msecs_to_jiffies (sysfs_kdamond->refresh_ms);if (!mutex_trylock (&damon_sysfs_lock))
@@ -2271,8 +2270,8 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond) } kdamond->damon_ctx = ctx; - damon_sysfs_next_update_jiffies = - jiffies +msecs_to_jiffies (kdamond->refresh_ms); + kdamond->next_refresh_jiffies = jiffies + +msecs_to_jiffies (kdamond->refresh_ms); repeat_call_control->fn = damon_sysfs_repeat_call_fn; repeat_call_control->data = kdamond;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 4/4] mm/damon/sysfs: set next refresh jiffies per sysfs context
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
When '
refresh_ms' is set, DAMON sysfs interface periodically updates auto-tuned parameters and DAMOS stats. The timestamp for the next refresh is initialized when a DAMON context starts, and updated in itsdamon_call()callback function. That is, each DAMON context updates it. However, the timestamp is a global variable that is shared with all the contexts. When there are multiple DAMON contexts having differentrefresh_ms, the update frequency will be changed, depending on the order of the contexts. When there are multiple kdamonds, it will be even more chaotic. Fix the problem by having the timestamp per each context.The user impact is not very critical. It does not leak, corrupt or crash. The update will not be faster or slower than the lowest and largest
refresh_msvalues of the contexts, respectively. The user can also manually ask the updates on demand using kdamond state commands. That said, clearly this is a bug and can easily be reproduced.
Quoted 3 lines
Fixes 9fd7bb5083d1 ("mm/damon/sysfs: change next_update_jiffies to a global variable")Cc <[email protected]> # 6.18.xSigned-off-by SJ Park <[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=4
Re: [PATCH 4/4] mm/damon/sysfs: set next refresh jiffies per sysfs context
In reply to SJ ParkQuoted 56 lines · On Tue, 1 Sep 2026 17:27:23 -0700 SJ Park <[email protected]> wrote:
When '
refresh_ms' is set, DAMON sysfs interface periodically updates auto-tuned parameters and DAMOS stats. The timestamp for the next refresh is initialized when a DAMON context starts, and updated in itsdamon_call()callback function. That is, each DAMON context updates it. However, the timestamp is a global variable that is shared with all the contexts. When there are multiple DAMON contexts having differentrefresh_ms, the update frequency will be changed, depending on the order of the contexts. When there are multiple kdamonds, it will be even more chaotic. Fix the problem by having the timestamp per each context.The user impact is not very critical. It does not leak, corrupt or crash. The update will not be faster or slower than the lowest and largest
refresh_msvalues of the contexts, respectively. The user can also manually ask the updates on demand using kdamond state commands. That said, clearly this is a bug and can easily be reproduced.Fixes 9fd7bb5083d1 ("mm/damon/sysfs: change next_update_jiffies to a global variable")Cc <[email protected]> # 6.18.xSigned-off-by SJ Park <[email protected]>--- mm/damon/sysfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)mm/damon/sysfs.c +3
-4@@ -1788,6 +1788,7 @@ struct damon_sysfs_kdamond {struct damon_sysfs_contexts *contexts;struct damon_ctx *damon_ctx;unsigned int refresh_ms; +unsigned long next_refresh_jiffies; };static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc (void )@@ -2213,17 +2214,15 @@ static struct damon_ctx *damon_sysfs_build_ctx(return ctx; } -static unsigned long damon_sysfs_next_update_jiffies; -static int damon_sysfs_repeat_call_fn (void *data) {struct damon_sysfs_kdamond *sysfs_kdamond = data;if (!sysfs_kdamond->refresh_ms)return 0 ; -if (time_before (jiffies, damon_sysfs_next_update_jiffies)) +if (time_before (jiffies, sysfs_kdamond->next_refresh_jiffies))return 0 ; - damon_sysfs_next_update_jiffies = jiffies + + sysfs_kdamond->next_refresh_jiffies = jiffies +msecs_to_jiffies (sysfs_kdamond->refresh_ms);if (!mutex_trylock (&damon_sysfs_lock))
mm/damon/sysfs.c static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond) · line 2274
Quoted 7 lines
mm/damon/sysfs.c +2
-2@@ -2271,8 +2270,8 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond) } kdamond->damon_ctx = ctx; - damon_sysfs_next_update_jiffies = - jiffies +msecs_to_jiffies (kdamond->refresh_ms); + kdamond->next_refresh_jiffies = jiffies + +msecs_to_jiffies (kdamond->refresh_ms);
The fix looks correct to me.
Moving next_refresh_jiffies into struct damon_sysfs_kdamond gives each kdamond ownership of its refresh schedule, so refresh activity from one kdamond can no longer interfere with another.
I also checked the initialization path: the new field is zero-initialized by kzalloc_obj(), and damon_sysfs_turn_damon_on() sets it to jiffies + refresh_ms before registering the callback via damon_call().
Thanks,
Kunwu
Quoted 6 lines
mm/damon/sysfs.c +0
-0repeat_call_control->fn = damon_sysfs_repeat_call_fn; repeat_call_control->data = kdamond;Signature · 1 line
2.47.3
Sent using hkml (https://github.com/sjp38/hackermail)
SJ Park
maintainerQuoted 4 lines · On Tue, 1 Sep 2026 17:27:19 -0700 SJ Park <[email protected]> wrote:
DAMOS quota goals commit unit test is mistakenly not testing a test case that was designed to test. DAMOS quota goals and DAMON sysfs
refresh_msfile have bugs that can produce non critical but still unexpected behaviors. Fix the bugs.
Sashiko found no blocker for this series. Sashiko sent findings to damon@ mailing list [1], and I replied to all the comments. Please read those for details.
Sashiko found a typo in the commit message of patch 3, though. It should 's/QUITA/QUOTA/'. I asked Andrew if he could fix it from his side.
[1] https://lore.kernel.org/damon/
Thanks,
SJ
Hi SJ,
Quoted 4 lines
Patch 1 fixes the DAMOS quota goals commit unit test to cover a mistakenly uncovered case. Patches 2 and 3 fix the bugs in DAMOS PSI goal initialization and
eligible_mem_bponline commit, respectively. Patch 4 fixes the bug in DAMON sysfsrefresh_msfile handling.
I reviewed and tested the integrated four-patch series in mm-new:
a20e38846efb..72dc8fdaae62
The integrated commits had stable patch-ids matching the posted patches. DAMON KUnit passed 42/42 tests. I also ran test-only eligible_mem_bp nid and two-kdamond refresh-isolation regression cases; they passed 42/42 and 43/43 tests, respectively. Both test-only changes were then removed and the worktree returned clean at the unchanged series tip.
These were functional UML KUnit tests. The fixes look good to me.
For the series:
Thanks,
Lian
SJ Park
maintainerQuoted 17 lines · On Thu, 3 Sep 2026 11:13:28 +0800 Lian Wang <[email protected]> wrote:
Hi SJ,
Quoted 4 lines
Patch 1 fixes the DAMOS quota goals commit unit test to cover a mistakenly uncovered case. Patches 2 and 3 fix the bugs in DAMOS PSI goal initialization and
eligible_mem_bponline commit, respectively. Patch 4 fixes the bug in DAMON sysfsrefresh_msfile handling.I reviewed and tested the integrated four-patch series in mm-new:
a20e38846efb..72dc8fdaae62The integrated commits had stable patch-ids matching the posted patches. DAMON KUnit passed 42/42 tests. I also ran test-only
eligible_mem_bpnid and two-kdamond refresh-isolation regression cases; they passed 42/42 and 43/43 tests, respectively. Both test-only changes were then removed and the worktree returned clean at the unchanged series tip.
Quoted 6 lines
These were functional UML KUnit tests. The fixes look good to me.
For the series:
Reviewed-by Lian Wang <[email protected]>Tested-by Lian Wang <[email protected]>
Thank you for your review and test, Lian!
Thanks,
SJ
[...]