* [PATCH] mm/damon/core: fix wasteful CPU calls by skipping non-existent targets
@ 2025-12-10 5:25 Enze Li
2025-12-10 9:15 ` SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: Enze Li @ 2025-12-10 5:25 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, enze.li, Enze Li
Currently, DAMON does not proactively clean up invalid monitoring
targets during its runtime. When some monitored processes exit, DAMON
continues to make the following unnecessary function calls,
--damon_for_each_target--
--damon_for_each_region--
damon_do_apply_schemes
damos_apply_scheme
damon_va_apply_scheme
damos_madvise
damon_get_mm
it is only in the damon_get_mm() function that it may finally discover
the target no longer exists, which wastes CPU resources. A simple idea
is to check for the existence of monitoring targets within the
kdamond_need_stop() function and promptly clean up non-existent targets.
However, SJ pointed out that this approach is problematic because the
online commit logic incorrectly uses list indices to update the
monitoring state. This can lead to data loss if the target list is
changed concurrently. Meanwhile, SJ suggests checking for target
existence at the damon_for_each_target level, and if a target does not
exist, simply skip it and proceed to the next one.
Suggested-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Enze Li <lienze@kylinos.cn>
---
mm/damon/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index f9fc0375890a..e43bdf0b41a8 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2266,6 +2266,9 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
mutex_lock(&c->walk_control_lock);
damon_for_each_target(t, c) {
+ if (c->ops.target_valid && c->ops.target_valid(t) == false)
+ continue;
+
damon_for_each_region_safe(r, next_r, t)
damon_do_apply_schemes(c, t, r);
}
base-commit: c9b47175e9131118e6f221cc8fb81397d62e7c91
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/damon/core: fix wasteful CPU calls by skipping non-existent targets
2025-12-10 5:25 [PATCH] mm/damon/core: fix wasteful CPU calls by skipping non-existent targets Enze Li
@ 2025-12-10 9:15 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2025-12-10 9:15 UTC (permalink / raw)
To: Enze Li; +Cc: SeongJae Park, akpm, damon, linux-mm, enze.li
On Wed, 10 Dec 2025 13:25:08 +0800 Enze Li <lienze@kylinos.cn> wrote:
> Currently, DAMON does not proactively clean up invalid monitoring
> targets during its runtime. When some monitored processes exit, DAMON
> continues to make the following unnecessary function calls,
>
> --damon_for_each_target--
> --damon_for_each_region--
> damon_do_apply_schemes
> damos_apply_scheme
> damon_va_apply_scheme
> damos_madvise
> damon_get_mm
>
> it is only in the damon_get_mm() function that it may finally discover
> the target no longer exists, which wastes CPU resources. A simple idea
> is to check for the existence of monitoring targets within the
> kdamond_need_stop() function and promptly clean up non-existent targets.
>
> However, SJ pointed out that this approach is problematic because the
> online commit logic incorrectly uses list indices to update the
> monitoring state. This can lead to data loss if the target list is
> changed concurrently. Meanwhile, SJ suggests checking for target
> existence at the damon_for_each_target level, and if a target does not
> exist, simply skip it and proceed to the next one.
Thank you for making this patch, Enze!
>
> Suggested-by: SeongJae Park <sj@kernel.org>
> Signed-off-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: SeongJae Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-10 9:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 5:25 [PATCH] mm/damon/core: fix wasteful CPU calls by skipping non-existent targets Enze Li
2025-12-10 9:15 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).