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] mm/damon/core: deduplicate core and ops filter commit functions
Date: Wed, 25 Mar 2026 20:42:50 +0000 [thread overview]
Message-ID: <20260325204250.254364-1-objecting@objecting.org> (raw)
damos_commit_core_filters() and damos_commit_ops_filters() are
identical except for which filter list they operate on. The same
duplication exists in damos_nth_core_filter() and
damos_nth_ops_filter().
Unify each pair into a single function that takes the list_head
directly: damos_nth_filter() and damos_commit_filters_of(). This
follows the same pattern already used by damos_filters_default_reject()
in the same file.
Signed-off-by: Josh Law <objecting@objecting.org>
---
mm/damon/core.c | 61 +++++++++++--------------------------------------
1 file changed, 13 insertions(+), 48 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index b2361dbf78d1..83b0542f4d76 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -919,24 +919,13 @@ static int damos_commit_quota(struct damos_quota *dst, struct damos_quota *src)
return 0;
}
-static struct damos_filter *damos_nth_core_filter(int n, struct damos *s)
+static struct damos_filter *damos_nth_filter(int n,
+ struct list_head *filters)
{
struct damos_filter *filter;
int i = 0;
- damos_for_each_core_filter(filter, s) {
- if (i++ == n)
- return filter;
- }
- return NULL;
-}
-
-static struct damos_filter *damos_nth_ops_filter(int n, struct damos *s)
-{
- struct damos_filter *filter;
- int i = 0;
-
- damos_for_each_ops_filter(filter, s) {
+ list_for_each_entry(filter, filters, list) {
if (i++ == n)
return filter;
}
@@ -973,48 +962,22 @@ static void damos_commit_filter(
damos_commit_filter_arg(dst, src);
}
-static int damos_commit_core_filters(struct damos *dst, struct damos *src)
-{
- struct damos_filter *dst_filter, *next, *src_filter, *new_filter;
- int i = 0, j = 0;
-
- damos_for_each_core_filter_safe(dst_filter, next, dst) {
- src_filter = damos_nth_core_filter(i++, src);
- if (src_filter)
- damos_commit_filter(dst_filter, src_filter);
- else
- damos_destroy_filter(dst_filter);
- }
-
- damos_for_each_core_filter_safe(src_filter, next, src) {
- if (j++ < i)
- continue;
-
- new_filter = damos_new_filter(
- src_filter->type, src_filter->matching,
- src_filter->allow);
- if (!new_filter)
- return -ENOMEM;
- damos_commit_filter_arg(new_filter, src_filter);
- damos_add_filter(dst, new_filter);
- }
- return 0;
-}
-
-static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
+static int damos_commit_filters_of(struct damos *dst,
+ struct list_head *dst_filters,
+ struct list_head *src_filters)
{
struct damos_filter *dst_filter, *next, *src_filter, *new_filter;
int i = 0, j = 0;
- damos_for_each_ops_filter_safe(dst_filter, next, dst) {
- src_filter = damos_nth_ops_filter(i++, src);
+ list_for_each_entry_safe(dst_filter, next, dst_filters, list) {
+ src_filter = damos_nth_filter(i++, src_filters);
if (src_filter)
damos_commit_filter(dst_filter, src_filter);
else
damos_destroy_filter(dst_filter);
}
- damos_for_each_ops_filter_safe(src_filter, next, src) {
+ list_for_each_entry_safe(src_filter, next, src_filters, list) {
if (j++ < i)
continue;
@@ -1108,10 +1071,12 @@ static int damos_commit_filters(struct damos *dst, struct damos *src)
{
int err;
- err = damos_commit_core_filters(dst, src);
+ err = damos_commit_filters_of(dst, &dst->core_filters,
+ &src->core_filters);
if (err)
return err;
- err = damos_commit_ops_filters(dst, src);
+ err = damos_commit_filters_of(dst, &dst->ops_filters,
+ &src->ops_filters);
if (err)
return err;
damos_set_filters_default_reject(dst);
--
2.34.1
next reply other threads:[~2026-03-25 20:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 20:42 Josh Law [this message]
2026-03-25 23:59 ` (sashiko status) [PATCH] mm/damon/core: deduplicate core and ops filter commit functions SeongJae 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=20260325204250.254364-1-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