* [PATCH] mm/damon/core: reject zero sample_interval
@ 2026-07-22 9:43 dayou5941
2026-07-22 14:01 ` SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: dayou5941 @ 2026-07-22 9:43 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, liyouhong
From: liyouhong <liyouhong@kylinos.cn>
damon_set_attrs() allows sample_interval == 0. Sysfs likewise accepts
sample_us=0. kdamond_fn() then calls kdamond_usleep(0) every loop
iteration, so kdamond busy-spins and can peg a CPU.
With a zero sampling interval the access-rate accounting also diverges:
nr_accesses_bp no longer matches nr_accesses * 10000, and
kdamond_reset_aggregated() hits:
WARNING: invalid nr_accesses_bp at reset: ...
Reject sample_interval == 0 in damon_set_attrs(), which covers sysfs
commit and other callers. damon_lru_sort already refused a zero
sample_interval; align the core validation with that.
Reproduce:
echo 0 > .../intervals/sample_us
echo on > .../kdamonds/0/state
# kdamond ~100% CPU; may WARN in kdamond_reset_aggregated()
Fixes: 4472edf63d66 ("mm/damon/core: use number of passed access sampling as a timer")
Assisted-by: Cursor Grok 4.5
Signed-off-by: liyouhong <liyouhong@kylinos.cn>
---
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 7e4b9affc5b0..a6d54ec8c4be 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -911,6 +911,8 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
return -EINVAL;
if (attrs->min_nr_regions > attrs->max_nr_regions)
return -EINVAL;
+ if (!attrs->sample_interval)
+ return -EINVAL;
if (attrs->sample_interval > attrs->aggr_interval)
return -EINVAL;
@@ -3770,8 +3772,9 @@ void damon_update_region_access_rate(struct damon_region *r, bool accessed,
unsigned int len_window = 1;
/*
- * sample_interval can be zero, but cannot be larger than
- * aggr_interval, owing to validation of damon_set_attrs().
+ * sample_interval cannot be zero or larger than aggr_interval,
+ * owing to validation of damon_set_attrs(). Keep the zero check
+ * below as defense in depth.
*/
if (attrs->sample_interval)
len_window = damon_max_nr_accesses(attrs);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/damon/core: reject zero sample_interval
2026-07-22 9:43 [PATCH] mm/damon/core: reject zero sample_interval dayou5941
@ 2026-07-22 14:01 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-07-22 14:01 UTC (permalink / raw)
To: dayou5941; +Cc: SJ Park, akpm, damon, liyouhong
Hello liyouhong,
Thank you for sharing this patch!
On Wed, 22 Jul 2026 17:43:04 +0800 dayou5941@163.com wrote:
> From: liyouhong <liyouhong@kylinos.cn>
>
> damon_set_attrs() allows sample_interval == 0. Sysfs likewise accepts
> sample_us=0. kdamond_fn() then calls kdamond_usleep(0) every loop
> iteration, so kdamond busy-spins and can peg a CPU.
>
> With a zero sampling interval the access-rate accounting also diverges:
> nr_accesses_bp no longer matches nr_accesses * 10000, and
> kdamond_reset_aggregated() hits:
>
> WARNING: invalid nr_accesses_bp at reset: ...
The warning has removed by nr_accesses_bp optimization patch series, which is
currently queued for 7.3-rc1. So the warning will not be triggered on near
future mainline.
>
> Reject sample_interval == 0 in damon_set_attrs(), which covers sysfs
> commit and other callers. damon_lru_sort already refused a zero
> sample_interval; align the core validation with that.
This is a sort of behavioral change. I also feel this adds another corner case
that makes my head complicated. There are a few logic written under the
assumption of zero intervals. Having inconsistencies between allowed input and
handling logic will make it difficult to maintain in long term. Can't we keep
supporting zero sample interval and fix the warning or the real bug instead?
[1] https://lore.kernel.org/20260630040812.149729-1-sj@kernel.org
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-22 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 9:43 [PATCH] mm/damon/core: reject zero sample_interval dayou5941
2026-07-22 14:01 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox