From: Liew Rui Yan <aethernet65535@gmail.com>
To: suhaas@s-joshi.in
Cc: Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, SJ Park <sj@kernel.org>,
Liew Rui Yan <aethernet65535@gmail.com>
Subject: [PATCH 1/2] mm/damon/core: Use only installed probe in damon_merge_two_regions()
Date: Thu, 8 Oct 2026 18:40:29 +0800 [thread overview]
Message-ID: <20261008104112.4763-1-aethernet65535@gmail.com> (raw)
In-Reply-To: <20261007154851.45368-2-suhaas@s-joshi.in>
Hi Suhaas,
Thank you for your patches series!
On Wed, 07 Oct 2026 21:18:45 +0530 Suhaas Joshi <suhaas@s-joshi.in> wrote:
> While merging 2 regions, we iterate over the entire probe_hits[] array,
> whose size is determined by the DAMON_MAX_PROBES macro. It is possible,
> however, that we have fewer probes installed than DAMON_MAX_PROBES. In such
I find this a bit hard to read. Could we change it to this?
"However, it is possible that we have fewer probes installed than
DAMON_MAX_PROBES."
> cases, we end up making redundant iterations. Therefore, to remedy this,
> iterate over the list of installed probes instead of iterating over the
> entire array. For doing this, start accepting a struct damon_ctx in
> damon_merge_two_regions(), and update calling functions to pass this
> argument.
>
> Update the damon_test_merge_two() test to use this new signature for
> damon_merge_two_regions() as well.
>
> Signed-off-by: Suhaas Joshi <suhaas@s-joshi.in>
> ---
> mm/damon/core.c | 14 +++++++++-----
> mm/damon/tests/core-kunit.h | 19 +++++++++++++++++--
> 2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 733025b36745..a3af5ee685e1 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -3499,20 +3499,24 @@ static void damon_verify_merge_two_regions(
> /*
> * Merge two adjacent regions into one region
> */
> -static void damon_merge_two_regions(struct damon_target *t,
> - struct damon_region *l, struct damon_region *r)
> +static void damon_merge_two_regions(struct damon_ctx *ctx, struct damon_target *t,
> + struct damon_region *l, struct damon_region *r)
> {
> unsigned long sz_l = damon_sz_region(l), sz_r = damon_sz_region(r);
> int i;
> + struct damon_probe *p;
>
> l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) /
> (sz_l + sz_r);
> l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r);
> l->ar.end = r->ar.end;
> - /* todo: do this for only installed probes */
> - for (i = 0; i < DAMON_MAX_PROBES; i++)
> +
> + i = 0;
> + damon_for_each_probe(p, ctx) {
> l->probe_hits[i] = (l->probe_hits[i] * sz_l + r->probe_hits[i]
> * sz_r) / (sz_l + sz_r);
> + ++i;
> + }
> damon_verify_merge_two_regions(l, r);
> damon_destroy_region(r, t);
> }
> @@ -3565,7 +3569,7 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres,
> goto set_prev_continue;
> if (damon_sz_region(prev) + damon_sz_region(r) > sz_limit)
> goto set_prev_continue;
> - damon_merge_two_regions(t, prev, r);
> + damon_merge_two_regions(ctx, t, prev, r);
> continue;
> set_prev_continue:
> prev = r;
> diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> index df84d9cc7d20..5ad89c1d9fc2 100644
> --- a/mm/damon/tests/core-kunit.h
> +++ b/mm/damon/tests/core-kunit.h
> @@ -182,13 +182,27 @@ static void damon_test_merge_two(struct kunit *test)
> {
> struct damon_target *t;
> struct damon_region *r, *r2, *r3;
> + struct damon_probe *p;
> + struct damon_ctx *ctx;
> int i;
>
> + p = damon_new_probe();
> + if (!p)
> + kunit_skip(test, "probe alloc fail");
> + ctx = damon_new_ctx();
> + if (!ctx) {
> + damon_destroy_probe(p);
> + kunit_skip(test, "context alloc fail");
> + }
> + damon_add_probe(ctx, p);
> t = damon_new_target();
> - if (!t)
> + if (!t) {
> + damon_destroy_ctx(ctx);
> kunit_skip(test, "target alloc fail");
> + }
> r = damon_new_region(0, 100);
> if (!r) {
> + damon_destroy_ctx(ctx);
> damon_free_target(t);
> kunit_skip(test, "region alloc fail");
> }
> @@ -206,7 +220,7 @@ static void damon_test_merge_two(struct kunit *test)
> r2->age = 21;
> damon_add_region(r2, t);
>
> - damon_merge_two_regions(t, r, r2);
> + damon_merge_two_regions(ctx, t, r, r2);
> KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
> KUNIT_EXPECT_EQ(test, r->ar.end, 300ul);
> KUNIT_EXPECT_EQ(test, r->nr_accesses, 16u);
> @@ -220,6 +234,7 @@ static void damon_test_merge_two(struct kunit *test)
> }
> KUNIT_EXPECT_EQ(test, i, 1);
>
> + damon_destroy_ctx(ctx);
> damon_free_target(t);
> }
>
> --
> 2.55.0
Other than the commit message I just mentioned, and the issue reported
[1] by Sashiko, LGTM.
Reviewed-by: Liew Rui Yan <aethernet65535@gmail.com>
[1] https://lore.kernel.org/damon/sashiko-outbox-163177@kernel.org
Best regards,
Rui Yan
next prev parent reply other threads:[~2026-10-08 10:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261007154851.45368-1-suhaas@s-joshi.in>
2026-10-07 15:48 ` Suhaas Joshi
2026-10-08 10:40 ` Liew Rui Yan [this message]
2026-10-08 10:44 ` SJ Park
2026-10-07 15:48 ` [PATCH 2/2] mm/damon/core: Copy only installed probe in damon_split_region_at() Suhaas Joshi
2026-10-08 10:44 ` Liew Rui Yan
2026-10-08 11:03 ` 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=20261008104112.4763-1-aethernet65535@gmail.com \
--to=aethernet65535@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.org \
--cc=suhaas@s-joshi.in \
/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
all inboxes | Powered by JetHome®