]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/damon/vaddr: support DAMON-based Operation Schemes
authorSeongJae Park <sj@kernel.org>
Fri, 5 Nov 2021 20:46:25 +0000 (13:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 6 Nov 2021 20:30:44 +0000 (13:30 -0700)
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/20211001125604.29660-4-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Amit Shah <amit@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rienjes <rientjes@google.com>
Cc: David Woodhouse <dwmw@amazon.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Leonard Foerster <foersleo@amazon.de>
Cc: Marco Elver <elver@google.com>
Cc: Markus Boehme <markubo@amazon.de>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/damon.h
mm/damon/vaddr.c

index dbe18b0fb795c4a1908f287bd9754c63ce4e0212..be6b6e81e8ee1ca4dbf8ec26e0fe8ff0b5ef9397 100644 (file)
@@ -337,6 +337,8 @@ void damon_va_prepare_access_checks(struct damon_ctx *ctx);
 unsigned int damon_va_check_accesses(struct damon_ctx *ctx);
 bool damon_va_target_valid(void *t);
 void damon_va_cleanup(struct damon_ctx *ctx);
+int damon_va_apply_scheme(struct damon_ctx *context, struct damon_target *t,
+               struct damon_region *r, struct damos *scheme);
 void damon_va_set_primitives(struct damon_ctx *ctx);
 
 #endif /* CONFIG_DAMON_VADDR */
index 58c1fb2aafa91fcf410df608927e7b67c8f6a3e8..3e1c74d36bab7558d6fe13e70fdfbc279e948703 100644 (file)
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt) "damon-va: " fmt
 
+#include <asm-generic/mman-common.h>
 #include <linux/damon.h>
 #include <linux/hugetlb.h>
 #include <linux/mm.h>
@@ -658,6 +659,60 @@ bool damon_va_target_valid(void *target)
        return false;
 }
 
+#ifndef CONFIG_ADVISE_SYSCALLS
+static int damos_madvise(struct damon_target *target, struct damon_region *r,
+                       int behavior)
+{
+       return -EINVAL;
+}
+#else
+static int damos_madvise(struct damon_target *target, struct damon_region *r,
+                       int behavior)
+{
+       struct mm_struct *mm;
+       int ret = -ENOMEM;
+
+       mm = damon_get_mm(target);
+       if (!mm)
+               goto out;
+
+       ret = do_madvise(mm, PAGE_ALIGN(r->ar.start),
+                       PAGE_ALIGN(r->ar.end - r->ar.start), behavior);
+       mmput(mm);
+out:
+       return ret;
+}
+#endif /* CONFIG_ADVISE_SYSCALLS */
+
+int damon_va_apply_scheme(struct damon_ctx *ctx, struct damon_target *t,
+               struct damon_region *r, struct damos *scheme)
+{
+       int madv_action;
+
+       switch (scheme->action) {
+       case DAMOS_WILLNEED:
+               madv_action = MADV_WILLNEED;
+               break;
+       case DAMOS_COLD:
+               madv_action = MADV_COLD;
+               break;
+       case DAMOS_PAGEOUT:
+               madv_action = MADV_PAGEOUT;
+               break;
+       case DAMOS_HUGEPAGE:
+               madv_action = MADV_HUGEPAGE;
+               break;
+       case DAMOS_NOHUGEPAGE:
+               madv_action = MADV_NOHUGEPAGE;
+               break;
+       default:
+               pr_warn("Wrong action %d\n", scheme->action);
+               return -EINVAL;
+       }
+
+       return damos_madvise(t, r, madv_action);
+}
+
 void damon_va_set_primitives(struct damon_ctx *ctx)
 {
        ctx->primitive.init = damon_va_init;
@@ -667,6 +722,7 @@ void damon_va_set_primitives(struct damon_ctx *ctx)
        ctx->primitive.reset_aggregated = NULL;
        ctx->primitive.target_valid = damon_va_target_valid;
        ctx->primitive.cleanup = NULL;
+       ctx->primitive.apply_scheme = damon_va_apply_scheme;
 }
 
 #include "vaddr-test.h"