Re: [RFC PATCH -next 16/16] mm/damon/core: handle quota->esz overflow issues
From: SeongJae Park
Date: Wed Aug 13 2025 - 13:20:29 EST
On Wed, 13 Aug 2025 13:07:06 +0800 Quanmin Yan <yanquanmin1@xxxxxxxxxx> wrote:
> In the original quota enforcement implementation, the traffic
> calculation multiplied A by 1000000 due to time unit conversion,
> making it highly prone to overflow on 32-bit systems:
>
> damos_set_effective_quota
> if (quota->total_charged_ns)
> throughput = quota->total_charged_sz * 1000000 /
> quota->total_charged_ns;
>
> Requiring total_charged_sz to be less than 4GB/1000000 is unreasonable.
> Additionally, when overflow occurs and causes quota->esz to become
> extremely small, the subsequent damos_apply_scheme logic permanently
> sets sz to 0, while quota stop updating, ultimately leading to complete
> functional failure:
>
> damos_apply_scheme
> if (quota->esz && quota->charged_sz + sz > quota->esz)
> sz = ALIGN_DOWN(quota->esz - quota->charged_sz, DAMON_MIN_REGION);
>
> Total charged stats use the unsigned long long data type to reduce
> overflow risk, with data reset capability after overflow occurs.
Thank you for finding this issue! I don't want to change the data type if
possible, though. Could replacing the easily-overflowing throughput
calculation with mult_frac() fix the issue?
Thanks,
SJ
[...]