linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota()
@ 2025-08-21 12:55 Quanmin Yan
  2025-08-21 16:59 ` SeongJae Park
  0 siblings, 1 reply; 2+ messages in thread
From: Quanmin Yan @ 2025-08-21 12:55 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1, wangkefeng.wang,
	zuoze1, apanyaki

On 32-bit systems, the throughput calculation in function
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.

Fixes: 1cd243030059 ("mm/damon/schemes: implement time quota")
Cc: <stable@vger.kernel.org> # 5.16.x
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
Reported-by: Andrew Paniakin <apanyaki@amazon.com>
Closes: N/A # privately reported
---
 mm/damon/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 831a9afc6cf6..fe1c19307ddd 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2103,8 +2103,8 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 
 	if (quota->ms) {
 		if (quota->total_charged_ns)
-			throughput = quota->total_charged_sz * 1000000 /
-				quota->total_charged_ns;
+			throughput = mult_frac(quota->total_charged_sz, 1000000,
+							quota->total_charged_ns);
 		else
 			throughput = PAGE_SIZE * 1024;
 		esz = min(throughput * quota->ms, esz);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota()
  2025-08-21 12:55 [PATCH] mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota() Quanmin Yan
@ 2025-08-21 16:59 ` SeongJae Park
  0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2025-08-21 16:59 UTC (permalink / raw)
  To: Quanmin Yan
  Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
	wangkefeng.wang, zuoze1, apanyaki

On Thu, 21 Aug 2025 20:55:55 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> On 32-bit systems, the throughput calculation in function
> 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.
> 
> Fixes: 1cd243030059 ("mm/damon/schemes: implement time quota")
> Cc: <stable@vger.kernel.org> # 5.16.x
> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
> Reported-by: Andrew Paniakin <apanyaki@amazon.com>
> Closes: N/A # privately reported

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-21 16:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 12:55 [PATCH] mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota() Quanmin Yan
2025-08-21 16:59 ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).