DAMON development mailing list
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v2.2 05/28] mm/damon/core: introduce damon_region->probe_hits
Date: Fri, 15 May 2026 17:35:58 -0700	[thread overview]
Message-ID: <20260516003559.141476-1-sj@kernel.org> (raw)
In-Reply-To: <20260515005446.EEF89C2BCB3@smtp.kernel.org>

On Fri, 15 May 2026 00:54:46 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
> - [High] The `probe_hits` array is not propagated to the new sub-region during a region split.
> - [High] The `probe_hits` array is not recalculated during a region merge.
> - [High] The `probe_hits` counters are susceptible to integer overflow.
> - [Medium] The `probe_hits` array is not scaled when monitoring attributes change dynamically.
> --
> 
> commit 5ada6fcb6176988079396fb12d1bf709aa9d2522
> Author: SeongJae Park <sj@kernel.org>
> 
> mm/damon/core: introduce damon_region->probe_hits
>     
> Add an array for the per-region per-probe positive samples count.  For
> simple and efficient implementation, add a limit to the number of data
> probes and set the array to support only the limited number of counters.
> 
> > diff --git a/include/linux/damon.h b/include/linux/damon.h
> > index 9c2576f103767..bf78ad849a9be 100644
> > --- a/include/linux/damon.h
> > +++ b/include/linux/damon.h
> [ ... ]
> > @@ -80,6 +83,7 @@ struct damon_region {
> >  	unsigned long sampling_addr;
> >  	unsigned int nr_accesses;
> >  	unsigned int nr_accesses_bp;
> > +	unsigned char probe_hits[DAMON_MAX_PROBES];
> >  	struct list_head list;
> 
> Can this overflow?
> 
> Since it is an 8-bit unsigned char, it can hold a maximum of 255.
> The number of samples per aggregation interval is aggr_interval /
> sample_interval. Both are user-configurable via damon_set_attrs(), so
> configurations that yield more than 255 samples per interval could
> overflow this counter and corrupt the exposed data.

Yes, but such configurations may be rare.  The default and recommended
configuration is to have 20 as the max number.  And users who runs proper
testing before deploying changes to the production may find the issue.

But better to avoid that if possible.  I will consider returning error when
such configuration is committed.

> 
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 15f2795a1156f..f6b4beb4b8ecd 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> [ ... ]
> > @@ -235,6 +236,8 @@ struct damon_region *damon_new_region(unsigned long start, unsigned long end)
> >  	region->ar.end = end;
> >  	region->nr_accesses = 0;
> >  	region->nr_accesses_bp = 0;
> > +	for (i = 0; i < DAMON_MAX_PROBES; i++)
> > +		region->probe_hits[i] = 0;
> >  	INIT_LIST_HEAD(&region->list);
> >  
> >  	region->age = 0;
> 
> Are we missing a copy of probe_hits in damon_split_region_at()?
> 
> When a region is split, the new right-hand sub-region gets zeroed
> counters from damon_new_region(), losing its historical positive sample
> counts for the current aggregation interval:
> 
> mm/damon/core.c:damon_split_region_at() {
> 	...
> 	new = damon_new_region(r->ar.start + sz_r, r->ar.end);
> 	if (!new)
> 		return;
> 
> 	r->ar.end = new->ar.start;
> 
> 	new->age = r->age;
> 	new->last_nr_accesses = r->last_nr_accesses;
> 	new->nr_accesses_bp = r->nr_accesses_bp;
> 	new->nr_accesses = r->nr_accesses;
> 	...
> }

Nice catch!  I will do that in the next revision.

> 
> Should probe_hits also be merged in damon_merge_two_regions()?
> 
> When adjacent regions are merged, l->nr_accesses and l->age are
> recalibrated using a size-weighted average. However, the probe_hits
> array of l is left untouched, and the probe_hits data from r is entirely
> discarded:
> 
> mm/damon/core.c:damon_merge_two_regions() {
> 	...
> 	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;
> 	l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r);
> 	l->ar.end = r->ar.end;
> 	...
> 	damon_destroy_region(r, t);
> }
> 
> Does probe_hits need to be scaled in damon_update_monitoring_result()
> when monitoring attributes change dynamically?
> 
> Since it tracks positive samples over the aggregation interval just like
> nr_accesses, leaving it unscaled might result in stale values that
> misalign with the new interval constraints.

Good finding!  I will do that in the next revision.


Thanks,
SJ

[...]

  reply	other threads:[~2026-05-16  0:36 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15  0:44 [RFC PATCH v2.2 00/28] mm/damon: introduce data attributes monitoring SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 01/28] mm/damon/core: introduce struct damon_probe SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 02/28] mm/damon/core: embed damon_probe objects in damon_ctx SeongJae Park
2026-05-15  1:17   ` sashiko-bot
2026-05-15 22:58     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 03/28] mm/damon/core: introduce damon_filter SeongJae Park
2026-05-15  1:14   ` sashiko-bot
2026-05-16  0:11     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 04/28] mm/damon/core: commit probes SeongJae Park
2026-05-15  1:05   ` sashiko-bot
2026-05-16  0:23     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 05/28] mm/damon/core: introduce damon_region->probe_hits SeongJae Park
2026-05-15  0:54   ` sashiko-bot
2026-05-16  0:35     ` SeongJae Park [this message]
2026-05-15  0:44 ` [RFC PATCH v2.2 06/28] mm/damon/core: introduce damon_ops->apply_probes SeongJae Park
2026-05-15  0:53   ` sashiko-bot
2026-05-16  0:41     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 07/28] mm/damon/core: do data attributes monitoring SeongJae Park
2026-05-15  1:05   ` sashiko-bot
2026-05-16  0:46     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 08/28] mm/damon/paddr: support " SeongJae Park
2026-05-15  1:29   ` sashiko-bot
2026-05-16  0:56     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 09/28] mm/damon/sysfs: implement probes dir SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 10/28] mm/damon/sysfs: implement probe dir SeongJae Park
2026-05-15  1:08   ` sashiko-bot
2026-05-16  1:00     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 11/28] mm/damon/sysfs: implement filters directory SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 12/28] mm/damon/sysfs: implement filter dir SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 13/28] mm/damon/sysfs: implement filter dir files SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 14/28] mm/damon/sysfs: setup probes on DAMON core API parameters SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 15/28] mm/damon/sysfs-schemes: implement tried_regions/<r>/probes/ SeongJae Park
2026-05-15  1:27   ` sashiko-bot
2026-05-16  1:27     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 16/28] mm/damon/sysfs-schemes: implement probe dir SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 17/28] mm/damon/sysfs-schemes: implement probe/hits file SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 18/28] mm/damon: trace probe_hits SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 19/28] selftests/damon/sysfs.sh: test probes dir SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 20/28] Docs/mm/damon/design: document data attributes monitoring SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 21/28] Docs/admin-guide/mm/damon/usage: " SeongJae Park
2026-05-15  1:06   ` sashiko-bot
2026-05-16  1:40     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 22/28] mm/damon/core: introduce DAMON_FILTER_TYPE_MEMCG SeongJae Park
2026-05-15  1:22   ` sashiko-bot
2026-05-16  1:45     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 23/28] mm/damon/paddr: support DAMON_FILTER_TYPE_MEMCG SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 24/28] mm/damon/sysfs: add filters/<F>/path file SeongJae Park
2026-05-15  1:35   ` sashiko-bot
2026-05-16  1:47     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 25/28] mm/damon/sysfs-schemes: move memcg_path_to_id() to sysfs-common SeongJae Park
2026-05-15  1:24   ` sashiko-bot
2026-05-16  1:50     ` SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 26/28] mm/damon/sysfs: setup damon_filter->memcg_id from path SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 27/28] Docs/mm/damon/design: update for memcg damon filter SeongJae Park
2026-05-15  0:44 ` [RFC PATCH v2.2 28/28] Docs/admin-guide/mm/damon/usage: " 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=20260516003559.141476-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