Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/core: cleanup targets and regions at once on kdamond termination

When kdamond terminates, it destroys the regions of the context first, and
the targets of the context just before the kdamond main function returns.
Because regions are linked inside targets, doing them separately is only
inefficient and looks weird. A more serious problem is that the cleanup
of the targets is done after damon_ctx->kdamond reset, which is the event
that lets DAMON API callers know the kdamond is no longer actively
running. That is, some DAMON targets could still exist while kdamond is
not running. There are no real problems from this, but this implicit fact
could cause subtle racy issues in future. Destroy targets and regions at
one.

Adding contexts on how the code has evolved in the way. Doing only
regions destruction was because putting pids of the targets were done on
DAMON API callers. Commit 7114bc5e01cf ("mm/damon/core: add
cleanup_target() ops callback") moved the role to be done via operations
set on each target destruction. Hence it removed the reason to do only
regions cleanup. Commit 3a69f1635769 ("mm/damon/core: destroy targets
when kdamond_fn() finish") therefore further destructed targets on kdamond
termination time. It was still separated from regions destruction because
damon_operations->cleanup() may do additional targets cleanup. Placing
the targets destruction after damon_ctx->kdamond reset was just an
unnecessary decision of the commit. The previous commit removed
damon_operations->cleanup(), so there is no more reason to do destructions
of regions and targets separately.

Link: https://lkml.kernel.org/r/20260117175256.82826-3-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
1736047a 50962b16

+1 -7
+1 -7
mm/damon/core.c
··· 2748 2748 static int kdamond_fn(void *data) 2749 2749 { 2750 2750 struct damon_ctx *ctx = data; 2751 - struct damon_target *t; 2752 - struct damon_region *r, *next; 2753 2751 unsigned int max_nr_accesses = 0; 2754 2752 unsigned long sz_limit = 0; 2755 2753 ··· 2852 2854 } 2853 2855 } 2854 2856 done: 2855 - damon_for_each_target(t, ctx) { 2856 - damon_for_each_region_safe(r, next, t) 2857 - damon_destroy_region(r, t); 2858 - } 2857 + damon_destroy_targets(ctx); 2859 2858 2860 2859 kfree(ctx->regions_score_histogram); 2861 2860 kdamond_call(ctx, true); ··· 2870 2875 running_exclusive_ctxs = false; 2871 2876 mutex_unlock(&damon_lock); 2872 2877 2873 - damon_destroy_targets(ctx); 2874 2878 return 0; 2875 2879 } 2876 2880