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 earlier1 and it is needed to allow developers to create DAMON modules that use DAMON_OPS_VADDR targets. Signed-off-by: Asier Gutierrez Suggested-by: SeongJae Park --- mm/damon/modules-common.c | 33 +++++++++++++++++++++++++-------- mm/damon/modules-common.h | 3 +++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/mm/damon/modules-common.c b/mm/damon/modules-common.c index 86d58f8c4f63..35a4a89b6caa 100644 --- a/mm/damon/modules-common.c +++ b/mm/damon/modules-common.c @@ -9,13 +9,8 @@ #include "modules-common.h" -/* - * 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) +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 +19,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 +35,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