* [PATCH] mm/damon/core: deduplicate core and ops filter commit functions
@ 2026-03-25 20:42 Josh Law
2026-03-25 23:59 ` (sashiko status) " SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: Josh Law @ 2026-03-25 20:42 UTC (permalink / raw)
To: SeongJae Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel, Josh Law
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: (sashiko status) [PATCH] mm/damon/core: deduplicate core and ops filter commit functions
2026-03-25 20:42 [PATCH] mm/damon/core: deduplicate core and ops filter commit functions Josh Law
@ 2026-03-25 23:59 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2026-03-25 23:59 UTC (permalink / raw)
To: Josh Law; +Cc: SeongJae Park, Andrew Morton, damon, linux-mm, linux-kernel
Forwarding sashiko.dev review status for this thread.
# review url: https://sashiko.dev/#/patchset/20260325204250.254364-1-objecting@objecting.org
- [PATCH] mm/damon/core: deduplicate core and ops filter commit functions
- status: Reviewed
- review: No issues found.
# hkml [1] generated a draft of this mail. It can be regenerated
# using below command:
#
# hkml patch sashiko_dev --thread_status --for_forwarding \
# 20260325204250.254364-1-objecting@objecting.org
#
# [1] https://github.com/sjp38/hackermail
Sent using hkml (https://github.com/sjp38/hackermail)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-25 23:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25 20:42 [PATCH] mm/damon/core: deduplicate core and ops filter commit functions Josh Law
2026-03-25 23:59 ` (sashiko status) " SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox