From 99b4cdcce43ad0f706120bef26fef8c628c572cf Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 23 Jan 2017 15:03:52 -0800 Subject: [PATCH 151/154] mm: Export do_madvise() Combined with some interesting flags madvise() system call allows to free memory more smartly and more efficiently than we could do with a simple free(). The issue is that is not available for kernel modules that could need it. In order to solve this lack of support, this patch exports do_madvise() so as to make it available to the entire kernel. The already existing madvise() system call is unchanged and now relies on this new do_madvise() function. Suggested-by: Arjan van de Ven Signed-off-by: Sebastien Boeuf --- include/linux/mm.h | 2 ++ mm/madvise.c | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0b5b2e4df14e..925ec25f99a8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2450,5 +2450,7 @@ void __init setup_nr_node_ids(void); static inline void setup_nr_node_ids(void) {} #endif +extern int do_madvise(unsigned long start, size_t len_in, int behavior); + #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */ diff --git a/mm/madvise.c b/mm/madvise.c index 93fb63e88b5e..c8bbf93d4978 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -618,9 +618,7 @@ madvise_behavior_valid(int behavior) } /* - * The madvise(2) system call. - * - * Applications can use madvise() to advise the kernel how it should + * Kernel modules can use do_madvise() to advise the kernel how it should * handle paging I/O in this VM area. The idea is to help the kernel * use appropriate read-ahead and caching techniques. The information * provided is advisory only, and can be safely disregarded by the @@ -673,7 +671,7 @@ madvise_behavior_valid(int behavior) * -EBADF - map exists, but area maps something that isn't a file. * -EAGAIN - a kernel resource was temporarily unavailable. */ -SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) +int do_madvise(unsigned long start, size_t len_in, int behavior) { unsigned long end, tmp; struct vm_area_struct *vma, *prev; @@ -767,3 +765,22 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) return error; } +EXPORT_SYMBOL_GPL(do_madvise); + +/* + * The madvise(2) system call. + * + * Applications can use madvise() system call to advise the kernel how + * it should handle paging I/O in this VM area. The idea is to help + * the kernel use appropriate read-ahead and caching techniques. The + * information provided is advisory only, and can be safely disregarded + * by the kernel without affecting the correct operation of the application. + * + * behavior values are the same than the ones defined in madvise() + * + * return values are the same than the ones defined in madvise() + */ +SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) +{ + return do_madvise(start, len_in, behavior); +} -- 2.12.1