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>
} 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) {
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,
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);
- }
}
/*
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)
.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,
damon_stop(&ctx, 1);
damon_destroy_ctx(ctx);
}
- if (target_pidp)
- put_pid(target_pidp);
}
static bool init_called;
damon_stop(&ctx, 1);
damon_destroy_ctx(ctx);
}
- if (target_pidp)
- put_pid(target_pidp);
}
static bool init_called;