All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.2 12/17] mm/damon/core: remove nr_accesses_bp setups and updates
Date: Sun, 21 Jun 2026 18:10:05 +0000	[thread overview]
Message-ID: <20260621181005.CBCD11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260621155715.87932-13-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] 32-bit integer overflow in mult_frac() calculation for left_window_bp.

Pre-existing issues:
- [High] Region merge operations do not size-weight average the last_nr_accesses field, leading to inaccurate pseudo moving sum calculations.
--

commit f4a10131988cee7930aeb4f2c1a3598bf65f3936
Author: SeongJae Park <sj@kernel.org>

mm/damon/core: remove nr_accesses_bp setups and updates
    
This patch removes the nr_accesses_bp field from struct damon_region and its
associated setups and updates. It states that the field is no longer used for
any real purpose and has been replaced by a simpler function.

The commit message mentions the field is replaced by a simpler function,
which is damon_nr_accesses_mvsum().

Looking at damon_nr_accesses_mvsum(), the fraction of the remaining
aggregation window is calculated like this:

mm/damon/core.c:damon_nr_accesses_mvsum() {
    ...
	left_window_bp = mult_frac(left_window, 10000, window_len);
    ...
}

[Severity: Medium]
Could this result in a 32-bit integer overflow?

The mult_frac(x, n, d) macro safely computes (x / d) * n + (x % d) * n / d.
Since left_window and window_len are of type unsigned long, on 32-bit
architectures the remainder 'r' and the multiplication 'r * 10000' are
evaluated as 32-bit unsigned integers.

Because userspace can configure an arbitrarily large aggr_interval relative
to sample_interval, window_len can exceed 429,496. If left_window %
window_len is large enough, r * 10000 will overflow 2^32 - 1.

Can this overflow result in an incorrect left_window_bp value, corrupting
the pseudo moving sum access frequency score and misleading DAMON's memory
management decisions on 32-bit systems?

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 94d8ec2965451..be41601163e29 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c

[ ... ]

> @@ -3103,7 +3099,6 @@ static void damon_merge_two_regions(struct damon_target *t,
>  
>  	l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) /
>  			(sz_l + sz_r);
> -	l->nr_accesses_bp = l->nr_accesses * 10000;

[Severity: High]
This is a pre-existing issue, but its impact is amplified to a regression by
this patchset. When damon_merge_two_regions() merges two adjacent regions,
it correctly calculates the size-weighted average for nr_accesses and age,
but fails to merge last_nr_accesses.

Prior to this series, the access score was represented by nr_accesses_bp,
which was correctly size-weighted during a merge. By replacing
nr_accesses_bp with damon_nr_accesses_mvsum(), DAMON now actively relies on
last_nr_accesses to compute the moving sum score.

Because last_nr_accesses is not size-weighted during a merge, merging a
large hot region with a small cold region will entirely wipe out the hot
region's access history.

Could this omission cause inaccurate moving sum scores, leading to incorrect
and suboptimal DAMOS targeting decisions?

>  	l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r);
>  	l->ar.end = r->ar.end;
>  	/* todo: do this for only installed probes */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260621155715.87932-1-sj@kernel.org?part=12

  reply	other threads:[~2026-06-21 18:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-21 15:56 [RFC PATCH v1.2 00/17] mm/damon: optimize out nr_accesses_bp SeongJae Park
2026-06-21 15:56 ` [RFC PATCH v1.2 01/17] mm/damon: introduce damon_nr_accesses_mvsum() SeongJae Park
2026-06-21 16:10   ` sashiko-bot
2026-06-21 20:01     ` SeongJae Park
2026-06-21 15:56 ` [RFC PATCH v1.2 02/17] mm/damon/tests/core-kunit: test damon_mvsum() SeongJae Park
2026-06-21 15:56 ` [RFC PATCH v1.2 03/17] mm/damon/core: always update ->last_nr_accesses for intervals change SeongJae Park
2026-06-21 16:11   ` sashiko-bot
2026-06-21 20:23     ` SeongJae Park
2026-06-21 21:13       ` SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 04/17] mm/damon/core: use damon_nr_accesses_mvsum() in __damos_valid_target() SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 05/17] mm/damon/core: use damon_nr_accesses_mvsum() for damos region tracing SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 06/17] mm/damon/sysfs-schemes: use damon_nr_accesses_mvsum() for damo regions SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 07/17] mm/damon/core: remove damon_warn_fix_nr_accesses_corruption() SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 08/17] mm/damon/core: remove damon_verify_reset_aggregated() SeongJae Park
2026-06-21 16:06   ` sashiko-bot
2026-06-21 20:24     ` SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 09/17] mm/damon/core: remove damon_verify_merge_regions_of() SeongJae Park
2026-06-21 18:09   ` sashiko-bot
2026-06-21 20:35     ` SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 10/17] mm/damon/tests/core-kunit: remove nr_accesses_bp setup and tests SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 11/17] selftests/damon/drgn_dump_damon_status: do not dump nr_accesses_bp SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 12/17] mm/damon/core: remove nr_accesses_bp setups and updates SeongJae Park
2026-06-21 18:10   ` sashiko-bot [this message]
2026-06-21 20:37     ` SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 13/17] mm/damon/core: remove attrs param from damon_update_region_access_rate() SeongJae Park
2026-06-21 16:14   ` sashiko-bot
2026-06-21 20:40     ` SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 14/17] mm/damonn/paddr: remove attrs param from __damon_pa_check_access() SeongJae Park
2026-06-21 16:07   ` sashiko-bot
2026-06-21 20:42     ` SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 15/17] mm/damon/vaddr: remove attrs param from __damon_va_check_access() SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 16/17] mm/damon/core: remove damon_moving_sum() and its unit test SeongJae Park
2026-06-21 15:57 ` [RFC PATCH v1.2 17/17] mm/damon: remove damon_region->nr_accesses_bp SeongJae 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=20260621181005.CBCD11F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 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.