From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.2 08/19] mm/damon/core: extend merge function to work with probe hits
Date: Thu, 9 Jul 2026 07:56:11 -0700 [thread overview]
Message-ID: <20260709145612.96391-1-sj@kernel.org> (raw)
In-Reply-To: <20260709143216.39DF61F000E9@smtp.kernel.org>
On Thu, 09 Jul 2026 14:32:15 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Region `age` is incorrectly updated multiple times per aggregation interval and evaluated against a stale `last_score` when the `kdamond_merge_regions` retry loop is triggered.
> --
>
> --- Patch [8]: [RFC PATCH v1.2 08/19] mm/damon/core: extend merge function to work with probe hits ---
> commit 938ea22fc6c1fec3c909339503398aa70ea047c8
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: extend merge function to work with probe hits
>
> When probe weights are set, users may want DAMON monitoring results to
> be optimized for the weights. For that, regions adjustment should work
> for the weighted sum of probe hits. Extend damon_merge_regions_of() to
> detect if the weights are set, and work with probe hits in the case.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
>
> [ ... ]
>
> > @@ -3256,24 +3271,38 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres,
> > - unsigned long sz_limit)
> > + unsigned long sz_limit, struct damon_ctx *ctx)
> > {
> > struct damon_region *r, *prev = NULL, *next;
> > + bool use_probe_hits = damon_has_probe_weights(ctx);
> >
> > damon_for_each_region_safe(r, next, t) {
> > - if (abs_diff(r->nr_accesses, r->last_nr_accesses) > thres)
> > + unsigned int score, last_score, diff;
> > +
> > + score = damon_merge_score(r, false, ctx, use_probe_hits);
> > + last_score = damon_merge_score(r, true, ctx, use_probe_hits);
> > +
> > + if (abs_diff(score, last_score) > thres)
> > r->age = 0;
> > - else if ((r->nr_accesses == 0) != (r->last_nr_accesses == 0))
> > + else if ((score == 0) != (last_score == 0))
> > r->age = 0;
> > else
> > r->age++;
>
> [Severity: High]
> This is a pre-existing issue, but does this logic in damon_merge_regions_of()
> incorrectly increment or reset r->age multiple times per aggregation interval?
>
> When the number of regions exceeds max_nr_regions, kdamond_merge_regions()
> repeatedly calls damon_merge_regions_of() with doubled thresholds. During
> these retries, r->age is incremented multiple times within a single
> aggregation interval.
>
> Furthermore, because damon_merge_two_regions() updates the current
> nr_accesses and probe_hits but fails to merge their historical counterparts
> (last_nr_accesses and last_probe_hits), these values become stale.
>
> On subsequent iterations of the retry loop, damon_merge_score() computes
> last_score using these stale unmerged values. This can cause
> abs_diff(score, last_score) to spuriously exceed the threshold, resetting
> r->age to 0 inappropriately.
>
> Could this cause DAMOS age-based schemes to trigger prematurely or fail to
> trigger entirely?
I already promised to separately work on this.
>
> > - if (prev && prev->ar.end == r->ar.start &&
> > - abs_diff(prev->nr_accesses, r->nr_accesses) <= thres &&
> > - damon_sz_region(prev) + damon_sz_region(r) <= sz_limit)
> > - damon_merge_two_regions(t, prev, r);
> > - else
> > - prev = r;
> > + if (!prev)
> > + goto set_prev_continue;
> > + if (prev->ar.end != r->ar.start)
> > + goto set_prev_continue;
> > + diff = abs_diff(score, damon_merge_score(prev, false, ctx,
> > + use_probe_hits));
> > + if (diff > thres)
> > + goto set_prev_continue;
> > + if (damon_sz_region(prev) + damon_sz_region(r) > sz_limit)
> > + goto set_prev_continue;
> > + damon_merge_two_regions(t, prev, r);
> > + continue;
> > +set_prev_continue:
> > + prev = r;
> > }
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260709140600.90950-1-sj@kernel.org?part=8
Thanks,
SJ
next prev parent reply other threads:[~2026-07-09 14:56 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 14:05 [RFC PATCH v1.2 00/19] mm/damon: introduce data attributes only monitoring SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 01/19] mm/damon/core: introduce damon_probe->weight SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 02/19] mm/damon/core: ask apply_probes() ops callback to set sampling address SJ Park
2026-07-09 14:16 ` sashiko-bot
2026-07-09 14:47 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 03/19] mm/damon/paddr: set samples in apply_probes() if requested SJ Park
2026-07-09 14:21 ` sashiko-bot
2026-07-09 14:48 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 04/19] mm/damon/core: ask apply_probe() to return max probe hits weighted sum SJ Park
2026-07-09 14:16 ` sashiko-bot
2026-07-09 14:49 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 05/19] mm/damon/core: implement damon_probe_hits_wsum() SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 06/19] mm/damon/paddr: respect return_max_wsum SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 07/19] mm/damon/core: use abs_diff() instead of abs() SJ Park
2026-07-09 14:32 ` sashiko-bot
2026-07-09 14:54 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 08/19] mm/damon/core: extend merge function to work with probe hits SJ Park
2026-07-09 14:32 ` sashiko-bot
2026-07-09 14:56 ` SJ Park [this message]
2026-07-09 14:05 ` [RFC PATCH v1.2 09/19] mm/damon/core: disallow probe_hits overflow on attrs only monitoring SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 10/19] mm/damon/core: validate params for probe hits weighted sum overflow SJ Park
2026-07-09 14:36 ` sashiko-bot
2026-07-09 14:58 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 11/19] mm/damon/core: disable access monitoring when probe weights are set SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 12/19] mm/damon/core: set samples in apply_probes() if " SJ Park
2026-07-09 14:48 ` sashiko-bot
2026-07-09 15:00 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 13/19] mm/damon/core: s/max_nr_accesses/max_merge_score/ in kdamond_fn() SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 14/19] mm/damon/core: get merge threshold from probe hits when weights are set SJ Park
2026-07-09 14:49 ` sashiko-bot
2026-07-09 15:02 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 15/19] mm/damon/core: implement damon_has_probe_weight() SJ Park
2026-07-09 14:56 ` sashiko-bot
2026-07-09 15:03 ` SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 16/19] mm/damon/sysfs: implement probe/weight file SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 17/19] Docs/mm/damon/design: document attrs-only monitoring SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 18/19] Docs/admin-guide/mm/damon/usage: document weight sysfs file SJ Park
2026-07-09 14:05 ` [RFC PATCH v1.2 19/19] Docs/ABI/damon: document probe weight file 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=20260709145612.96391-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@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