From: SJ Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Carlier <devnexen@gmail.com>,
Aveline Noir <jm5905938@gmail.com>, SJ Park <sj@kernel.org>,
damon@lists.linux.dev, linux-mm@kvack.org,
stable@vger.kernel.org
Subject: [PATCH mm-hotfixes-unstable 1/3] mm/damon/stat: avoid 32-bit overflow in idle time milliseconds
Date: Mon, 23 Nov 2026 07:00:46 -0800 [thread overview]
Message-ID: <20261123150049.81317-2-sj@kernel.org> (raw)
In-Reply-To: <20261123150049.81317-1-sj@kernel.org>
From: David Carlier <devnexen@gmail.com>
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
Cc: Aveline Noir <jm5905938@gmail.com>
Signed-off-by: David Carlier <devnexen@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20261117094339.30978-1-devnexen@gmail.com
- Collect R-b: from SJ.
- Rebase to the latest mm-new.
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 e44f5bf3645cc..d90a43becaddf 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -129,8 +129,8 @@ static void damon_stat_set_idletime_percentiles(struct damon_ctx *c)
accounted_bytes += region->ar.end - region->ar.start;
while (next_percentile <= accounted_bytes * 100 / total_sz)
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.47.3
next prev parent reply other threads:[~2026-11-23 15:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:00 [PATCH mm-hotfixes-unstable 0/3] mm/damon: three fixes for idle_time overflow and damos_walk() hang SJ Park
2026-11-23 15:00 ` SJ Park [this message]
2026-11-23 15:00 ` [PATCH mm-hotfixes-unstable 2/3] mm/damon/core: fix damos_walk() hang with zero watermarks interval SJ Park
2026-11-23 15:00 ` [PATCH mm-hotfixes-unstable 3/3] mm/damon/core: do not overwrite wmarks.activated in damos_commit() SJ Park
2026-11-23 15:16 ` [PATCH mm-hotfixes-unstable 0/3] mm/damon: three fixes for idle_time overflow and damos_walk() hang sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123150049.81317-2-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=devnexen@gmail.com \
--cc=jm5905938@gmail.com \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox