Skip to content

Commit 9f68eab

Browse files
Quanmin Yanakpm00
authored andcommitted
mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota()
On 32-bit systems, the throughput calculation in damos_set_effective_quota() is prone to unnecessary multiplication overflow. Using mult_frac() to fix it. Andrew Paniakin also recently found and privately reported this issue, on 64 bit systems. This can also happen on 64-bit systems, once the charged size exceeds ~17 TiB. On systems running for long time in production, this issue can actually happen. More specifically, when a DAMOS scheme having the time quota run for longtime, throughput calculation can overflow and set esz too small. As a result, speed of the scheme get unexpectedly slow. Link: https://lkml.kernel.org/r/[email protected] Fixes: 1cd2430 ("mm/damon/schemes: implement time quota") Signed-off-by: Quanmin Yan <[email protected]> Reported-by: Andrew Paniakin <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: ze zuo <[email protected]> Cc: <[email protected]> [5.16+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 6310c14 commit 9f68eab

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mm/damon/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,8 @@ static void damos_set_effective_quota(struct damos_quota *quota)
20732073

20742074
if (quota->ms) {
20752075
if (quota->total_charged_ns)
2076-
throughput = quota->total_charged_sz * 1000000 /
2077-
quota->total_charged_ns;
2076+
throughput = mult_frac(quota->total_charged_sz, 1000000,
2077+
quota->total_charged_ns);
20782078
else
20792079
throughput = PAGE_SIZE * 1024;
20802080
esz = min(throughput * quota->ms, esz);

0 commit comments

Comments
 (0)