Re: [PATCH] mm/damon/core: fix damos_walk() hang with zero watermarks interval

From: SJ Park

Date: Thu Nov 19 2026 - 19:49:45 EST


On Thu, 19 Nov 2026 16:13:00 -0800 Yifan Feng <evanfengff@xxxxxxxxx> wrote:

> On Wed, 18 Nov 2026 17:42:46 -0800 SJ Park <sj@xxxxxxxxxx> wrote:
>
> [...]
> > 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?
>
> Thanks for the review. You are right about the false positive.
>
> I tried your change. It fixes the hang, but has_schemes_to_apply is also
> false whenever no scheme has reached its next_apply_sis yet, so it cancels
> the walks of activated schemes too. In my test (one stat scheme, default
> intervals) 18 of 20 update_schemes_tried_regions writes got -ECANCELED,
> and two selftests fail: sysfs_update_schemes_tried_regions_wss_estimation.py
> and sysfs_update_schemes_tried_regions_hang.py.

You're right. Thanks for further testing and sharing the results.

>
> What do you think about cancelling only when no scheme is activated?
>
> '''
> --- 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);
> '''

Looks good to me.

>
> With this the hang is gone, 20 of 20 writes succeed while the scheme is
> activated, and kunit and selftests results are the same as on the base
> kernel.
>
> I will send v2 with this if you are ok with it.

Yes, I'm ok with it. Please wait ~1 day before posting the v2, so that others
can also add comments if they have.


Thanks,
SJ

[...]