* [PATCH] mm/damon/stat: avoid 32-bit overflow in idle time milliseconds
@ 2026-11-17 9:43 David Carlier
2026-11-17 14:44 ` SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: David Carlier @ 2026-11-17 9:43 UTC (permalink / raw)
To: SJ Park, Andrew Morton
Cc: damon, linux-mm, linux-kernel, Aveline Noir, David Carlier, stable
On 32-bit, the region idle time in microseconds is computed in a long
before the division to milliseconds. It wraps once a region has been
idle for about 36 minutes regardless of the intervals, so the cold end
of memory_idle_ms_percentiles reports wrong values with flipped signs.
Do the multiplication in 64 bits and divide with div_s64() so the sign
of recently accessed regions is kept.
Fixes: e5d2585d9e85 ("mm/damon/stat: calculate and expose idle time percentiles")
Cc: stable@vger.kernel.org
Signed-off-by: David Carlier <devnexen@gmail.com>
---
Ref: https://lore.kernel.org/20261115173343.82437-1-sj@kernel.org
mm/damon/stat.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/damon/stat.c b/mm/damon/stat.c
index 6e05a2b067f2..f2387aee675d 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -130,8 +130,8 @@ static void damon_stat_set_idletime_percentiles(struct damon_ctx *c)
percentile = div64_ul((u64)accounted_bytes * 100, total_sz);
while (next_percentile <= percentile)
memory_idle_ms_percentiles[next_percentile++] =
- damon_stat_idletime(region) *
- (long)c->attrs.aggr_interval / USEC_PER_MSEC;
+ div_s64((s64)damon_stat_idletime(region) *
+ c->attrs.aggr_interval, USEC_PER_MSEC);
}
kfree(sorted_regions);
}
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/damon/stat: avoid 32-bit overflow in idle time milliseconds
2026-11-17 9:43 [PATCH] mm/damon/stat: avoid 32-bit overflow in idle time milliseconds David Carlier
@ 2026-11-17 14:44 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-11-17 14:44 UTC (permalink / raw)
To: David Carlier
Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel,
Aveline Noir, stable
Hello David,
On Tue, 17 Nov 2026 09:43:22 +0000 David Carlier <devnexen@gmail.com> wrote:
> On 32-bit, the region idle time in microseconds is computed in a long
> before the division to milliseconds. It wraps once a region has been
> idle for about 36 minutes regardless of the intervals, so the cold end
> of memory_idle_ms_percentiles reports wrong values with flipped signs.
>
> Do the multiplication in 64 bits and divide with div_s64() so the sign
> of recently accessed regions is kept.
Thank you for this patch. Looks good to me.
>
> Fixes: e5d2585d9e85 ("mm/damon/stat: calculate and expose idle time percentiles")
> Cc: stable@vger.kernel.org
> Signed-off-by: David Carlier <devnexen@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] 2+ messages in thread
end of thread, other threads:[~2026-11-17 14:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 9:43 [PATCH] mm/damon/stat: avoid 32-bit overflow in idle time milliseconds David Carlier
2026-11-17 14:44 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®