Skip to content

Commit 6dea8ad

Browse files
sjp38torvalds
authored andcommitted
mm/damon/vaddr: support DAMON-based Operation Schemes
This makes DAMON's default primitives for virtual address spaces to support DAMON-based Operation Schemes (DAMOS) by implementing actions application functions and registering it to the monitoring context. The implementation simply links 'madvise()' for related DAMOS actions. That is, 'madvise(MADV_WILLNEED)' is called for 'WILLNEED' DAMOS action and similar for other actions ('COLD', 'PAGEOUT', 'HUGEPAGE', 'NOHUGEPAGE'). So, the kernel space DAMON users can now use the DAMON-based optimizations with only small amount of code. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Amit Shah <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rienjes <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Leonard Foerster <[email protected]> Cc: Marco Elver <[email protected]> Cc: Markus Boehme <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1f366e4 commit 6dea8ad

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

include/linux/damon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ void damon_va_prepare_access_checks(struct damon_ctx *ctx);
337337
unsigned int damon_va_check_accesses(struct damon_ctx *ctx);
338338
bool damon_va_target_valid(void *t);
339339
void damon_va_cleanup(struct damon_ctx *ctx);
340+
int damon_va_apply_scheme(struct damon_ctx *context, struct damon_target *t,
341+
struct damon_region *r, struct damos *scheme);
340342
void damon_va_set_primitives(struct damon_ctx *ctx);
341343

342344
#endif /* CONFIG_DAMON_VADDR */

mm/damon/vaddr.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#define pr_fmt(fmt) "damon-va: " fmt
99

10+
#include <asm-generic/mman-common.h>
1011
#include <linux/damon.h>
1112
#include <linux/hugetlb.h>
1213
#include <linux/mm.h>
@@ -658,6 +659,60 @@ bool damon_va_target_valid(void *target)
658659
return false;
659660
}
660661

662+
#ifndef CONFIG_ADVISE_SYSCALLS
663+
static int damos_madvise(struct damon_target *target, struct damon_region *r,
664+
int behavior)
665+
{
666+
return -EINVAL;
667+
}
668+
#else
669+
static int damos_madvise(struct damon_target *target, struct damon_region *r,
670+
int behavior)
671+
{
672+
struct mm_struct *mm;
673+
int ret = -ENOMEM;
674+
675+
mm = damon_get_mm(target);
676+
if (!mm)
677+
goto out;
678+
679+
ret = do_madvise(mm, PAGE_ALIGN(r->ar.start),
680+
PAGE_ALIGN(r->ar.end - r->ar.start), behavior);
681+
mmput(mm);
682+
out:
683+
return ret;
684+
}
685+
#endif /* CONFIG_ADVISE_SYSCALLS */
686+
687+
int damon_va_apply_scheme(struct damon_ctx *ctx, struct damon_target *t,
688+
struct damon_region *r, struct damos *scheme)
689+
{
690+
int madv_action;
691+
692+
switch (scheme->action) {
693+
case DAMOS_WILLNEED:
694+
madv_action = MADV_WILLNEED;
695+
break;
696+
case DAMOS_COLD:
697+
madv_action = MADV_COLD;
698+
break;
699+
case DAMOS_PAGEOUT:
700+
madv_action = MADV_PAGEOUT;
701+
break;
702+
case DAMOS_HUGEPAGE:
703+
madv_action = MADV_HUGEPAGE;
704+
break;
705+
case DAMOS_NOHUGEPAGE:
706+
madv_action = MADV_NOHUGEPAGE;
707+
break;
708+
default:
709+
pr_warn("Wrong action %d\n", scheme->action);
710+
return -EINVAL;
711+
}
712+
713+
return damos_madvise(t, r, madv_action);
714+
}
715+
661716
void damon_va_set_primitives(struct damon_ctx *ctx)
662717
{
663718
ctx->primitive.init = damon_va_init;
@@ -667,6 +722,7 @@ void damon_va_set_primitives(struct damon_ctx *ctx)
667722
ctx->primitive.reset_aggregated = NULL;
668723
ctx->primitive.target_valid = damon_va_target_valid;
669724
ctx->primitive.cleanup = NULL;
725+
ctx->primitive.apply_scheme = damon_va_apply_scheme;
670726
}
671727

672728
#include "vaddr-test.h"

0 commit comments

Comments
 (0)