Re: [PATCH] mm/damon/stat: avoid overflow in estimated_memory_bandwidth calculation
From: SJ Park
Date: Mon Nov 02 2026 - 09:40:44 EST
On Mon, 2 Nov 2026 18:04:23 +0800 Wang Guangke <gkwang@xxxxxxxxxxxxx> wrote:
> Hi SJ,
> Thanks for your review.
>
> On Sun, Nov 01, 2026 at 11:13:43AM -0800, SJ Park wrote:
> > Hello Wang,
> >
> > On Mon, 2 Nov 2026 02:00:01 +0800 Wang Guangke <gkwang@xxxxxxxxxxxxx> wrote:
> >
> > > The calculation of estimated_memory_bandwidth computes
> > > access_bytes * USEC_PER_MSEC * MSEC_PER_SEC / aggr_interval directly.
> > > On 32-bit systems, the intermediate product
> > > access_bytes * USEC_PER_MSEC * MSEC_PER_SEC may overflow before the
> > > division is performed.
> >
> > Do you find this issue from real usage? Or, jsut theoretical? Could you
> > please clarify it, and user impacts of the issue?
>
> I found it by code inspection, not from real usage on a 32-bit system.
Thank you for clarifying.
[...]
> > > + estimated_memory_bandwidth =
> > > + bytes_per_interval * USEC_PER_MSEC * MSEC_PER_SEC +
> > > + div64_u64(remainder * USEC_PER_MSEC * MSEC_PER_SEC,
> > > + c->attrs.aggr_interval);
> >
> > Let's use USEC_PER_SEC instead of 'USEC_PER_MSEC * MSEC_PER_SEC'.
>
> Thanks, I will rename the variable to bytes_per_us, and use USEC_PER_SEC
> instead of 'USEC_PER_MSEC * MSEC_PER_SEC'.
Thank you for accepting my humble suggestions. Looking forward to v2.
Thanks,
SJ
[...]