mm/damon/core: fix damos_walk() hang with zero watermarks interval
Subsystems (3)
PATCH 1/1 mm/damon/core: fix damos_walk() hang with zero watermarks interval
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.
---
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(-)
mm/damon/core.c +2 -2
@@ -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
Signature · 1 line
2.39.3 (Apple Git-146)
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 23 lines
kdamond_wait_activation()cancelsdamos_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 callsdamos_walk_complete(). The walk request is neither completed nor cancelled, sodamos_walk()waits until the watermarks activate a scheme again, possibly forever.For example, with a scheme that has the
free_mem_ratemetric, zerointerval_usand a high watermark below the current free memory rate, writingupdate_schemes_tried_regionsto the kdamond state file never returns and cannot be killed. The writer holdsdamon_sysfs_lock, so all other DAMON sysfs writes including "off" fail with-EBUSYmeanwhile.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.
Quoted 3 lines
Fixes bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")Cc <[email protected]> # 6.14.xSigned-off-by Yifan Feng <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerHello Yifan,
Quoted 11 lines · On Wed, 18 Nov 2026 15:50:12 -0800 Yifan Feng <[email protected]> wrote:
kdamond_wait_activation()cancelsdamos_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 callsdamos_walk_complete(). The walk request is neither completed nor cancelled, sodamos_walk()waits until the watermarks activate a scheme again, possibly forever.
Quoted 5 lines
For example, with a scheme that has the
free_mem_ratemetric, zerointerval_usand a high watermark below the current free memory rate, writingupdate_schemes_tried_regionsto the kdamond state file never returns and cannot be killed. The writer holdsdamon_sysfs_lock, so all other DAMON sysfs writes including "off" fail with-EBUSYmeanwhile.
Thank you for finding and sharing the issue.
Quoted 24 lines
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 <[email protected]> # 6.14.xSigned-off-by Yifan Feng <[email protected]>---
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(-)mm/damon/core.c +0
-0@@ -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 ;
mm/damon/core.c static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c) · line 3507
Quoted 10 lines
mm/damon/core.c +2
-2+ 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?
'''
mm/damon/core.c +3 -1
@@ -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
[...]
On Wed, 18 Nov 2026 17:42:46 -0800 SJ Park <[email protected]> wrote:
[...]
Quoted 2 lines
But, this could make
has_schemes_to_applyhas false positive. How about callingdamos_Walk_cancel()whenhas_schemes_to_applyis 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.
What do you think about cancelling only when no scheme is activated?
'''
mm/damon/core.c +9 -1
@@ -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);
'''
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.
Thanks,
Yifan
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] mm/damon: missing Signed-off-by trailer in commit message - [Low] mm/damon: commit message body is…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] mm/damon: missing Signed-off-by trailer in commit message
- [Low] mm/damon: commit message body is an unedited mailing-list reply
- [Low] mm/damon: missing Fixes trailer for damos_walk() commit bf0eaba0ff9c
--
commit 47dbaffa25c5043afa14731164c912784e9890e4
Author: Yifan Feng <[email protected]>
Quoted 17 lines
mm/damon/core: fixdamos_walk()hang with zero watermarks intervalOn Wed, 18 Nov 2026 17:42:46 -0800 SJ Park <[email protected]> wrote:
[...]
Quoted 2 lines
But, this could make
has_schemes_to_applyhas false positive. How about callingdamos_Walk_cancel()whenhas_schemes_to_applyis 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_applyis also false whenever no scheme has reached itsnext_apply_sisyet, so it cancels the walks of activated schemes too. In my test (one stat scheme, default intervals) 18 of 20update_schemes_tried_regionswrites got-ECANCELED, and two selftests fail:sysfs_update_schemes_tried_regions_wss_estimation.pyandsysfs_update_schemes_tried_regions_hang.py.
Quoted 3 lines
What do you think about cancelling only when no scheme is activated?
'''
[Severity: High]
The commit message is missing a Signed-off-by: trailer, which is required by Documentation/process/submitting-patches.rst to certify the Developer's Certificate of Origin.
[Severity: Low]
This isn't a code bug, but the commit description is an unedited mailing-list reply ending with trailing single quotes rather than a standalone changelog explaining why damos_walk() hangs with a zero watermarks interval and how tracking activated schemes in kdamond_apply_schemes() resolves it.
[Severity: Low]
This fixes the damos_walk() hang when all schemes are deactivated with a zero watermarks interval. Should the commit message include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerQuoted 6 lines · On Thu, 19 Nov 2026 16:13:00 -0800 Yifan Feng <[email protected]> wrote:
On Wed, 18 Nov 2026 17:42:46 -0800 SJ Park <[email protected]> wrote:
[...]
Quoted 2 lines
But, this could make
has_schemes_to_applyhas false positive. How about callingdamos_Walk_cancel()whenhas_schemes_to_applyis false, like below?
Quoted 8 lines
Thanks for the review. You are right about the false positive.
I tried your change. It fixes the hang, but
has_schemes_to_applyis also false whenever no scheme has reached itsnext_apply_sisyet, so it cancels the walks of activated schemes too. In my test (one stat scheme, default intervals) 18 of 20update_schemes_tried_regionswrites got-ECANCELED, and two selftests fail:sysfs_update_schemes_tried_regions_wss_estimation.pyandsysfs_update_schemes_tried_regions_hang.py.
You're right. Thanks for further testing and sharing the results.
Quoted 34 lines
What do you think about cancelling only when no scheme is activated?
'''
mm/damon/core.c +9
-1@@ -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);
Quoted 1 line
'''
Looks good to me.
Quoted 6 lines
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
[...]