[PATCH mm-hotfixes-unstable 1/3] mm/damon/core: reset watermark wait state on each iteration

From: SJ Park

Date: Mon Nov 02 2026 - 11:07:42 EST


From: Aveline Noir <jm5905938@xxxxxxxxx>

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.

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.

Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update")
Cc: <stable@xxxxxxxxxxxxxxx> # 5.19.x
Assisted-by: LLM
Signed-off-by: Aveline Noir <jm5905938@xxxxxxxxx>
Reviewed-by: SJ Park <sj@xxxxxxxxxx>
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
Changes from v1
- v1: https://lore.kernel.org/179277129124.2.16132047926074873101.damon-empty-schemes@xxxxxxxxx
- Collect R-b: from SJ.
- Add how to work around the problem.
- Update Fixes: and add Cc: stable@.
- Rebase to latest mm-new.

mm/damon/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 73b571b429cb3..7441cdea57dc5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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) {
--
2.47.3