From: Josh Law <objecting@objecting.org>
To: SeongJae Park <sj@kernel.org>, Andrew Morton <akpm@linux-foundation.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Josh Law <objecting@objecting.org>
Subject: [PATCH 3/3] mm/damon/core: move last_nr_regions from static local to damon_ctx
Date: Wed, 25 Mar 2026 07:38:00 +0000 [thread overview]
Message-ID: <20260325073800.141756-4-objecting@objecting.org> (raw)
In-Reply-To: <20260325073800.141756-1-objecting@objecting.org>
kdamond_split_regions() uses a function-level static variable to
remember the previous iteration's region count. This is shared across
all kdamond threads, so one kdamond's region count leaks into another's
splitting decision. Move the variable into struct damon_ctx so each
kdamond tracks its own state.
Signed-off-by: Josh Law <objecting@objecting.org>
---
include/linux/damon.h | 2 ++
mm/damon/core.c | 5 ++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 438fe6f3eab4..85fe33ce7be4 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -803,6 +803,8 @@ struct damon_ctx {
struct completion kdamond_started;
/* for scheme quotas prioritization */
unsigned long *regions_score_histogram;
+ /* for kdamond_split_regions() heuristic */
+ unsigned int last_nr_regions;
/* lists of &struct damon_call_control */
struct list_head call_controls;
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 6c1f738e265c..50e8bdeb70dd 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2722,7 +2722,6 @@ static void kdamond_split_regions(struct damon_ctx *ctx)
{
struct damon_target *t;
unsigned int nr_regions = 0;
- static unsigned int last_nr_regions;
int nr_subregions = 2;
damon_for_each_target(t, ctx)
@@ -2732,14 +2731,14 @@ static void kdamond_split_regions(struct damon_ctx *ctx)
return;
/* Maybe the middle of the region has different access frequency */
- if (last_nr_regions == nr_regions &&
+ if (ctx->last_nr_regions == nr_regions &&
nr_regions < ctx->attrs.max_nr_regions / 3)
nr_subregions = 3;
damon_for_each_target(t, ctx)
damon_split_regions_of(t, nr_subregions, ctx->min_region_sz);
- last_nr_regions = nr_regions;
+ ctx->last_nr_regions = nr_regions;
}
/*
--
2.34.1
next prev parent reply other threads:[~2026-03-25 7:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 7:37 [PATCH 0/3] mm/damon/core: small cleanups Josh Law
2026-03-25 7:37 ` [PATCH 1/3] mm/damon/core: deduplicate scheme index lookup into helper Josh Law
2026-03-25 7:37 ` [PATCH 2/3] mm/damon/core: use damon_nr_regions() in damon_commit_target_regions() Josh Law
2026-03-25 7:38 ` Josh Law [this message]
2026-03-25 14:58 ` (sashiko status) [PATCH 0/3] mm/damon/core: small cleanups SeongJae Park
2026-03-25 15:44 ` Josh Law
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=20260325073800.141756-4-objecting@objecting.org \
--to=objecting@objecting.org \
--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 \
/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