Re: [RFC PATCH -next 16/16] mm/damon/core: handle quota->esz overflow issues

From: Quanmin Yan
Date: Wed Aug 20 2025 - 06:10:52 EST


Hi SJ,

在 2025/8/14 1:15, SeongJae Park 写道:
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?

Thank you for your guidance, it does work effectively. The relevant changes
have been included in patch #12 of the v2 series[1].

[1] https://lore.kernel.org/all/20250820080623.3799131-13-yanquanmin1@xxxxxxxxxx/

Thanks, Quanmin Yan