summaryrefslogtreecommitdiffstats
path: root/patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch
diff options
context:
space:
mode:
authorAdrian Calianu <adrian.calianu@enea.com>2021-05-11 09:42:24 +0200
committerAdrian Calianu <Adrian.Calianu@enea.com>2021-05-12 21:56:14 +0100
commitc6e89e8a31eeeb82c5711cba8235e7e55d9be6a8 (patch)
tree93a3d96c027a437fc9b168d07ab2ad62248d77d1 /patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch
parent7a93e54032bb148a92e16b59736a1b76fedae319 (diff)
downloadenea-kernel-cache-c6e89e8a31eeeb82c5711cba8235e7e55d9be6a8.tar.gz
boot_time_opt: update patches to 5.10 kernel
Patches used in boot time optimization are coming from clearlinux distribution. Update patches correspuding to 5.10 kernel: https://github.com/clearlinux-pkgs/linux/tree/5.10.32-1034 We selected a list of patches from ClearLinux. Those we have considered risky, unknown impact on functionality have been avoided. Change-Id: If01459292a5a383b49944645bd8536d9a62d9de3 Signed-off-by: Adrian Calianu <adrian.calianu@enea.com>
Diffstat (limited to 'patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch')
-rw-r--r--patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch137
1 files changed, 0 insertions, 137 deletions
diff --git a/patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch b/patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch
deleted file mode 100644
index 64021c6..0000000
--- a/patches/boot_time_opt/0154-sysctl-vm-Fine-grained-cache-shrinking.patch
+++ /dev/null
@@ -1,137 +0,0 @@
1From 130d5d976b920aec243e0fa63273f3143660054b Mon Sep 17 00:00:00 2001
2From: Sebastien Boeuf <sebastien.boeuf@intel.com>
3Date: Mon, 23 Jan 2017 15:32:39 -0800
4Subject: [PATCH 154/154] sysctl: vm: Fine-grained cache shrinking
5
6Lots of virtual machines are let in idle state for days until they
7are terminated, and they can keep a large amount of memory in their
8cache, meaning this memory cannot be used by other processes.
9
10We tried to release this memory using existing drop_caches sysctl,
11but it led to the complete cache loss while it could have been used
12whether the idle process wakes up. Indeed, the process can't find any
13available cached data and it directly affects performances to rebuild
14it from scratch.
15
16Instead, the solution we want is based on shrinking gradually system
17cache over time. This patch adds a new sysctl shrink_caches_mb so as
18to allow userspace applications indicating the kernel it should shrink
19system cache up to the amount (in MiB) specified.
20
21There is an application called "memshrinker" which uses this new
22mechanism. It runs in the background and periodically releases a
23specified amount of cache. This amount is based on the remaining
24cache on the system, and period is computed to follow a shrinking
25model. It results in saving a lot of memory for other processes
26running on the system.
27
28Suggested-by: Arjan van de Ven <arjan.van.de.ven@intel.com>
29Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
30---
31 fs/drop_caches.c | 25 +++++++++++++++++++++++++
32 include/linux/mm.h | 4 ++++
33 kernel/sysctl.c | 8 ++++++++
34 mm/vmscan.c | 2 --
35 4 files changed, 37 insertions(+), 2 deletions(-)
36
37diff --git a/fs/drop_caches.c b/fs/drop_caches.c
38index 82377017130f..f8de1383498b 100644
39--- a/fs/drop_caches.c
40+++ b/fs/drop_caches.c
41@@ -9,10 +9,12 @@
42 #include <linux/writeback.h>
43 #include <linux/sysctl.h>
44 #include <linux/gfp.h>
45+#include <linux/swap.h>
46 #include "internal.h"
47
48 /* A global variable is a bit ugly, but it keeps the code simple */
49 int sysctl_drop_caches;
50+int sysctl_shrink_caches_mb;
51
52 static void drop_pagecache_sb(struct super_block *sb, void *unused)
53 {
54@@ -68,3 +70,26 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
55 }
56 return 0;
57 }
58+
59+int shrink_caches_sysctl_handler(struct ctl_table *table, int write,
60+ void __user *buffer, size_t *length, loff_t *ppos)
61+{
62+ int ret;
63+ unsigned long nr_to_reclaim, page_reclaimed;
64+
65+ ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
66+ if (ret)
67+ return ret;
68+
69+ nr_to_reclaim = sysctl_shrink_caches_mb * (1 << 20) / PAGE_SIZE;
70+ if (write) {
71+ page_reclaimed = shrink_all_memory(nr_to_reclaim);
72+ if (page_reclaimed > 0)
73+ lru_add_drain_all();
74+
75+ if (page_reclaimed != nr_to_reclaim)
76+ return page_reclaimed;
77+ }
78+
79+ return 0;
80+}
81diff --git a/include/linux/mm.h b/include/linux/mm.h
82index 15e02bf3a6b3..9f9b967ad2c9 100644
83--- a/include/linux/mm.h
84+++ b/include/linux/mm.h
85@@ -2457,6 +2457,10 @@ extern int kvm_ret_mem_advice;
86 int kvm_madv_instant_free_sysctl_handler(struct ctl_table *table, int write,
87 void __user *buffer, size_t *length,
88 loff_t *ppos);
89+extern int sysctl_shrink_caches_mb;
90+int shrink_caches_sysctl_handler(struct ctl_table *table, int write,
91+ void __user *buffer, size_t *length,
92+ loff_t *ppos);
93 #endif
94
95 void drop_slab(void);
96diff --git a/kernel/sysctl.c b/kernel/sysctl.c
97index 9a1611f92a2a..9b74b4f0251d 100644
98--- a/kernel/sysctl.c
99+++ b/kernel/sysctl.c
100@@ -1417,6 +1417,14 @@ static struct ctl_table vm_table[] = {
101 .mode = 0644,
102 .proc_handler = kvm_madv_instant_free_sysctl_handler,
103 },
104+ {
105+ .procname = "shrink_caches_mb",
106+ .data = &sysctl_shrink_caches_mb,
107+ .maxlen = sizeof(int),
108+ .mode = 0644,
109+ .proc_handler = shrink_caches_sysctl_handler,
110+ .extra1 = &one,
111+ },
112 #ifdef CONFIG_COMPACTION
113 {
114 .procname = "compact_memory",
115diff --git a/mm/vmscan.c b/mm/vmscan.c
116index eb2f0315b8c0..b16f327b0211 100644
117--- a/mm/vmscan.c
118+++ b/mm/vmscan.c
119@@ -3646,7 +3646,6 @@ void wakeup_kswapd(struct zone *zone, int order, enum zone_type classzone_idx)
120 wake_up_interruptible(&pgdat->kswapd_wait);
121 }
122
123-#ifdef CONFIG_HIBERNATION
124 /*
125 * Try to free `nr_to_reclaim' of memory, system-wide, and return the number of
126 * freed pages.
127@@ -3686,7 +3685,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
128
129 return nr_reclaimed;
130 }
131-#endif /* CONFIG_HIBERNATION */
132
133 /* It's optimal to keep kswapds on the same CPUs as their memory, but
134 not required for correctness. So if the last cpu in a node goes
135--
1362.15.0
137