Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: DaeMyung Kang <charsyam@gmail.com>
To: SJ Park <sj@kernel.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Asier Gutierrez <gutierrez.asier@huawei-partners.com>,
	DaeMyung Kang <charsyam@gmail.com>
Subject: [RFC PATCH 0/3] mm/damon: fix overflows in score and ratio calculations
Date: Tue, 27 Oct 2026 22:59:29 +0900	[thread overview]
Message-ID: <20261027135932.2301646-1-charsyam@gmail.com> (raw)

Sashiko reported several pre-existing overflows in DAMON score and
ratio calculations [1-5].  This series fixes them with wide
intermediates and an overflow-safe mult_frac() variant.

Patch 1 fixes the weighted hotness score, which overflows with large
user supplied quota weights on any architecture.  It accumulates the
weighted sum in u64, preserving scores for non-overflowing inputs.

Patch 2 adds damon_mult_frac().  It returns the same result as
mult_frac() when that does not overflow, computes the remainder product
in full width when needed, and saturates results that do not fit in
unsigned long.  It fixes the region age and sample ratio conversions
for new monitoring intervals, and the moving sums of access counts and
probe hits.  The helper is introduced with its first users so that each
commit builds without an unused function warning.

Patch 3 uses the helper for the page based memory ratio quota goal
metrics, including the hugepage metric, and for the quota goal score.
The node eligible memory metric counts bytes in phys_addr_t and uses
mul_u64_u64_div_u64() directly to avoid truncation on 32-bit PAE.

The remaining mult_frac() users, including the intervals auto-tuning
score that has an ongoing discussion, are not changed.

I am sending this as RFC to ask whether this approach is preferred for
these overflow issues.

The DAMON KUnit suites pass on UML, i386 QEMU, and x86_64 QEMU with
NUMA enabled (54 tests each).  The new regression cases fail on i386
without the fixes.

[1] https://lore.kernel.org/20260623141527.044D11F000E9@smtp.kernel.org
[2] https://lore.kernel.org/20260708140944.F26821F000E9@smtp.kernel.org
[3] https://lore.kernel.org/20260901133650.EF4F71F000E9@smtp.kernel.org
[4] https://lore.kernel.org/20260626002448.975E21F000E9@smtp.kernel.org
[5] https://lore.kernel.org/20260831184956.1DA321F000E9@smtp.kernel.org

DaeMyung Kang (3):
  mm/damon/ops-common: avoid overflow in weighted hotness score
  mm/damon/core: avoid overflows in monitoring results calculations
  mm/damon/core: avoid overflows in quota goal metrics and scores

 mm/damon/core.c                   |  59 ++++++++++++-----
 mm/damon/ops-common.c             |  10 ++-
 mm/damon/tests/core-kunit.h       | 105 ++++++++++++++++++++++++++++++
 mm/damon/tests/ops-common-kunit.h |  47 +++++++++++++
 4 files changed, 203 insertions(+), 18 deletions(-)
 create mode 100644 mm/damon/tests/ops-common-kunit.h


base-commit: bae9a042b03b27924c6fd5bdc00a20d6a44d6041
-- 
2.43.0



             reply	other threads:[~2026-10-27 13:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 13:59 DaeMyung Kang [this message]
2026-10-27 13:59 ` [RFC PATCH 1/3] mm/damon/ops-common: avoid overflow in weighted hotness score DaeMyung Kang
2026-10-27 13:59 ` [RFC PATCH 2/3] mm/damon/core: avoid overflows in monitoring results calculations DaeMyung Kang
2026-10-27 14:18   ` Gutierrez Asier
2026-10-27 13:59 ` [RFC PATCH 3/3] mm/damon/core: avoid overflows in quota goal metrics and scores DaeMyung Kang
2026-10-27 14:23 ` [RFC PATCH 0/3] mm/damon: fix overflows in score and ratio calculations SJ Park

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=20261027135932.2301646-1-charsyam@gmail.com \
    --to=charsyam@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=gutierrez.asier@huawei-partners.com \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox