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 09/11] mm/damon/sysfs: split probe setup function out
Date: Tue, 30 Jun 2026 07:17:23 -0700 [thread overview]
Message-ID: <20260630141726.92246-10-sj@kernel.org> (raw)
In-Reply-To: <20260630141726.92246-1-sj@kernel.org>
damon_sysfs_set_probes() function is relatively long. It has two nested
loop for setting two nested entities, namely probe and filter. Split
out the probe level setup for readability.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs.c | 80 ++++++++++++++++++++++++++++--------------------
1 file changed, 46 insertions(+), 34 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index e3526a263e205..02afd37b04df4 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1909,47 +1909,59 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ctx,
return damon_set_attrs(ctx, &attrs);
}
-static int damon_sysfs_set_probes(struct damon_ctx *ctx,
- struct damon_sysfs_probes *sys_probes)
+static int damon_sysfs_set_probe(struct damon_probe *probe,
+ struct damon_sysfs_probe *sys_probe)
{
+ struct damon_sysfs_filters *sys_filters;
int i;
- for (i = 0; i < sys_probes->nr; i++) {
- struct damon_sysfs_filters *sys_filters =
- sys_probes->probes_arr[i]->filters;
- struct damon_probe *c;
- int j;
+ sys_filters = sys_probe->filters;
+ if (!sys_filters)
+ return 0;
- if (!sys_filters)
- continue;
- c = damon_new_probe();
- if (!c)
+ for (i = 0; i < sys_filters->nr; i++) {
+ struct damon_sysfs_filter *sys_filter =
+ sys_filters->filters_arr[i];
+ struct damon_filter *filter;
+
+ filter = damon_new_filter(sys_filter->type,
+ sys_filter->matching,
+ sys_filter->allow);
+ if (!filter)
return -ENOMEM;
- damon_add_probe(ctx, c);
-
- for (j = 0; j < sys_filters->nr; j++) {
- struct damon_sysfs_filter *sys_filter =
- sys_filters->filters_arr[j];
- struct damon_filter *filter;
-
- filter = damon_new_filter(sys_filter->type,
- sys_filter->matching,
- sys_filter->allow);
- if (!filter)
- return -ENOMEM;
- if (filter->type == DAMON_FILTER_TYPE_MEMCG) {
- int err;
-
- err = damon_sysfs_memcg_path_to_id(
- sys_filter->path,
- &filter->memcg_id);
- if (err) {
- damon_destroy_filter(filter);
- return err;
- }
+ if (filter->type == DAMON_FILTER_TYPE_MEMCG) {
+ int err;
+
+ err = damon_sysfs_memcg_path_to_id(
+ sys_filter->path,
+ &filter->memcg_id);
+ if (err) {
+ damon_destroy_filter(filter);
+ return err;
}
- damon_add_filter(c, filter);
}
+ damon_add_filter(probe, filter);
+ }
+ return 0;
+}
+
+static int damon_sysfs_set_probes(struct damon_ctx *ctx,
+ struct damon_sysfs_probes *sys_probes)
+{
+ int i, err;
+
+ for (i = 0; i < sys_probes->nr; i++) {
+ struct damon_sysfs_probe *sys_probe;
+ struct damon_probe *p;
+
+ p = damon_new_probe();
+ if (!p)
+ return -ENOMEM;
+ damon_add_probe(ctx, p);
+ sys_probe = sys_probes->probes_arr[i];
+ err = damon_sysfs_set_probe(p, sys_probe);
+ if (err)
+ return err;
}
return 0;
}
--
2.47.3
next prev parent reply other threads:[~2026-06-30 14:18 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 ` [PATCH 08/11] mm/damon/core: reduce range setup in damon_commit_target_regions() SJ Park
2026-06-30 14:17 ` SJ Park [this message]
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-10-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 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.