Skip to contentSkip to conversation

Make /proc/sys/vm/drop_caches write only

PATCH In review Nikanth Karthikesan 2 participants 3 messages Nov 13, 2008 – Nov 17, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make /proc/sys/vm/drop_caches write only

/proc/sys/vm/drop_caches is used only to trigger dropping caches. It does not
disable the cache. The ability to read the value written to this file long back gives wrong impression.

---

fs/drop_caches.c +4 -6
index 3e5637f..9892e1b 100644
@@ -66,11 +66,9 @@ int drop_caches_sysctl_handler(ctl_table *table, int write,
 	struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
 {
 	proc_dointvec_minmax(table, write, file, buffer, length, ppos);
-	if (write) {
-		if (sysctl_drop_caches & 1)
-			drop_pagecache();
-		if (sysctl_drop_caches & 2)
-			drop_slab();
-	}
+	if (sysctl_drop_caches & 1)
+		drop_pagecache();
+	if (sysctl_drop_caches & 2)
+		drop_slab();
 	return 0;
 }
kernel/sysctl.c +1 -1
index 9d048fa..dff3c13 100644
@@ -1015,7 +1015,7 @@ static struct ctl_table vm_table[] = {
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
 		.maxlen		= sizeof(int),
-		.mode		= 0644,
+		.mode		= 0200,
 		.proc_handler	= drop_caches_sysctl_handler,
 		.strategy	= &sysctl_intvec,
 	},
#1 lore raw
Quoted 33 lines · On Thu, 13 Nov 2008 17:54:11 +0530 Nikanth Karthikesan <[email protected]> wrote:

/proc/sys/vm/drop_caches is used only to trigger dropping caches. It does not
disable the cache. The ability to read the value written to this file long back gives wrong impression.

---

fs/drop_caches.c +4 -6
index 3e5637f..9892e1b 100644
@@ -66,11 +66,9 @@ int drop_caches_sysctl_handler(ctl_table *table, int write,
 	struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
 {
 	proc_dointvec_minmax(table, write, file, buffer, length, ppos);
-	if (write) {
-		if (sysctl_drop_caches & 1)
-			drop_pagecache();
-		if (sysctl_drop_caches & 2)
-			drop_slab();
-	}
+	if (sysctl_drop_caches & 1)
+		drop_pagecache();
+	if (sysctl_drop_caches & 2)
+		drop_slab();
 	return 0;
 }
kernel/sysctl.c +0 -0
index 9d048fa..dff3c13 100644

kernel/sysctl.c static struct ctl_table vm_table[] = { · line 1021

Quoted 8 lines
kernel/sysctl.c +1 -1
@@ -1015,7 +1015,7 @@ static struct ctl_table vm_table[] = {
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
 		.maxlen		= sizeof(int),
-		.mode		= 0644,
+		.mode		= 0200,
 		.proc_handler	= drop_caches_sysctl_handler,
 		.strategy	= &sysctl_intvec,
 	},

True. But it's a backward-incompatible change, and there's a (small) chance that someone's tools will break if we do this.

We have to get these things right first time :(

#2 lore raw
Quoted 48 lines · On Saturday 15 November 2008 04:37:05 Andrew Morton wrote:

On Thu, 13 Nov 2008 17:54:11 +0530

Quoted 33 lines · Nikanth Karthikesan

/proc/sys/vm/drop_caches is used only to trigger dropping caches. It
does not disable the cache. The ability to read the value written to this file long back gives wrong impression.

---

fs/drop_caches.c +0 -0
index 3e5637f..9892e1b 100644
@@ -66,11 +66,9 @@ int drop_caches_sysctl_handler(ctl_table *table, int

write, struct file *file, void __user *buffer, size_t *length, loff_t *ppos) {

fs/drop_caches.c +4 -6
 	proc_dointvec_minmax(table, write, file, buffer, length, ppos);
-	if (write) {
-		if (sysctl_drop_caches & 1)
-			drop_pagecache();
-		if (sysctl_drop_caches & 2)
-			drop_slab();
-	}
+	if (sysctl_drop_caches & 1)
+		drop_pagecache();
+	if (sysctl_drop_caches & 2)
+		drop_slab();
 	return 0;
 }
kernel/sysctl.c +0 -0
index 9d048fa..dff3c13 100644

kernel/sysctl.c static struct ctl_table vm_table[] = { · line 1021

Quoted 8 lines
kernel/sysctl.c +1 -1
@@ -1015,7 +1015,7 @@ static struct ctl_table vm_table[] = {
 		.procname	= "drop_caches",
 		.data		= &sysctl_drop_caches,
 		.maxlen		= sizeof(int),
-		.mode		= 0644,
+		.mode		= 0200,
 		.proc_handler	= drop_caches_sysctl_handler,
 		.strategy	= &sysctl_intvec,
 	},

True. But it's a backward-incompatible change, and there's a (small) chance that someone's tools will break if we do this.

Quoted 1 line

We have to get these things right first time :(

hmm.. add this to the list of things for the big version change ;)

May be zeroing out the value would have slimmer chance of breaking things?! Or would it cause a different confusion?

Thanks
Nikanth Karthikesan

/proc/sys/vm/drop_caches is used only to trigger dropping caches. It does not disable the cache. Unset it after clearing the cache.

---

fs/drop_caches.c +1 -0
index 3e5637f..1a03d6e 100644
@@ -71,6 +71,7 @@ int drop_caches_sysctl_handler(ctl_table *table, int write,
 			drop_pagecache();
 		if (sysctl_drop_caches & 2)
 			drop_slab();
+		sysctl_drop_caches = 0;
 	}
 	return 0;
 }