blob: 483e1ed812b625901515f2903de3f0817b3c8dde [file] [log] [blame]
From 6f969d5c5893c4c92900dadf7709878c51300212 Mon Sep 17 00:00:00 2001
From: Johannes Weiner <>
Date: Sat, 30 Nov 2019 17:56:08 -0800
Subject: [PATCH] kernel: sysctl: make drop_caches write-only
commit 204cb79ad42f015312a5bbd7012d09c93d9b46fb upstream.
Currently, the drop_caches proc file and sysctl read back the last value
written, suggesting this is somehow a stateful setting instead of a
one-time command. Make it write-only, like e.g. compact_memory.
While mitigating a VM problem at scale in our fleet, there was confusion
about whether writing to this file will permanently switch the kernel into
a non-caching mode. This influences the decision making in a tense
situation, where tens of people are trying to fix tens of thousands of
affected machines: Do we need a rollback strategy? What are the
performance implications of operating in a non-caching state for several
days? It also caused confusion when the kernel team said we may need to
write the file several times to make sure it's effective ("But it already
reads back 3?").
Signed-off-by: Johannes Weiner <>
Acked-by: Chris Down <>
Acked-by: Vlastimil Babka <>
Acked-by: David Hildenbrand <>
Acked-by: Michal Hocko <>
Acked-by: Alexey Dobriyan <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
Signed-off-by: Paul Gortmaker <>
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 1beca96fb625..952fc547ea50 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1452,7 +1452,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,
.extra1 = &one,
.extra2 = &four,