]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/damon/vaddr: put pid in cleanup_target()
authorSeongJae Park <sj@kernel.org>
Sat, 12 Jul 2025 19:50:12 +0000 (12:50 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 20 Jul 2025 01:59:56 +0000 (18:59 -0700)
Implement cleanup_target() callback for [f]vaddr, which calls put_pid()
for each target that will be destroyed.  Also remove redundant put_pid()
calls in core, sysfs and sample modules, which were required to be done
redundantly due to the lack of such self cleanup in vaddr.

Link: https://lkml.kernel.org/r/20250712195016.151108-11-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/core.c
mm/damon/sysfs.c
mm/damon/vaddr.c
samples/damon/prcl.c
samples/damon/wsse.c

index 678c9b4e038cd69e79f176984a4ebbe68bfe608b..9554743dc992b5cd8f7fa755db967da9e4aa5ef3 100644 (file)
@@ -1139,8 +1139,6 @@ static int damon_commit_targets(
                } else {
                        struct damos *s;
 
-                       if (damon_target_has_pid(dst))
-                               put_pid(dst_target->pid);
                        damon_destroy_target(dst_target, dst);
                        damon_for_each_scheme(s, dst) {
                                if (s->quota.charge_target_from == dst_target) {
index f2f9f756f5a2bf69f9a4212d3ab0aec7a5cf0988..5eba6ac53939994b9375f1b2805e03fecb6c18f0 100644 (file)
@@ -1298,13 +1298,9 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ctx,
 static void damon_sysfs_destroy_targets(struct damon_ctx *ctx)
 {
        struct damon_target *t, *next;
-       bool has_pid = damon_target_has_pid(ctx);
 
-       damon_for_each_target_safe(t, next, ctx) {
-               if (has_pid)
-                       put_pid(t->pid);
+       damon_for_each_target_safe(t, next, ctx)
                damon_destroy_target(t, ctx);
-       }
 }
 
 static int damon_sysfs_set_regions(struct damon_target *t,
@@ -1387,10 +1383,8 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx)
        if (!damon_target_has_pid(ctx))
                return;
 
-       damon_for_each_target_safe(t, next, ctx) {
-               put_pid(t->pid);
+       damon_for_each_target_safe(t, next, ctx)
                damon_destroy_target(t, ctx);
-       }
 }
 
 /*
index 7f5dc9c221a045b0416759f86db80d1b248add39..94af19c4dfedc15471f152d29e0a2eb3c540f566 100644 (file)
@@ -805,6 +805,11 @@ static bool damon_va_target_valid(struct damon_target *t)
        return false;
 }
 
+static void damon_va_cleanup_target(struct damon_target *t)
+{
+       put_pid(t->pid);
+}
+
 #ifndef CONFIG_ADVISE_SYSCALLS
 static unsigned long damos_madvise(struct damon_target *target,
                struct damon_region *r, int behavior)
@@ -946,6 +951,7 @@ static int __init damon_va_initcall(void)
                .prepare_access_checks = damon_va_prepare_access_checks,
                .check_accesses = damon_va_check_accesses,
                .target_valid = damon_va_target_valid,
+               .cleanup_target = damon_va_cleanup_target,
                .cleanup = NULL,
                .apply_scheme = damon_va_apply_scheme,
                .get_scheme_score = damon_va_scheme_score,
index 25a751a67b2d46fec6921ef5cf273b8d052dffb5..1b839c06a612f2d91ad0f8da78a8c19e40a02616 100644 (file)
@@ -120,8 +120,6 @@ static void damon_sample_prcl_stop(void)
                damon_stop(&ctx, 1);
                damon_destroy_ctx(ctx);
        }
-       if (target_pidp)
-               put_pid(target_pidp);
 }
 
 static bool init_called;
index a250e86b24a552ffb6d93a067d90fb0bc1e42a1f..da052023b099071bddc6ce76bbef74abfd2b46ab 100644 (file)
@@ -100,8 +100,6 @@ static void damon_sample_wsse_stop(void)
                damon_stop(&ctx, 1);
                damon_destroy_ctx(ctx);
        }
-       if (target_pidp)
-               put_pid(target_pidp);
 }
 
 static bool init_called;