From: SeongJae Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 08/14] mm/damon/core: add kdamond_call() debug_sanity check
Date: Fri, 22 May 2026 13:11:10 -0700 [thread overview]
Message-ID: <20260522201111.3319-1-sj@kernel.org> (raw)
In-Reply-To: <20260522175515.0CADA1F000E9@smtp.kernel.org>
On Fri, 22 May 2026 17:55:14 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] Calling damon_nr_regions() instead of accessing t->nr_regions directly causes completely redundant O(N) list traversals and duplicate warnings.
No blocker. Read below for more details.
> --
>
> commit 97b7c0b9ade3ed697ef1eba39c981f58994bd0bd
> Author: SeongJae Park <sj@kernel.org>
>
> mm/damon/core: add kdamond_call() debug_sanity check
>
> This commit introduces a new debugging check, damon_verify_ctx(), which
> runs under CONFIG_DAMON_DEBUG_SANITY. It is called from kdamond_call() to
> ensure the DAMON context state is valid before proceeding.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index d816679dd7020..00e2997524ece 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> [ ... ]
> > @@ -3329,6 +3329,37 @@ static void kdamond_usleep(unsigned long usecs)
> > usleep_range_idle(usecs, usecs + 1);
> > }
> >
> > +#ifdef CONFIG_DAMON_DEBUG_SANITY
> > +static void damon_verify_ctx(struct damon_ctx *c)
> > +{
> > + struct damon_target *t;
> > + struct damon_region *r;
> > +
> > + damon_for_each_target(t, c) {
> > + struct damon_region *prev_r = NULL;
> > + unsigned int nr_regions = 0;
> > +
> > + damon_for_each_region(r, t) {
> > + WARN_ONCE(r->ar.start >= r->ar.end,
> > + "region start (%lu) >= end (%lu)\n",
> > + r->ar.start, r->ar.end);
> > + WARN_ONCE(prev_r && prev_r->ar.end > r->ar.start,
> > + "region overlap (%lu > %lu)\n",
> > + prev_r->ar.end, r->ar.start);
> > + prev_r = r;
> > + nr_regions++;
> > + }
> > + WARN_ONCE(damon_nr_regions(t) != nr_regions,
> > + "nr_regions mismatch: %u != %u\n",
> > + damon_nr_regions(t), nr_regions);
>
> [Severity: Low]
> Does this code perform unnecessary list traversals and cause duplicate warnings?
>
> Since damon_nr_regions() internally calls damon_verify_nr_regions() which
> performs its own O(N) list traversal and issues its own WARN_ONCE on mismatch,
> using it here results in traversing the list multiple times.
>
> It also causes multiple warnings for the exact same mismatch.
Correct. And therefore the next patch is removing damon_verify_nr_regions().
>
> Would it be better to compare against t->nr_regions directly to avoid the
> redundant traversals and duplicate warnings?
For the above reason, no.
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-05-22 20:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 15:40 [PATCH 00/14] mm/damon: minor improvements for code readability and tests SeongJae Park
2026-05-22 15:40 ` [PATCH 01/14] mm/damon/core: safely handle no region case in damon_set_regions() SeongJae Park
2026-05-22 16:18 ` sashiko-bot
2026-05-22 20:09 ` SeongJae Park
2026-05-22 15:40 ` [PATCH 02/14] mm/damon/core: do not use region out of a loop " SeongJae Park
2026-05-22 15:40 ` [PATCH 03/14] samples/damon/mtier: replace damon_add_region() with damon_set_regions() SeongJae Park
2026-05-22 15:40 ` [PATCH 04/14] mm/damon/tests/vaddr-kunit: " SeongJae Park
2026-05-22 15:40 ` [PATCH 05/14] mm/damon/core: hide damon_add_region() SeongJae Park
2026-05-22 15:40 ` [PATCH 06/14] mm/damon/core: hide damon_insert_region() SeongJae Park
2026-05-22 15:40 ` [PATCH 07/14] mm/damon/core: hide damon_destroy_region() SeongJae Park
2026-05-22 15:40 ` [PATCH 08/14] mm/damon/core: add kdamond_call() debug_sanity check SeongJae Park
2026-05-22 17:55 ` sashiko-bot
2026-05-22 20:11 ` SeongJae Park [this message]
2026-05-22 15:40 ` [PATCH 09/14] mm/damon/core: remove damon_verify_nr_regions() SeongJae Park
2026-05-22 15:40 ` [PATCH 10/14] mm/damon/tests/core-kunit: add damon_set_regions() test cases SeongJae Park
2026-05-22 15:40 ` [PATCH 11/14] selftests/damon/sysfs.py: stop kdamonds before failing SeongJae Park
2026-05-22 15:40 ` [PATCH 12/14] selftests/damon/sysfs.sh: test monitoring intervals goal dir SeongJae Park
2026-05-22 15:40 ` [PATCH 13/14] selftests/damon/sysfs.sh: test addr_unit file existence SeongJae Park
2026-05-22 15:40 ` [PATCH 14/14] selftests/damon/sysfs.sh: test pause " SeongJae Park
2026-05-22 20:13 ` [PATCH 00/14] mm/damon: minor improvements for code readability and tests SeongJae Park
2026-05-22 20:22 ` Andrew Morton
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=20260522201111.3319-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