aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hansen <dave@linux.vnet.ibm.com>2014-04-03 17:48:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-03 19:21:04 -0400
commit5509a5d27b971a90b940e148ca9ca53312e4fa7a (patch)
treea05845240563a79deafc3350e6409c6b3058e0f2
parent67f9fd91f93c582b7de2ab9325b6e179db77e4d5 (diff)
drop_caches: add some documentation and info message
There is plenty of anecdotal evidence and a load of blog posts suggesting that using "drop_caches" periodically keeps your system running in "tip top shape". Perhaps adding some kernel documentation will increase the amount of accurate data on its use. If we are not shrinking caches effectively, then we have real bugs. Using drop_caches will simply mask the bugs and make them harder to find, but certainly does not fix them, nor is it an appropriate "workaround" to limit the size of the caches. On the contrary, there have been bug reports on issues that turned out to be misguided use of cache dropping. Dropping caches is a very drastic and disruptive operation that is good for debugging and running tests, but if it creates bug reports from production use, kernel developers should be aware of its use. Add a bit more documentation about it, a syslog message to track down abusers, and vmstat drop counters to help analyze problem reports. [akpm@linux-foundation.org: checkpatch fixes] [hannes@cmpxchg.org: add runtime suppression control] Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Michal Hocko <mhocko@suse.cz> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/sysctl/vm.txt33
-rw-r--r--fs/drop_caches.c16
-rw-r--r--include/linux/vm_event_item.h1
-rw-r--r--kernel/sysctl.c4
-rw-r--r--mm/vmstat.c3
5 files changed, 47 insertions, 10 deletions
diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt
index d614a9b6a280..dd9d0e33b443 100644
--- a/Documentation/sysctl/vm.txt
+++ b/Documentation/sysctl/vm.txt
@@ -175,18 +175,39 @@ Setting this to zero disables periodic writeback altogether.
175 175
176drop_caches 176drop_caches
177 177
178Writing to this will cause the kernel to drop clean caches, dentries and 178Writing to this will cause the kernel to drop clean caches, as well as
179inodes from memory, causing that memory to become free. 179reclaimable slab objects like dentries and inodes. Once dropped, their
180memory becomes free.
180 181
181To free pagecache: 182To free pagecache:
182 echo 1 > /proc/sys/vm/drop_caches 183 echo 1 > /proc/sys/vm/drop_caches
183To free dentries and inodes: 184To free reclaimable slab objects (includes dentries and inodes):
184 echo 2 > /proc/sys/vm/drop_caches 185 echo 2 > /proc/sys/vm/drop_caches
185To free pagecache, dentries and inodes: 186To free slab objects and pagecache:
186 echo 3 > /proc/sys/vm/drop_caches 187 echo 3 > /proc/sys/vm/drop_caches
187 188
188As this is a non-destructive operation and dirty objects are not freeable, the 189This is a non-destructive operation and will not free any dirty objects.
189user should run `sync' first. 190To increase the number of objects freed by this operation, the user may run
191`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
192number of dirty objects on the system and create more candidates to be
193dropped.
194
195This file is not a means to control the growth of the various kernel caches
196(inodes, dentries, pagecache, etc...) These objects are automatically
197reclaimed by the kernel when memory is needed elsewhere on the system.
198
199Use of this file can cause performance problems. Since it discards cached
200objects, it may cost a significant amount of I/O and CPU to recreate the
201dropped objects, especially if they were under heavy use. Because of this,
202use outside of a testing or debugging environment is not recommended.
203
204You may see informational messages in your kernel log when this file is
205used:
206
207 cat (1234): drop_caches: 3
208
209These are informational only. They do not mean that anything is wrong
210with your system. To disable them, echo 4 (bit 3) into drop_caches.
190 211
191============================================================== 212==============================================================
192 213
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index 9fd702f5bfb2..9280202e488c 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -59,10 +59,22 @@ int drop_caches_sysctl_handler(ctl_table *table, int write,
59 if (ret) 59 if (ret)
60 return ret; 60 return ret;
61 if (write) { 61 if (write) {
62 if (sysctl_drop_caches & 1) 62 static int stfu;
63
64 if (sysctl_drop_caches & 1) {
63 iterate_supers(drop_pagecache_sb, NULL); 65 iterate_supers(drop_pagecache_sb, NULL);
64 if (sysctl_drop_caches & 2) 66 count_vm_event(DROP_PAGECACHE);
67 }
68 if (sysctl_drop_caches & 2) {
65 drop_slab(); 69 drop_slab();
70 count_vm_event(DROP_SLAB);
71 }
72 if (!stfu) {
73 pr_info("%s (%d): drop_caches: %d\n",
74 current->comm, task_pid_nr(current),
75 sysctl_drop_caches);
76 }
77 stfu |= sysctl_drop_caches & 4;
66 } 78 }
67 return 0; 79 return 0;
68} 80}
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 3a712e2e7d76..486c3972c0be 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -37,6 +37,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
37 PGINODESTEAL, SLABS_SCANNED, KSWAPD_INODESTEAL, 37 PGINODESTEAL, SLABS_SCANNED, KSWAPD_INODESTEAL,
38 KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY, 38 KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY,
39 PAGEOUTRUN, ALLOCSTALL, PGROTATED, 39 PAGEOUTRUN, ALLOCSTALL, PGROTATED,
40 DROP_PAGECACHE, DROP_SLAB,
40#ifdef CONFIG_NUMA_BALANCING 41#ifdef CONFIG_NUMA_BALANCING
41 NUMA_PTE_UPDATES, 42 NUMA_PTE_UPDATES,
42 NUMA_HUGE_PTE_UPDATES, 43 NUMA_HUGE_PTE_UPDATES,
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 09d2e2413605..5c14b547882e 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -123,7 +123,7 @@ static int __maybe_unused neg_one = -1;
123static int zero; 123static int zero;
124static int __maybe_unused one = 1; 124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2; 125static int __maybe_unused two = 2;
126static int __maybe_unused three = 3; 126static int __maybe_unused four = 4;
127static unsigned long one_ul = 1; 127static unsigned long one_ul = 1;
128static int one_hundred = 100; 128static int one_hundred = 100;
129#ifdef CONFIG_PRINTK 129#ifdef CONFIG_PRINTK
@@ -1264,7 +1264,7 @@ static struct ctl_table vm_table[] = {
1264 .mode = 0644, 1264 .mode = 0644,
1265 .proc_handler = drop_caches_sysctl_handler, 1265 .proc_handler = drop_caches_sysctl_handler,
1266 .extra1 = &one, 1266 .extra1 = &one,
1267 .extra2 = &three, 1267 .extra2 = &four,
1268 }, 1268 },
1269#ifdef CONFIG_COMPACTION 1269#ifdef CONFIG_COMPACTION
1270 { 1270 {
diff --git a/mm/vmstat.c b/mm/vmstat.c
index f3155d51acfd..197b4c4a9587 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -813,6 +813,9 @@ const char * const vmstat_text[] = {
813 813
814 "pgrotated", 814 "pgrotated",
815 815
816 "drop_pagecache",
817 "drop_slab",
818
816#ifdef CONFIG_NUMA_BALANCING 819#ifdef CONFIG_NUMA_BALANCING
817 "numa_pte_updates", 820 "numa_pte_updates",
818 "numa_huge_pte_updates", 821 "numa_huge_pte_updates",