DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.1 6/7] mm/damon/core: update probe hits for new parameter commit
Date: Tue, 07 Jul 2026 14:06:38 +0000	[thread overview]
Message-ID: <20260707140639.449861F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707135038.90068-7-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Silent integer truncation when assigning scaled `probe_hits` from `unsigned int` to `unsigned char`.
- [Low] The KUnit test update adds the required `ctx` parameter but entirely fails to test the new `probe_hits` logic.
--

--- Patch [6]: [RFC PATCH v1.1 6/7] mm/damon/core: update probe hits for new parameter commit ---
commit 4d31f2a415d3352c6ff9b689ba6991c3606580b1
Author: SJ Park <sj@kernel.org>

mm/damon/core: update probe hits for new parameter commit

Users can update DAMON parameters at runtime. If the samples and/or
aggregation intervals are updated in this way, monitoring results depending on
the intervals should also be updated for a more accurate snapshot. This commit
updates probe_hits to reflect these changes.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index cda318806b65b..9a3ff0fe55a61 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -898,10 +898,32 @@ static unsigned int damon_nr_samples_for_new_attrs(unsigned int nr_accesses,
>  			new_attrs);
>  }
>  
> +static void damon_update_probe_hits(struct damon_region *r,
> +		struct damon_attrs *old_attrs, struct damon_attrs *new_attrs,
> +		bool aggregating, struct damon_ctx *ctx)
> +{
> +	struct damon_probe *p;
> +	int i = 0;
> +
> +	damon_for_each_probe(p, ctx) {
> +		r->last_probe_hits[i] = damon_nr_samples_for_new_attrs(
> +				r->last_probe_hits[i], old_attrs, new_attrs);

[Severity: Medium]
Does this code silently truncate the scaled sample counts?

The function damon_nr_samples_for_new_attrs() computes and returns an
unsigned int. However, r->last_probe_hits and r->probe_hits are arrays of
unsigned char.

If a privileged user updates DAMON parameters via sysfs such that the new
aggr_interval / sample_interval ratio scales the existing hits beyond 255, it
will silently truncate (modulo 256), losing the accuracy of the metric. 

Should the result be explicitly clamped via min_t(), or the underlying type
widened?

> +		if (!aggregating)
> +			r->probe_hits[i] = damon_nr_samples_for_new_attrs(
> +					r->probe_hits[i], old_attrs,
> +					new_attrs);
> +		else
> +			r->probe_hits[i] = 0;
> +		i++;
> +	}
> +}

[ ... ]

> diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> index 9e631b19b184a..b4feef1a460f4 100644
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -591,32 +591,39 @@ static void damon_test_update_monitoring_result(struct kunit *test)
>  		.sample_interval = 10, .aggr_interval = 1000,};
>  	struct damon_attrs new_attrs;
>  	struct damon_region *r = damon_new_region(3, 7);
> +	struct damon_ctx *ctx;
>  
>  	if (!r)
>  		kunit_skip(test, "region alloc fail");
> +	ctx = damon_new_ctx();
> +	if (!ctx) {
> +		damon_free_region(r);
> +		kunit_skip(test, "ctx alloc fail");
> +	}

[Severity: Low]
Is the new probe_hits logic effectively dead code during this test?

The test allocates a new damon_ctx via damon_new_ctx(), but it doesn't add
any mock probes to it, nor does it initialize any probe_hits on the test
region. 

As a result, the new damon_for_each_probe() loop in
damon_update_probe_hits() exits immediately without testing the scaling logic.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260707135038.90068-1-sj@kernel.org?part=6

  reply	other threads:[~2026-07-07 14:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 13:50 [RFC PATCH v1.1 0/7] mm/damon: update probe hits for runtime parameter commits SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 1/7] mm/damon/core: remove obsolete comment for nr_to_bp() divide-by-zero SJ Park
2026-07-07 13:57   ` sashiko-bot
2026-07-07 14:19     ` SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 2/7] mm/damon/core: s/damon_max_nr_accesses()/damon_nr_samples_per_aggr()/ SJ Park
2026-07-07 13:58   ` sashiko-bot
2026-07-07 14:21     ` SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/ SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 4/7] mm/damon/core: s/nr_accesses_to_accesses_bp/sample_count_to_bp/ SJ Park
2026-07-07 14:02   ` sashiko-bot
2026-07-07 14:26     ` SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/ SJ Park
2026-07-07 14:05   ` sashiko-bot
2026-07-07 14:27     ` SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 6/7] mm/damon/core: update probe hits for new parameter commit SJ Park
2026-07-07 14:06   ` sashiko-bot [this message]
2026-07-07 14:30     ` SJ Park
2026-07-07 13:50 ` [RFC PATCH v1.1 7/7] mm/damon/core: handle unreset probe_hits in probe_hits_mvsum() 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=20260707140639.449861F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sj@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