All of lore.kernel.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: Quanmin Yan <yanquanmin1@huawei.com>
Cc: SeongJae Park <sj@kernel.org>,
	akpm@linux-foundation.org, damon@lists.linux.dev,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	wangkefeng.wang@huawei.com, zuoze1@huawei.com,
	Andrew Paniakin <apanyaki@amazon.com>
Subject: Re: [RFC PATCH mm-next v2 12/12] mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota()
Date: Wed, 20 Aug 2025 15:16:33 -0700	[thread overview]
Message-ID: <20250820221633.87243-1-sj@kernel.org> (raw)
In-Reply-To: <20250820080623.3799131-13-yanquanmin1@huawei.com>

+ Andrew

On Wed, 20 Aug 2025 16:06:22 +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 runs for long
time, throughput calculation can overflow and set esz too small.  As a result,
speed of the scheme get unexpectedly slow.

Quanmin, could you please add the above paragraph on the commit message?  Also,
I think this fix deserves Cc: stable@ and has no reason to be a part of this
patch series.  Could you please add appripriate tags like below and post again
separately?

    Fixes: 1cd243030059 ("mm/damon/schemes: implement time quota")
    Reported-by: Andrew Paniakin <apanyaki@amazon.com>
    Closes: N/A # privately reported
    Cc: <stable@vger.kernel.org> # 5.16.x

> 
> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
> ---
>  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 980e271e42e9..38b5f842ef30 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2102,8 +2102,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


Thanks,
SJ

  reply	other threads:[~2025-08-20 22:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20  8:06 [RFC PATCH mm-next v2 00/12] mm/damon: support ARM32 with LPAE Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 01/12] mm/damon/core: add damon_ctx->addr_unit Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 02/12] mm/damon/paddr: support addr_unit for access monitoring Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 03/12] mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 04/12] mm/damon/paddr: support addr_unit for DAMOS_LRU_[DE]PRIO Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 05/12] mm/damon/paddr: support addr_unit for MIGRATE_{HOT,COLD} Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 06/12] mm/damon/paddr: support addr_unit for DAMOS_STAT Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 07/12] mm/damon/sysfs: implement addr_unit file under context dir Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 08/12] Docs/mm/damon/design: document 'address unit' parameter Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 09/12] Docs/admin-guide/mm/damon/usage: document addr_unit file Quanmin Yan
2025-08-20  8:06 ` [RFC PATCH mm-next v2 10/12] Docs/ABI/damon: " Quanmin Yan
2025-08-20 21:37   ` SeongJae Park
2025-08-20  8:06 ` [RFC PATCH mm-next v2 11/12] mm/damon: add damon_ctx->min_region Quanmin Yan
2025-08-20 21:56   ` SeongJae Park
2025-08-20  8:06 ` [RFC PATCH mm-next v2 12/12] mm/damon/core: prevent unnecessary overflow in damos_set_effective_quota() Quanmin Yan
2025-08-20 22:16   ` SeongJae Park [this message]
2025-08-20 22:23 ` [RFC PATCH mm-next v2 00/12] mm/damon: support ARM32 with LPAE SeongJae Park
2025-08-21 11:19   ` Quanmin Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250820221633.87243-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=apanyaki@amazon.com \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=yanquanmin1@huawei.com \
    --cc=zuoze1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.