From: SJ Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SJ Park <sj@kernel.org>,
stable@vger.kernel.org, Jiayuan Chen <jiayuan.chen@shopee.com>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [PATCH 3/3] mm/damon/core: move static variable rotation to damon_ctx
Date: Sun, 25 Oct 2026 09:48:06 -0700 [thread overview]
Message-ID: <20261025164808.152048-4-sj@kernel.org> (raw)
In-Reply-To: <20261025164808.152048-1-sj@kernel.org>
damon_split_some_reigons() uses a static variable, rotation, to remember
how many times it was called. It is again used to determine fair
selection of regions to split. Since it is a static variable, it can be
indeterministic and therefore less fair.
The user impact is not critical. No crash, no leak. DAMON's
best-effort and indeterministic monitoring accuracy could be slightly
more indeterministic when multiple kdamonds are used in parallel.
Fix the problem by moving the static variable into the damon_ctx struct.
Fixes: 1a582e6e0174 ("mm/damon/core: split a fraction of regions when nr_regions exceeds max/2")
Cc: <stable@vger.kernel.org> # 7.3.x
Closes: https://sashiko.dev/#/bug/linux-eebfcdde-2881-48ef-8df1-e2019d2a47f2
Signed-off-by: SJ Park <sj@kernel.org>
---
include/linux/damon.h | 5 +++++
mm/damon/core.c | 5 +++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index cb6a50032a1eb..380f9cf6ddd82 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -963,6 +963,11 @@ struct damon_ctx {
* for more details.
*/
unsigned long last_nr_regions;
+ /*
+ * number of damon_split_some_regions() invocations for this context.
+ * Read damon_split_some_regions() for more details.
+ */
+ unsigned long region_split_rotation;
};
/* Get a random number in [@l, @r) using @ctx's lockless PRNG. */
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 09722257ce736..73b571b429cb3 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3753,12 +3753,13 @@ static void damon_split_regions_of(struct damon_ctx *ctx,
static void damon_split_some_regions(struct damon_ctx *ctx,
unsigned long split_step)
{
- static unsigned long rotation;
struct damon_target *t;
struct damon_region *r, *next;
- unsigned long offset = rotation++ % split_step;
+ unsigned long offset;
unsigned long idx = 0;
+ offset = ctx->region_split_rotation++ % split_step;
+
damon_for_each_target(t, ctx) {
damon_for_each_region_safe(r, next, t) {
unsigned long sz_region, sz_sub;
--
2.47.3
next prev parent reply other threads:[~2026-10-25 16:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 16:48 [PATCH 0/3] mm/damon: fix three race bugs in sysfs and core SJ Park
2026-10-25 16:48 ` [PATCH 1/3] mm/damon/sysfs-schemes: hold damon_sysfs_lock in target_metric_store() SJ Park
2026-10-25 16:52 ` sashiko-bot
2026-10-25 16:48 ` [PATCH 2/3] mm/damon/core: move static variable last_nr_regions to damon_ctx SJ Park
2026-10-25 16:53 ` sashiko-bot
2026-10-25 16:48 ` SJ Park [this message]
2026-10-25 16:51 ` [PATCH 3/3] mm/damon/core: move static variable rotation " sashiko-bot
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=20261025164808.152048-4-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.