[PATCH] mm/damon/stat: avoid 32-bit overflow in idle time milliseconds
From: David Carlier
Date: Tue Nov 17 2026 - 04:44:02 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: David Carlier <devnexen@xxxxxxxxx>
---
Ref: https://lore.kernel.org/20261115173343.82437-1-sj@xxxxxxxxxx
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