DAMON development mailing list
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 3/3] mm/damon/sysfs-schemes: set probe hits as pseudo moving sums
Date: Fri,  3 Jul 2026 10:42:27 -0700	[thread overview]
Message-ID: <20260703174228.98368-1-sj@kernel.org> (raw)
In-Reply-To: <20260703172651.7246F1F00A3A@smtp.kernel.org>

On Fri, 03 Jul 2026 17:26:50 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Missing left_window_bp == 10000 guard in damon_probe_hits_mvsum causes wrapped/doubled values at the aggregation interval boundary.

No blocker for this patch in my opinion.

> --
> 
> commit a039a69816e23f1f7d4a1680c2ab2713e7d81fe1
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/sysfs-schemes: set probe hits as pseudo moving sums
>     
> DAMON sysfs interface exposes damon_region->probe_hits via probe hit
> files.  Because the counters are completed only at the end of the
> aggregation interval, users can show incomplete values if they requested
> the file content update (update_schemes_tried_regions command) in the
> middle of an aggregation interval.  Set the value as the pseudo moving
> sum value of the counter, similar to that for nr_accesses.
> 
> > diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> > index dbf2b0515d582..32f495a96b17a 100644
> > --- a/mm/damon/sysfs-schemes.c
> > +++ b/mm/damon/sysfs-schemes.c
> > @@ -110,7 +110,8 @@ static int damos_sysfs_probes_add_dirs(struct damos_sysfs_probes *probes,
> >  		struct damos_sysfs_probe *sys_probe;
> >  		int err;
> >  
> > -		sys_probe = damos_sysfs_probe_alloc(region->probe_hits[i]);
> > +		sys_probe = damos_sysfs_probe_alloc(
> > +				damon_probe_hits_mvsum(i, region, ctx));
> 
> [Severity: Medium]
> Could this result in wrapped or doubled values at the aggregation interval
> boundary?
> 
> Looking at damon_probe_hits_mvsum() in mm/damon/core.c, it seems to calculate
> the moving sum without guarding against the boundary race condition, unlike
> damon_nr_accesses_mvsum():
> 
> mm/damon/core.c:damon_probe_hits_mvsum() {
>     ...
>     left_window_bp = mult_frac(left_window, 10000, window_len);
> 
>     return damon_mvsum(r->probe_hits[probe_idx],
>             r->last_probe_hits[probe_idx], left_window_bp);
> }
> 
> If damon_set_attrs() updates ctx->next_aggregation_sis (e.g., via a sysfs
> commit command) just before kdamond_apply_schemes() executes in the same loop
> iteration, left_window_bp could evaluate to 10000.
> 
> If a user concurrently queues an update_schemes_tried_regions walk exactly at
> this moment, the walk callback invokes damon_probe_hits_mvsum(). Because the
> guard `if (left_window_bp == 10000)` is missing, the function evaluates to
> probe_hits + last_probe_hits.
> 
> Since probe_hits retains its un-cleared values from before the attribute update
> (as damon_update_monitoring_result() does not clear it), does this effectively
> double the count and cause the 8-bit unsigned char to silently wrap around?
> 
> While this requires a tight race between sysfs writes (commit and
> update_schemes_tried_regions), it appears structurally possible.

Good finding, but this issue will only occasionally degrade the accuracy of
probe_hits.  It is too mild issue to block this patch in my opinion.  So, no
blocker unless someone raise a different opinion.

> 
> >  		if (!sys_probe) {
> >  			damos_sysfs_probes_rm_dirs(probes);
> >  			return -ENOMEM;
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260703170605.94472-1-sj@kernel.org?part=3


Thanks,
SJ

      reply	other threads:[~2026-07-03 17:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 17:06 [PATCH 0/3] mm/damon: provide pseudo moving sum probe_hits SJ Park
2026-07-03 17:06 ` [PATCH 1/3] mm/damon: add damon_region->last_probe_hits SJ Park
2026-07-03 17:24   ` sashiko-bot
2026-07-03 17:38     ` SJ Park
2026-07-03 17:06 ` [PATCH 2/3] mm/damon/core: introduce damon_probe_hits_mvsum() SJ Park
2026-07-03 17:06 ` [PATCH 3/3] mm/damon/sysfs-schemes: set probe hits as pseudo moving sums SJ Park
2026-07-03 17:26   ` sashiko-bot
2026-07-03 17:42     ` SJ Park [this message]

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=20260703174228.98368-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