From: SJ Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SJ Park <sj@kernel.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [PATCH 08/11] mm/damon/core: reduce range setup in damon_commit_target_regions()
Date: Tue, 30 Jun 2026 07:17:22 -0700 [thread overview]
Message-ID: <20260630141726.92246-9-sj@kernel.org> (raw)
In-Reply-To: <20260630141726.92246-1-sj@kernel.org>
damon_commit_target_regions() calls damon_set_regions() for updating the
destination target's monitoring target region boundaries. It sets the
boundaries same to source target's monitoring regions, even if they are
adjacent. Meanwhile, damon_set_region() sets the destination target
regions exactly the same to the source, only when the target regions are
empty. When there are existing target regions, only a few regions are
expanded or shrunk to fit on only the boundaries for disjoint regions in
the source. Hence the adjacent source ranges mean nothing in common
cases. When there are many regions, such adjacent range setup is only a
waste of time and space. We recently found [1] it is actually causing
memory overhead. Setup the ranges for only distinct ranges.
[1] https://lore.kernel.org/20260603112306.58490-1-akinobu.mita@gmail.com
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/core.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 59a91a0ab6d45..c6fc35be633b3 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1414,21 +1414,33 @@ static struct damon_target *damon_nth_target(int n, struct damon_ctx *ctx)
static int damon_commit_target_regions(struct damon_target *dst,
struct damon_target *src, unsigned long src_min_region_sz)
{
- struct damon_region *src_region;
+ struct damon_region *src_region, *prev = NULL;
struct damon_addr_range *ranges;
int i = 0, err;
- damon_for_each_region(src_region, src)
- i++;
+ damon_for_each_region(src_region, src) {
+ if (!prev || prev->ar.end != src_region->ar.start)
+ i++;
+ prev = src_region;
+ }
if (!i)
return 0;
ranges = kvmalloc_objs(*ranges, i, GFP_KERNEL | __GFP_NOWARN);
if (!ranges)
return -ENOMEM;
+ prev = NULL;
i = 0;
- damon_for_each_region(src_region, src)
- ranges[i++] = src_region->ar;
+ damon_for_each_region(src_region, src) {
+ if (!prev) {
+ ranges[i].start = src_region->ar.start;
+ } else if (prev->ar.end != src_region->ar.start) {
+ ranges[i++].end = prev->ar.end;
+ ranges[i].start = src_region->ar.start;
+ }
+ prev = src_region;
+ }
+ ranges[i++].end = damon_last_region(src)->ar.end;
err = damon_set_regions(dst, ranges, i, src_min_region_sz);
kvfree(ranges);
return err;
--
2.47.3
next prev parent reply other threads:[~2026-06-30 14:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 14:17 [PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SJ Park
2026-06-30 14:17 ` [PATCH 01/11] Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP SJ Park
2026-06-30 14:17 ` [PATCH 02/11] Docs/ABI/damon: document probe files SJ Park
2026-06-30 14:17 ` [PATCH 03/11] mm/damon/tests/core-kunit: test damon_rand() SJ Park
2026-06-30 14:25 ` sashiko-bot
2026-06-30 14:54 ` SJ Park
2026-06-30 14:17 ` [PATCH 04/11] selftests/damon/sysfs.sh: test multiple probe dirs creation SJ Park
2026-06-30 14:17 ` [PATCH 05/11] selftests/damon/sysfs.sh: test {core,ops}_filters/ directories SJ Park
2026-06-30 14:17 ` [PATCH 06/11] selftests/damon/sysfs.sh: test dests dir SJ Park
2026-06-30 14:17 ` [PATCH 07/11] selftests/damon/sysfs.sh: test all files in quota goal dir SJ Park
2026-06-30 14:17 ` SJ Park [this message]
2026-06-30 14:17 ` [PATCH 09/11] mm/damon/sysfs: split probe setup function out SJ Park
2026-06-30 14:17 ` [PATCH 10/11] mm/damon/sysfs: split out filters setup function SJ Park
2026-06-30 14:17 ` [PATCH 11/11] mm/damon/sysfs: fix typos in probe_{add,rm}_dirs: s/attr/probe/ SJ Park
2026-06-30 14:57 ` [PATCH 00/11] mm/damon: update, optimize, and clean up doc, tests, and code 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=20260630141726.92246-9-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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