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 1/3] mm/damon/core: deduplicate scheme index lookup into helper
Date: Wed, 25 Mar 2026 07:37:58 +0000 [thread overview]
Message-ID: <20260325073800.141756-2-objecting@objecting.org> (raw)
In-Reply-To: <20260325073800.141756-1-objecting@objecting.org>
Three functions (damos_apply_scheme, damos_trace_esz, damos_trace_stat)
contain identical loops walking the schemes list to find a scheme's
index for tracing. Extract the common pattern into damon_scheme_idx().
Signed-off-by: Josh Law <objecting@objecting.org>
---
mm/damon/core.c | 41 +++++++++++++++++------------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 6ee421141996..56372e577931 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2045,6 +2045,19 @@ static void damos_walk_cancel(struct damon_ctx *ctx)
mutex_unlock(&ctx->walk_control_lock);
}
+static unsigned int damon_scheme_idx(struct damon_ctx *c, struct damos *s)
+{
+ unsigned int idx = 0;
+ struct damos *siter;
+
+ damon_for_each_scheme(siter, c) {
+ if (siter == s)
+ break;
+ idx++;
+ }
+ return idx;
+}
+
static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
struct damon_region *r, struct damos *s)
{
@@ -2060,7 +2073,6 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
* index here.
*/
unsigned int cidx = 0;
- struct damos *siter; /* schemes iterator */
unsigned int sidx = 0;
struct damon_target *titer; /* targets iterator */
unsigned int tidx = 0;
@@ -2068,11 +2080,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
/* get indices for trace_damos_before_apply() */
if (trace_damos_before_apply_enabled()) {
- damon_for_each_scheme(siter, c) {
- if (siter == s)
- break;
- sidx++;
- }
+ sidx = damon_scheme_idx(c, s);
damon_for_each_target(titer, c) {
if (titer == t)
break;
@@ -2394,15 +2402,7 @@ static void damos_set_effective_quota(struct damos_quota *quota)
static void damos_trace_esz(struct damon_ctx *c, struct damos *s,
struct damos_quota *quota)
{
- unsigned int cidx = 0, sidx = 0;
- struct damos *siter;
-
- damon_for_each_scheme(siter, c) {
- if (siter == s)
- break;
- sidx++;
- }
- trace_damos_esz(cidx, sidx, quota->esz);
+ trace_damos_esz(0, damon_scheme_idx(c, s), quota->esz);
}
static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
@@ -2469,18 +2469,11 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
static void damos_trace_stat(struct damon_ctx *c, struct damos *s)
{
- unsigned int cidx = 0, sidx = 0;
- struct damos *siter;
-
if (!trace_damos_stat_after_apply_interval_enabled())
return;
- damon_for_each_scheme(siter, c) {
- if (siter == s)
- break;
- sidx++;
- }
- trace_damos_stat_after_apply_interval(cidx, sidx, &s->stat);
+ trace_damos_stat_after_apply_interval(0, damon_scheme_idx(c, s),
+ &s->stat);
}
static void kdamond_apply_schemes(struct damon_ctx *c)
--
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 ` Josh Law [this message]
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 ` [PATCH 3/3] mm/damon/core: move last_nr_regions from static local to damon_ctx Josh Law
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-2-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