public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: damon@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org, sj@kernel.org, akinobu.mita@gmail.com
Subject: [RFC PATCH v2 1/6] mm/damon: reintroduce damon_operations->cleanup()
Date: Mon,  9 Mar 2026 10:00:04 +0900	[thread overview]
Message-ID: <20260309010009.11639-2-akinobu.mita@gmail.com> (raw)
In-Reply-To: <20260309010009.11639-1-akinobu.mita@gmail.com>

Commit 50962b16c0d6 ("mm/damon: remove damon_operations->cleanup()")
removed damon_operations->cleanup(). However in order to support perf
event based access checks for physical and virtual address space
monitoring, damon_operations->cleanup() is required to release
perf events created by damon_operations->init().
---
 include/linux/damon.h | 3 +++
 mm/damon/core.c       | 2 ++
 mm/damon/paddr.c      | 1 +
 mm/damon/vaddr.c      | 1 +
 4 files changed, 7 insertions(+)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index a4fea23da857..49d2983af4a8 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -607,6 +607,7 @@ enum damon_ops_id {
  * @apply_scheme:		Apply a DAMON-based operation scheme.
  * @target_valid:		Determine if the target is valid.
  * @cleanup_target:		Clean up each target before deallocation.
+ * @cleanup:			Clean up the context.
  *
  * DAMON can be extended for various address spaces and usages.  For this,
  * users should register the low level operations for their target address
@@ -639,6 +640,7 @@ enum damon_ops_id {
  * @target_valid should check whether the target is still valid for the
  * monitoring.
  * @cleanup_target is called before the target will be deallocated.
+ * @cleanup is called from @kdamond just before its termination.
  */
 struct damon_operations {
 	enum damon_ops_id id;
@@ -654,6 +656,7 @@ struct damon_operations {
 			struct damos *scheme, unsigned long *sz_filter_passed);
 	bool (*target_valid)(struct damon_target *t);
 	void (*cleanup_target)(struct damon_target *t);
+	void (*cleanup)(struct damon_ctx *context);
 };
 
 /*
diff --git a/mm/damon/core.c b/mm/damon/core.c
index adfc52fee9dc..d0d9659658bd 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2841,6 +2841,8 @@ static int kdamond_fn(void *data)
 done:
 	damon_destroy_targets(ctx);
 
+	if (ctx->ops.cleanup)
+		ctx->ops.cleanup(ctx);
 	kfree(ctx->regions_score_histogram);
 	kdamond_call(ctx, true);
 	damos_walk_cancel(ctx);
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 9bfe48826840..4c2c935d82d6 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -373,6 +373,7 @@ static int __init damon_pa_initcall(void)
 		.prepare_access_checks = damon_pa_prepare_access_checks,
 		.check_accesses = damon_pa_check_accesses,
 		.target_valid = NULL,
+		.cleanup = NULL,
 		.apply_scheme = damon_pa_apply_scheme,
 		.get_scheme_score = damon_pa_scheme_score,
 	};
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index 729b7ffd3565..8a58aa912112 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -1013,6 +1013,7 @@ static int __init damon_va_initcall(void)
 		.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,
 	};
-- 
2.43.0


  reply	other threads:[~2026-03-09  1:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-09  1:00 [RFC PATCH v2 0/6] mm/damon: introduce perf event based access check Akinobu Mita
2026-03-09  1:00 ` Akinobu Mita [this message]
2026-03-09  1:00 ` [RFC PATCH v2 2/6] mm/damon/core: introduce struct damon_access_report Akinobu Mita
2026-03-09 15:19   ` Ian Rogers
2026-03-10  1:23     ` SeongJae Park
2026-03-09  1:00 ` [RFC PATCH v2 3/6] mm/damon/core: add common code for perf event based access check Akinobu Mita
2026-03-09  1:00 ` [RFC PATCH v2 4/6] mm/damon/vaddr: support " Akinobu Mita
2026-03-09  1:00 ` [RFC PATCH v2 5/6] mm/damon/paddr: " Akinobu Mita
2026-03-09  1:00 ` [RFC PATCH v2 6/6] mm/damon: allow user to set min size of region Akinobu Mita
2026-03-11  0:51 ` [RFC PATCH v2 0/6] mm/damon: introduce perf event based access check SeongJae Park
2026-03-13  7:35   ` Akinobu Mita
2026-03-14  1:31     ` SeongJae Park
2026-03-16  4:42       ` Akinobu Mita

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=20260309010009.11639-2-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=damon@lists.linux.dev \
    --cc=linux-perf-users@vger.kernel.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