linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: delete damon_target when detected invalid
@ 2025-12-09  5:57 Enze Li
  2025-12-09  7:21 ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Enze Li @ 2025-12-09  5:57 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 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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-09 10:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09  5:57 [PATCH] mm/damon/core: delete damon_target when detected invalid Enze Li
2025-12-09  7:21 ` SeongJae Park
2025-12-09  9:24   ` Enze Li
2025-12-09 10:49     ` 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).