From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 1/2] mm/damon/core: split age==0 regions when nr_regions exceeds max/2
Date: Thu, 21 May 2026 05:22:07 +0000 [thread overview]
Message-ID: <20260521052207.F01821F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260521045236.115749-2-jiayuan.chen@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The `damon_split_zero_age_regions` function processes targets and regions sequentially, potentially starving later targets if the budget is exhausted early.
- [Medium] The calculation of `sz_sub` can overflow on 32-bit architectures for large regions, resulting in incorrect sub-region sizes or failing to split.
--
commit 8c8f86e64dc7143fb89435db427efa2adca6f33c
Author: Jiayuan Chen <jiayuan.chen@shopee.com>
mm/damon/core: split age==0 regions when nr_regions exceeds max/2
This commit modifies the region splitting logic to handle scenarios where
the region count exceeds half the maximum limit. Instead of returning early,
it now splits regions whose access pattern has just changed (age == 0) up
to the remaining budget, which helps discover internal access variations in
large regions.
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[ ... ]
> +static void damon_split_zero_age_regions(struct damon_ctx *ctx,
> + unsigned long budget)
> +{
> + struct damon_target *t;
> + struct damon_region *r, *next;
> +
> + damon_for_each_target(t, ctx) {
> + damon_for_each_region_safe(r, next, t) {
> + unsigned long sz_region, sz_sub;
> +
> + if (!budget)
> + return;
[Severity: Medium]
Will this sequential processing potentially starve later targets if the
budget is exhausted early?
Since budget is a context-wide limit shared across all targets, a highly
active first target with many zero-age regions could consume the entire
available split budget.
This might permanently prevent subsequent targets in the same context from
refining their monitoring resolution under dynamically changing access
patterns. Could a round-robin or proportionate distribution be used here
instead to ensure uniform monitoring fidelity?
> + if (r->age != 0)
> + continue;
> + sz_region = damon_sz_region(r);
> + if (sz_region < 2 * ctx->min_region_sz)
> + continue;
> +
> + sz_sub = ALIGN_DOWN(damon_rand(ctx, 1, 10) *
> + sz_region / 10, ctx->min_region_sz);
[Severity: Medium]
Can the calculation for sz_sub overflow on 32-bit architectures for large
regions?
Since unsigned long is 32 bits on those architectures, if sz_region is
large (e.g., > 477 MB), multiplying it by a random value up to 9 could
wrap around ULONG_MAX.
This overflow would result in drastically smaller sub-region sizes. If the
wrapped product divided by 10 is smaller than min_region_sz, ALIGN_DOWN
evaluates to 0. This would trigger the blank region check below and skip
the split entirely.
Should the division occur before the multiplication to prevent this?
> + /* Do not allow blank region */
> + if (sz_sub == 0 || sz_sub >= sz_region)
> + continue;
> +
> + damon_split_region_at(t, r, sz_sub);
> + budget--;
> + }
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260521045236.115749-1-jiayuan.chen@linux.dev?part=1
next prev parent reply other threads:[~2026-05-21 5:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 4:52 [PATCH 0/2] mm/damon/core: detect internal variation above max_nr_regions/2 Jiayuan Chen
2026-05-21 4:52 ` [PATCH 1/2] mm/damon/core: split age==0 regions when nr_regions exceeds max/2 Jiayuan Chen
2026-05-21 5:22 ` sashiko-bot [this message]
2026-05-21 6:34 ` Jiayuan Chen
2026-05-21 4:52 ` [PATCH 2/2] mm/damon/tests/core-kunit: test split above max_nr_regions/2 Jiayuan Chen
2026-05-21 5:41 ` sashiko-bot
2026-05-21 6:44 ` Jiayuan Chen
2026-05-21 14:30 ` [PATCH 0/2] mm/damon/core: detect internal variation " SeongJae Park
2026-05-21 15:07 ` Jiayuan Chen
2026-05-22 2:42 ` SeongJae Park
2026-05-22 15:11 ` Jiayuan Chen
2026-05-23 1:43 ` SeongJae Park
2026-05-25 8:09 ` Jiayuan Chen
2026-05-25 16:38 ` 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=20260521052207.F01821F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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.