Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: fix damos_walk() hang with zero watermarks interval
@ 2026-11-18 23:50 Yifan Feng
  2026-11-19  1:42 ` SJ Park
  0 siblings, 1 reply; 2+ messages in thread
From: Yifan Feng @ 2026-11-18 23:50 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.

Do not skip the deactivated schemes when deciding whether
kdamond_apply_schemes() has something to do.  damon_do_apply_schemes()
still skips them, so no action is applied, and the walk is completed
with no region for them, as it already is when another scheme is
activated.

Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
Cc: <stable@vger.kernel.org> # 6.14.x
Signed-off-by: Yifan Feng <evanfengff@gmail.com>
---
QEMU: the write hangs before, returns after; kunit and 13 selftests pass on both (2 need drgn, not run).
Found and written with the help of an AI coding assistant.

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

diff --git a/mm/damon/core.c b/mm/damon/core.c
index b8678a53b0a9..12578fc3280c 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3498,11 +3498,11 @@ static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c)
 		if (time_before(c->passed_sample_intervals, s->next_apply_sis))
 			continue;
 
+		has_schemes_to_apply = true;
+
 		if (!s->wmarks.activated)
 			continue;
 
-		has_schemes_to_apply = true;
-
 		damos_adjust_quota(c, s);
 	}
 

base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
-- 
2.39.3 (Apple Git-146)



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/damon/core: fix damos_walk() hang with zero watermarks interval
  2026-11-18 23:50 [PATCH] mm/damon/core: fix damos_walk() hang with zero watermarks interval Yifan Feng
@ 2026-11-19  1:42 ` SJ Park
  0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-11-19  1:42 UTC (permalink / raw)
  To: Yifan Feng; +Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel, stable

Hello Yifan,

On Wed, 18 Nov 2026 15:50:12 -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.

Thank you for finding and sharing the issue.

> 
> Do not skip the deactivated schemes when deciding whether
> kdamond_apply_schemes() has something to do.  damon_do_apply_schemes()
> still skips them, so no action is applied, and the walk is completed
> with no region for them, as it already is when another scheme is
> activated.
> 
> Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
> Cc: <stable@vger.kernel.org> # 6.14.x
> Signed-off-by: Yifan Feng <evanfengff@gmail.com>
> ---
> QEMU: the write hangs before, returns after; kunit and 13 selftests pass on both (2 need drgn, not run).
> Found and written with the help of an AI coding assistant.
> 
>  mm/damon/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index b8678a53b0a9..12578fc3280c 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -3498,11 +3498,11 @@ static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c)
>  		if (time_before(c->passed_sample_intervals, s->next_apply_sis))
>  			continue;
>  
> +		has_schemes_to_apply = true;
> +
>  		if (!s->wmarks.activated)
>  			continue;
>  
> -		has_schemes_to_apply = true;
> -
>  		damos_adjust_quota(c, s);
>  	}

But, this could make has_schemes_to_apply has false positive.  How about
calling damos_Walk_cancel() when has_schemes_to_apply is false, like below?

'''
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3849,8 +3849,10 @@ 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) {
+               damos_walk_cancel(c);
                return;
+       }

        max_region_sz = damon_region_sz_limit(c);
        mutex_lock(&c->walk_control_lock);
'''


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19  1:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 23:50 [PATCH] mm/damon/core: fix damos_walk() hang with zero watermarks interval Yifan Feng
2026-11-19  1:42 ` SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox