mm/damon/core: reset watermark wait state on each iteration
Subsystems (3)
PATCH 1/1 mm/damon/core: reset watermark wait state on each iteration
Found while reviewing the DAMON source code that if an online commit removes all schemes while kdamond is waiting for watermark activation, the scheme loop becomes empty but min_wait_time keeps the previous positive value. kdamond then keeps sleeping instead of resuming monitoring without schemes.
Initialize min_wait_time and init_wait_time on each loop iteration so the wait is calculated from the current schemes and an empty scheme list resumes monitoring.
---
An x86-64 KVM test using free-memory watermarks reproduced the stall with nr_schemes=0 followed by commit. The same test resumed monitoring with this fix. DAMON KUnit and selftests all passed.
mm/damon/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/core.c +3 -2
@@ -3976,10 +3976,11 @@ static int kdamond_wait_activation(struct damon_ctx *ctx) {struct damos *s;unsigned long wait_time; -unsigned long min_wait_time =0 ; -bool init_wait_time = false;while (!kdamond_need_stop (ctx)) { +unsigned long min_wait_time =0 ; +bool init_wait_time = false; +damon_for_each_scheme (s, ctx) { wait_time =damos_wmark_wait_us (s);if (!init_wait_time || wait_time < min_wait_time) {
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 6 lines
Found while reviewing the DAMON source code that if an online commit removes all schemes while kdamond is waiting for watermark activation, the scheme loop becomes empty but
min_wait_timekeeps the previous positive value. kdamond then keeps sleeping instead of resuming monitoring without schemes.
Quoted 7 lines
Initialize
min_wait_timeandinit_wait_timeon each loop iteration so the wait is calculated from the current schemes and an empty scheme list resumes monitoring.Fixes 6e74d2bf5a26 ("mm/damon/core: add a new callback for watermarks checks")Assisted-by LLMSigned-off-by Aveline Noir <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179277129124.2.16132047926074873101.damon-empty-schemes@gmail.com?part=1
Quoted 9 lines · On Sat, 24 Oct 2026 00:01:31 +0800 Aveline Noir <[email protected]> wrote:
Found while reviewing the DAMON source code that if an online commit removes all schemes while kdamond is waiting for watermark activation, the scheme loop becomes empty but
min_wait_timekeeps the previous positive value. kdamond then keeps sleeping instead of resuming monitoring without schemes.Initialize
min_wait_timeandinit_wait_timeon each loop iteration so the wait is calculated from the current schemes and an empty scheme list resumes monitoring.
Nice catch and fix, thank you Aveline!
Quoted 2 lines
Fixes 6e74d2bf5a26 ("mm/damon/core: add a new callback for watermarks checks")
But, this is a preparational patch for online commit support, right? Shouldn't the Fixes: be the commit that enabled online commit?
Also, this bug seems nasty to me. Users could work around the issue without restarting DAMON only by installing a scheme that has watermarks that activates DAMON again, and then removing the scheme again. I think it deserves to add this to commit message and Cc stable@.
Quoted 2 lines
Assisted-by LLMSigned-off-by Aveline Noir <[email protected]>
Quoted 4 lines
---
An x86-64 KVM test using free-memory watermarks reproduced the stall with nr_schemes=0 followed by commit. The same test resumed monitoring with this fix. DAMON KUnit and selftests all passed.
Thank you for keep adding this useful test results.
Assuming you agree to above suggestions, I applied this patch to damon/next [1] tree after applying my suggestions like below. We are in the middle of the merge window.
It may better to let mm.git maintainer (Andrew Morton) take time for pull request works, rather than adding more changes that are not really urgent. I understand this series is not really urgent. Hence, Andrew might not add this patch until next -rc1 release. In the case, I will request adding this to mm.git after the next -rc1 release. So, no action from your side is needed for now. Let me know if you find anything I missed, or disagree to the suggestions or the urgency judgement.
Changes to the patch file that I made:
'''
@@ -8,6 +8,10 @@ the scheme loop becomes empty but min_wait_time keeps the previous
positive value. kdamond then keeps sleeping instead of resuming monitoring without schemes.
+The way to wake up the kdamond again without DAMON is bit complicated.
+Install a scheme having watermarks that can activate the kdamond again,
+and remove the scheme again. Doable but cumbersome and complicated.
+
Initialize min_wait_time and init_wait_time on each loop iteration so
the wait is calculated from the current schemes and an empty scheme
list resumes monitoring.
@@ -15,11 +19,15 @@ list resumes monitoring.
/* TODO: move below to commentary */
Changes from v1
- v1: https://lore.kernel.org/179277129124.2.16132047926074873101.damon-empty-schemes@gmail.com
-- None.
+- Collect R-b: from SJ. +- Add how to work around the problem. +- Update Fixes: and add Cc: stable@.
-Fixes: 6e74d2bf5a26 ("mm/damon/core: add a new callback for watermarks checks") +Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update") +Cc: <[email protected]> # 5.19.x
+Reviewed-by: SJ Park <[email protected]>
'''
[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]