Skip to content

RFC mm/damon: fix overflows in score and ratio calculations

DaeMyung Kang damon linux-mm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3mm/damon/ops-common: avoid overflow in weighted hotness scoremm/damon/ops-common.c mm/damon/tests/ops-common-kunit.h+54 -30 replies
2/3mm/damon/core: avoid overflows in monitoring results calculationsmm/damon/core.c mm/damon/tests/core-kunit.h+109 -61 reply
3/3mm/damon/core: avoid overflows in quota goal metrics and scoresmm/damon/core.c mm/damon/tests/core-kunit.h+40 -90 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/3] mm/damon: fix overflows in score and ratio calculations

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/[email protected]
[2] https://lore.kernel.org/[email protected]
[3] https://lore.kernel.org/[email protected]
[4] https://lore.kernel.org/[email protected]
[5] https://lore.kernel.org/[email protected]

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

Signature · 1 line
2.43.0