linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1 1/1] mm/damon: generalize ctx_target creation for damon_ops_id and add vaddr support
@ 2026-04-13 14:59 gutierrez.asier
  2026-04-14  0:47 ` SeongJae Park
  0 siblings, 1 reply; 3+ messages in thread
From: gutierrez.asier @ 2026-04-13 14:59 UTC (permalink / raw)
  To: gutierrez.asier, artem.kuzin, stepanov.anatoly, wangkefeng.wang,
	yanquanmin1, zuoze1, damon, sj, akpm, linux-mm, linux-kernel

From: Asier Gutierrez <gutierrez.asier@huawei-partners.com>

This patch adds a new function damon_modules_new_vaddr_ctx_target.
Since ctx_target creation for vaddr and paddr is almost identical,
the logic is extracted to a new function,
damon_modules_new_ctx_target, and vaddr and paddr functions are left
just as interfaces.

This change was suggested earlier[1] and it is needed to allow
developers to create DAMON modules that use DAMON_OPS_PADDR targets.

[1]: https://lore.kernel.org/damon/20260311005759.90440-1-sj@kernel.org/

Signed-off-by: Asier Gutierrez <gutierrez.asier@huawei-partners.com>
Suggested-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/modules-common.c | 31 +++++++++++++++++++++++++++----
 mm/damon/modules-common.h |  3 +++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/mm/damon/modules-common.c b/mm/damon/modules-common.c
index 86d58f8c4f63..fe12d109c87b 100644
--- a/mm/damon/modules-common.c
+++ b/mm/damon/modules-common.c
@@ -10,12 +10,13 @@
 #include "modules-common.h"
 
 /*
- * Allocate, set, and return a DAMON context for the physical address space.
+ * Allocate, set, and return a DAMON context.
  * @ctxp:	Pointer to save the point to the newly created context
  * @targetp:	Pointer to save the point to the newly created target
+ * @id:	Set of operations, physical or virtual
  */
-int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
-		struct damon_target **targetp)
+static int damon_modules_new_ctx_target(struct damon_ctx **ctxp,
+		struct damon_target **targetp, enum damon_ops_id id)
 {
 	struct damon_ctx *ctx;
 	struct damon_target *target;
@@ -24,7 +25,7 @@ int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
 	if (!ctx)
 		return -ENOMEM;
 
-	if (damon_select_ops(ctx, DAMON_OPS_PADDR)) {
+	if (damon_select_ops(ctx, id)) {
 		damon_destroy_ctx(ctx);
 		return -EINVAL;
 	}
@@ -40,3 +41,25 @@ int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
 	*targetp = target;
 	return 0;
 }
+
+/*
+ * Allocate, set, and return a DAMON context for the physical address space.
+ * @ctxp:	Pointer to save the point to the newly created context
+ * @targetp:	Pointer to save the point to the newly created target
+ */
+int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
+		struct damon_target **targetp)
+{
+	return damon_modules_new_ctx_target(ctxp, targetp, DAMON_OPS_PADDR);
+}
+
+/*
+ * Allocate, set, and return a DAMON context for the virtual address space.
+ * @ctxp:	Pointer to save the point to the newly created context
+ * @targetp:	Pointer to save the point to the newly created target
+ */
+int damon_modules_new_vaddr_ctx_target(struct damon_ctx **ctxp,
+		struct damon_target **targetp)
+{
+	return damon_modules_new_ctx_target(ctxp, targetp, DAMON_OPS_VADDR);
+}
diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h
index f103ad556368..324b9cb4957e 100644
--- a/mm/damon/modules-common.h
+++ b/mm/damon/modules-common.h
@@ -47,3 +47,6 @@
 
 int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
 		struct damon_target **targetp);
+
+int damon_modules_new_vaddr_ctx_target(struct damon_ctx **ctxp,
+		struct damon_target **targetp);
-- 
2.43.0



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

* Re: [RFC PATCH v1 1/1] mm/damon: generalize ctx_target creation for damon_ops_id and add vaddr support
  2026-04-13 14:59 [RFC PATCH v1 1/1] mm/damon: generalize ctx_target creation for damon_ops_id and add vaddr support gutierrez.asier
@ 2026-04-14  0:47 ` SeongJae Park
  2026-04-14 11:08   ` Gutierrez Asier
  0 siblings, 1 reply; 3+ messages in thread
From: SeongJae Park @ 2026-04-14  0:47 UTC (permalink / raw)
  To: gutierrez.asier
  Cc: SeongJae Park, artem.kuzin, stepanov.anatoly, wangkefeng.wang,
	yanquanmin1, zuoze1, damon, akpm, linux-mm, linux-kernel

On Mon, 13 Apr 2026 14:59:43 +0000 <gutierrez.asier@huawei-partners.com> wrote:

> From: Asier Gutierrez <gutierrez.asier@huawei-partners.com>
> 
> This patch adds a new function damon_modules_new_vaddr_ctx_target.
> Since ctx_target creation for vaddr and paddr is almost identical,
> the logic is extracted to a new function,
> damon_modules_new_ctx_target, and vaddr and paddr functions are left
> just as interfaces.
> 
> This change was suggested earlier[1] and it is needed to allow
> developers to create DAMON modules that use DAMON_OPS_PADDR targets.

You mean DAMON_OPS_VADDR?

And I agree this can be useful if we will make a DAMON module that runs for
virtual address spaces.  But we don't add new functions without their callers.
So this patch should be submitted only together with the caller of the
function.

> 
> [1]: https://lore.kernel.org/damon/20260311005759.90440-1-sj@kernel.org/


Thanks,
SJ

[...]


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

* Re: [RFC PATCH v1 1/1] mm/damon: generalize ctx_target creation for damon_ops_id and add vaddr support
  2026-04-14  0:47 ` SeongJae Park
@ 2026-04-14 11:08   ` Gutierrez Asier
  0 siblings, 0 replies; 3+ messages in thread
From: Gutierrez Asier @ 2026-04-14 11:08 UTC (permalink / raw)
  To: SeongJae Park
  Cc: artem.kuzin, stepanov.anatoly, wangkefeng.wang, yanquanmin1,
	zuoze1, damon, akpm, linux-mm, linux-kernel

Hi SJ,

On 4/14/2026 3:47 AM, SeongJae Park wrote:
> On Mon, 13 Apr 2026 14:59:43 +0000 <gutierrez.asier@huawei-partners.com> wrote:
> 
>> From: Asier Gutierrez <gutierrez.asier@huawei-partners.com>
>>
>> This patch adds a new function damon_modules_new_vaddr_ctx_target.
>> Since ctx_target creation for vaddr and paddr is almost identical,
>> the logic is extracted to a new function,
>> damon_modules_new_ctx_target, and vaddr and paddr functions are left
>> just as interfaces.
>>
>> This change was suggested earlier[1] and it is needed to allow
>> developers to create DAMON modules that use DAMON_OPS_PADDR targets.
> 
> You mean DAMON_OPS_VADDR?

Right, I missed that.
 
> And I agree this can be useful if we will make a DAMON module that runs for
> virtual address spaces.  But we don't add new functions without their callers.
> So this patch should be submitted only together with the caller of the
> function.

Fair enough. I will carry on working on the module for hugepages autotuning,
which will use this function. I will resubmit this along with the caller.

>>
>> [1]: https://lore.kernel.org/damon/20260311005759.90440-1-sj@kernel.org/
> 
> 
> Thanks,
> SJ
> 
> [...]

-- 
Asier Gutierrez
Huawei



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

end of thread, other threads:[~2026-04-14 11:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-13 14:59 [RFC PATCH v1 1/1] mm/damon: generalize ctx_target creation for damon_ops_id and add vaddr support gutierrez.asier
2026-04-14  0:47 ` SeongJae Park
2026-04-14 11:08   ` Gutierrez Asier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox