From: Asier Gutierrez 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 Suggested-by: SeongJae Park --- 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