[RFC PATCH v2.1 06/17] mm/damon/core: commit preps

From: SJ Park

Date: Mon Jul 27 2026 - 11:00:52 EST


damon_commit_probes() is ignoring damon_prep. Commit the prep actions,
too.

Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
mm/damon/core.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index bda61f9ec0266..c74dee56efee8 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -128,11 +128,34 @@ void damon_add_prep(struct damon_probe *p, struct damon_prep *prep)
list_add_tail(&prep->list, &p->preps);
}

+static void damon_del_prep(struct damon_prep *p)
+{
+ list_del(&p->list);
+}
+
static void damon_free_prep(struct damon_prep *p)
{
kfree(p);
}

+static void damon_destroy_prep(struct damon_prep *p)
+{
+ damon_del_prep(p);
+ damon_free_prep(p);
+}
+
+static struct damon_prep *damon_nth_prep(int n, struct damon_probe *p)
+{
+ struct damon_prep *prep;
+ int i = 0;
+
+ damon_for_each_prep(prep, p) {
+ if (i++ == n)
+ return prep;
+ }
+ return NULL;
+}
+
struct damon_filter *damon_new_filter(enum damon_filter_type type,
bool matching, bool allow)
{
@@ -1694,6 +1717,36 @@ static int damon_commit_targets(
return err;
}

+static void damon_commit_prep(struct damon_prep *dst, struct damon_prep *src)
+{
+ dst->action = src->action;
+}
+
+static int damon_commit_preps(struct damon_probe *dst, struct damon_probe *src)
+{
+ struct damon_prep *dst_prep, *next, *src_prep, *new_prep;
+ int i = 0, j = 0;
+
+ damon_for_each_prep_safe(dst_prep, next, dst) {
+ src_prep = damon_nth_prep(i++, src);
+ if (src_prep)
+ damon_commit_prep(dst_prep, src_prep);
+ else
+ damon_destroy_prep(dst_prep);
+ }
+
+ damon_for_each_prep_safe(src_prep, next, src) {
+ if (j++ < i)
+ continue;
+
+ new_prep = damon_new_prep(src_prep->action);
+ if (!new_prep)
+ return -ENOMEM;
+ damon_add_prep(dst, new_prep);
+ }
+ return 0;
+}
+
static void damon_commit_filter(struct damon_filter *dst,
struct damon_filter *src)
{
@@ -1752,6 +1805,9 @@ static int damon_commit_probes(struct damon_ctx *dst, struct damon_ctx *src)
src_probe = damon_nth_probe(i++, src);
if (src_probe) {
dst_probe->weight = src_probe->weight;
+ err = damon_commit_preps(dst_probe, src_probe);
+ if (err)
+ return err;
err = damon_commit_filters(dst_probe, src_probe);
if (err)
return err;
@@ -1769,6 +1825,9 @@ static int damon_commit_probes(struct damon_ctx *dst, struct damon_ctx *src)
return -ENOMEM;
damon_add_probe(dst, new_probe);
new_probe->weight = src_probe->weight;
+ err = damon_commit_preps(new_probe, src_probe);
+ if (err)
+ return err;
err = damon_commit_filters(new_probe, src_probe);
if (err)
return err;
--
2.47.3