summaryrefslogtreecommitdiffstats
path: root/patches/boot_time_opt_guest/0151-mm-Export-do_madvise.patch
blob: a6dbff722769979452ae5f28a44cc7e1399ecab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From 99b4cdcce43ad0f706120bef26fef8c628c572cf Mon Sep 17 00:00:00 2001
From: Sebastien Boeuf <sebastien.boeuf@intel.com>
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 <arjan.van.de.ven@intel.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
---
 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