* [PATCH v2] mm/damon/core: fix damos_walk() hang with zero watermarks interval
@ 2026-11-21 2:56 Yifan Feng
2026-11-21 3:10 ` sashiko-bot
2026-11-21 17:29 ` SJ Park
0 siblings, 2 replies; 3+ messages in thread
From: Yifan Feng @ 2026-11-21 2:56 UTC (permalink / raw)
To: SJ Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel, Yifan Feng, stable
kdamond_wait_activation() cancels damos_walk() requests while all
schemes are deactivated by their watermarks. But it returns without
waiting when the watermarks check interval of a deactivated scheme is
zero, which is the default of the DAMON sysfs interface. The kdamond
main loop then runs with all schemes deactivated.
In that state, kdamond_apply_schemes() finds no scheme to apply and
returns before it calls damos_walk_complete(). The walk request is
neither completed nor cancelled, so damos_walk() waits until the
watermarks activate a scheme again, possibly forever.
For example, with a scheme that has the free_mem_rate metric, zero
interval_us and a high watermark below the current free memory rate,
writing update_schemes_tried_regions to the kdamond state file never
returns and cannot be killed. The writer holds damon_sysfs_lock, so all
other DAMON sysfs writes including "off" fail with -EBUSY meanwhile.
Cancel the walk request in kdamond_apply_schemes() when no scheme is
activated, as kdamond_wait_activation() does for a non-zero interval.
Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
Cc: <stable@vger.kernel.org> # 6.14.x
Suggested-by: SJ Park <sj@kernel.org>
Signed-off-by: Yifan Feng <evanfengff@gmail.com>
---
v2: cancel the walk when no scheme is activated, and leave has_schemes_to_apply as it is (SJ Park).
v1: https://lore.kernel.org/r/20261118235012.14859-1-evanfengff@gmail.com
QEMU: -ECANCELED instead of the hang, 20/20 walks of an activated scheme pass; kunit and 13 selftests pass (2 need drgn).
Found and written with the help of an AI coding assistant.
mm/damon/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index b8678a53b0a9..2748f9199924 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3492,9 +3492,13 @@ static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c)
struct damon_target *t;
struct damos *s;
bool has_schemes_to_apply = false;
+ bool has_activated_schemes = false;
unsigned long max_region_sz;
damon_for_each_scheme(s, c) {
+ if (s->wmarks.activated)
+ has_activated_schemes = true;
+
if (time_before(c->passed_sample_intervals, s->next_apply_sis))
continue;
@@ -3506,8 +3510,12 @@ static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c)
damos_adjust_quota(c, s);
}
- if (!has_schemes_to_apply)
+ if (!has_schemes_to_apply) {
+ /* The walk cannot be completed while no scheme is activated */
+ if (!has_activated_schemes)
+ damos_walk_cancel(c);
return;
+ }
max_region_sz = damon_region_sz_limit(c);
mutex_lock(&c->walk_control_lock);
base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] mm/damon/core: fix damos_walk() hang with zero watermarks interval
2026-11-21 2:56 [PATCH v2] mm/damon/core: fix damos_walk() hang with zero watermarks interval Yifan Feng
@ 2026-11-21 3:10 ` sashiko-bot
2026-11-21 17:29 ` SJ Park
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-21 3:10 UTC (permalink / raw)
To: Yifan Feng; +Cc: damon
> kdamond_wait_activation() cancels damos_walk() requests while all
> schemes are deactivated by their watermarks. But it returns without
> waiting when the watermarks check interval of a deactivated scheme is
> zero, which is the default of the DAMON sysfs interface. The kdamond
> main loop then runs with all schemes deactivated.
>
> In that state, kdamond_apply_schemes() finds no scheme to apply and
> returns before it calls damos_walk_complete(). The walk request is
> neither completed nor cancelled, so damos_walk() waits until the
> watermarks activate a scheme again, possibly forever.
>
> For example, with a scheme that has the free_mem_rate metric, zero
> interval_us and a high watermark below the current free memory rate,
> writing update_schemes_tried_regions to the kdamond state file never
> returns and cannot be killed. The writer holds damon_sysfs_lock, so all
> other DAMON sysfs writes including "off" fail with -EBUSY meanwhile.
>
> Cancel the walk request in kdamond_apply_schemes() when no scheme is
> activated, as kdamond_wait_activation() does for a non-zero interval.
>
> Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
> Cc: <stable@vger.kernel.org> # 6.14.x
> Suggested-by: SJ Park <sj@kernel.org>
> Signed-off-by: Yifan Feng <evanfengff@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121025626.75981-1-evanfengff@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] mm/damon/core: fix damos_walk() hang with zero watermarks interval
2026-11-21 2:56 [PATCH v2] mm/damon/core: fix damos_walk() hang with zero watermarks interval Yifan Feng
2026-11-21 3:10 ` sashiko-bot
@ 2026-11-21 17:29 ` SJ Park
1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-11-21 17:29 UTC (permalink / raw)
To: Yifan Feng; +Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel, stable
Hello Yifan,
On Fri, 20 Nov 2026 18:56:26 -0800 Yifan Feng <evanfengff@gmail.com> wrote:
> kdamond_wait_activation() cancels damos_walk() requests while all
> schemes are deactivated by their watermarks. But it returns without
> waiting when the watermarks check interval of a deactivated scheme is
> zero, which is the default of the DAMON sysfs interface. The kdamond
> main loop then runs with all schemes deactivated.
>
> In that state, kdamond_apply_schemes() finds no scheme to apply and
> returns before it calls damos_walk_complete(). The walk request is
> neither completed nor cancelled, so damos_walk() waits until the
> watermarks activate a scheme again, possibly forever.
>
> For example, with a scheme that has the free_mem_rate metric, zero
> interval_us and a high watermark below the current free memory rate,
> writing update_schemes_tried_regions to the kdamond state file never
> returns and cannot be killed. The writer holds damon_sysfs_lock, so all
> other DAMON sysfs writes including "off" fail with -EBUSY meanwhile.
>
> Cancel the walk request in kdamond_apply_schemes() when no scheme is
> activated, as kdamond_wait_activation() does for a non-zero interval.
Thank you for finding and fixing this issue.
>
> Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
> Cc: <stable@vger.kernel.org> # 6.14.x
> Suggested-by: SJ Park <sj@kernel.org>
> Signed-off-by: Yifan Feng <evanfengff@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
This patch is applied to damon/next [1] tree. I will repost it soon (~1 week)
as an mm.git merge request. So, no action from your side is needed for now.
[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 2:56 [PATCH v2] mm/damon/core: fix damos_walk() hang with zero watermarks interval Yifan Feng
2026-11-21 3:10 ` sashiko-bot
2026-11-21 17:29 ` SJ Park
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.