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.1 1/3] mm/damon: add damon_region->last_probe_hits
Date: Thu, 2 Jul 2026 13:37:58 -0700 [thread overview]
Message-ID: <20260702203805.92738-1-sj@kernel.org> (raw)
In-Reply-To: <20260702172906.403FC1F000E9@smtp.kernel.org>
On Thu, 02 Jul 2026 17:29:05 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] When `damon_update_monitoring_result()` is called to apply new attributes mid-aggregation, it resets `r->nr_accesses` but fails to clear `r->probe_hits`. As a result, accumulated probe hits leak across the aborted interval boundary. Furthermore, the newly introduced `r->last_probe_hits` field is completely ignored by this function—it is neither scaled for the new interval attributes (unlike `last_nr_accesses`) nor protected from the `probe_hits` leak. This causes the newly introduced moving sum statistics exposed to userspace to become artificially inflated and mathematically incorrect after an attribute update.
> --
>
> commit c9f161ddb2f122eeb9bddfba63cb77e65fe86f9c
> Author: SJ Park <sj@kernel.org>
>
> mm/damon: add damon_region->last_probe_hits
>
> Add new damon_region field, last_probe_hits. Maintain fully accumulated
> probe_hits values from the last aggregation interval in the field.
>
> > diff --git a/include/linux/damon.h b/include/linux/damon.h
> > index 805e089ff4f2f..4f7e305b261c3 100644
> > --- a/include/linux/damon.h
> > +++ b/include/linux/damon.h
> > @@ -68,10 +68,10 @@ struct damon_region {
> > unsigned int nr_accesses;
> > unsigned char probe_hits[DAMON_MAX_PROBES];
> > struct list_head list;
> > -
> > unsigned int age;
> > /* private: Internal value for age calculation. */
> > unsigned int last_nr_accesses;
> > + unsigned char last_probe_hits[DAMON_MAX_PROBES];
> > };
> >
> > /**
>
> [ ... ]
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index c6fc35be633b3..60be3e9d87887 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
>
> [ ... ]
>
> > @@ -2040,8 +2042,10 @@ static void kdamond_reset_aggregated(struct damon_ctx *c)
> > damon_nr_regions(t), nr_probes);
> > r->last_nr_accesses = r->nr_accesses;
> > r->nr_accesses = 0;
> > - for (i = 0; i < DAMON_MAX_PROBES; i++)
> > + for (i = 0; i < DAMON_MAX_PROBES; i++) {
> > + r->last_probe_hits[i] = r->probe_hits[i];
> > r->probe_hits[i] = 0;
> > + }
>
> [Severity: Medium]
> Is there a regression in how statistics are updated when attributes change
> mid-aggregation?
>
> If damon_update_monitoring_result() is called to apply new attributes, it
> resets nr_accesses but doesn't clear the probe_hits array:
>
> mm/damon/core.c:damon_update_monitoring_result() {
> ...
> if (!aggregating)
> r->nr_accesses = damon_nr_accesses_for_new_attrs(
> r->nr_accesses, old_attrs, new_attrs);
> else
> /*
> * if this is called in the middle of the aggregation, reset
> * the aggregations we made so far for this aggregation
> * interval. In other words, make the status like
> * kdamond_reset_aggregated() is called.
> */
> r->nr_accesses = 0;
> ...
> }
>
> This appears to completely ignore the newly introduced last_probe_hits array.
>
> Since last_nr_accesses is scaled for the new interval attributes, should
> last_probe_hits also be scaled to maintain accurate moving sum statistics?
>
> Also, should probe_hits be cleared for mid-aggregation updates to prevent
> leaking accumulated counts into the aborted interval?
This is indeed something that can better improved.
The function is not updating probe_hits, either, though. So no regression.
Not a blocker of this patch.
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-07-02 20:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 17:17 [RFC PATCH v1.1 0/3] mm/damon: provide pseudo moving sum probe_hits SJ Park
2026-07-02 17:17 ` [RFC PATCH v1.1 1/3] mm/damon: add damon_region->last_probe_hits SJ Park
2026-07-02 17:29 ` sashiko-bot
2026-07-02 20:37 ` SJ Park [this message]
2026-07-02 17:17 ` [RFC PATCH v1.1 2/3] mm/damon/core: introduce damon_probe_hits_mvsum() SJ Park
2026-07-02 17:17 ` [RFC PATCH v1.1 3/3] mm/damon/sysfs-schemes: set probe hits as pseudo moving sums SJ Park
2026-07-02 17:32 ` sashiko-bot
2026-07-02 20:43 ` 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=20260702203805.92738-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 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.