From: Enze Li <lienze@kylinos.cn>
To: sj@kernel.org, akpm@linux-foundation.org
Cc: damon@lists.linux.dev, linux-mm@kvack.org, enze.li@gmx.com,
Enze Li <lienze@kylinos.cn>
Subject: [PATCH] mm/damon/core: delete damon_target when detected invalid
Date: Tue, 9 Dec 2025 13:57:13 +0800 [thread overview]
Message-ID: <20251209055713.270737-1-lienze@kylinos.cn> (raw)
Currently, DAMON does not proactively clean up invalid monitoring
targets during its runtime. When some monitored targets exit, DAMON
still makes 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
and it is only in the damon_get_mm() that it may finally discover that
the monitoring target no longer exists.
To avoid wasting CPU resources, this patch modifies the
kdamond_need_stop() logic to proactively clean up monitoring targets
when they are found to be invalid.
Signed-off-by: Enze Li <lienze@kylinos.cn>
---
mm/damon/core.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index f9fc0375890a..eb5612bfd6bf 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2462,7 +2462,8 @@ static void kdamond_split_regions(struct damon_ctx *ctx)
*/
static bool kdamond_need_stop(struct damon_ctx *ctx)
{
- struct damon_target *t;
+ struct damon_target *t, *next;
+ bool valid_target_exist = false;
if (kthread_should_stop())
return true;
@@ -2470,11 +2471,16 @@ static bool kdamond_need_stop(struct damon_ctx *ctx)
if (!ctx->ops.target_valid)
return false;
- damon_for_each_target(t, ctx) {
+ damon_for_each_target_safe(t, next, ctx) {
if (ctx->ops.target_valid(t))
- return false;
+ valid_target_exist = true;
+ else
+ damon_destroy_target(t, ctx);
}
+ if (valid_target_exist)
+ return false;
+
return true;
}
--
2.52.0
next reply other threads:[~2025-12-09 5:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 5:57 Enze Li [this message]
2025-12-09 7:21 ` SeongJae Park
2025-12-09 9:24 ` Enze Li
2025-12-09 10:49 ` SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251209055713.270737-1-lienze@kylinos.cn \
--to=lienze@kylinos.cn \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=enze.li@gmx.com \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox