Re: [PATCH v2] mm/damon/stat: avoid overflow in estimated_memory_bandwidth calculation

From: SJ Park

Date: Tue Nov 03 2026 - 09:41:51 EST


Hi Wang,

On Tue, 3 Nov 2026 11:40:34 +0800 Wang Guangke <gkwang@xxxxxxxxxxxxx> wrote:

> estimated_memory_bandwidth is calculated by access_bytes *
> USEC_PER_MSEC * MSEC_PER_SEC (= USEC_PER_SEC) / aggr_interval,
> and users read it via
> /sys/module/damon_stat/parameters/estimated_memory_bandwidth.
>
> On 32-bit systems, access_bytes * USEC_PER_SEC overflows unsigned
> long once access_bytes exceeds about 4294 (U32_MAX / USEC_PER_SEC),
> so users get a wrong value.
>
> Fix it by doing the calculation in 64-bit and splitting the division
> into quotient and remainder.
>
> The issue was reproduced on a 32-bit system (qemu-system-i386): the
> parameter estimated_memory_bandwidth reported 362 instead of the
> expected 1926150; with the fix, the value matches the expectation.

Looks good to me.

>
> Fixes: fabdd1e911da ("mm/damon/stat: calculate and expose estimated memory bandwidth")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Wang Guangke <gkwang@xxxxxxxxxxxxx>

Reviewed-by: SJ Park <sj@xxxxxxxxxx>

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

[...]