Setting /proc/sys/vm/drop_caches to clear cache
As part of doing some cold cache timings, I'm trying to free the OS cache. The kernel documentation (retrieved January 2019) says:
drop_caches
Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.
This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...) These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.
Use of this file can cause performance problems. Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use. Because of this,
use outside of a testing or debugging environment is not recommended.
You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3
These are informational only. They do not mean that anything is wrong
with your system. To disable them, echo 4 (bit 3) into drop_caches.
I'm a bit sketchy about the details. Running
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. Ok.
So, if I want the system to start caching normally again, do I need to reset it to 0 first? My system has the value currently set to 0, which I assume is the default. Or will it reset on its own? I see at least two possibilities here, and I'm not sure which one is true:
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. The system then immediately starts caching again. I'm not sure what I would expect the value in/proc/sys/vm/drop_caches
to do if this is the case. Go back to 0 almost immediately?If
/proc/sys/vm/drop_caches
is set to 3, the system does not do any memory caching till it is reset to 0.
Which case is true?
linux virtual-memory
add a comment |
As part of doing some cold cache timings, I'm trying to free the OS cache. The kernel documentation (retrieved January 2019) says:
drop_caches
Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.
This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...) These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.
Use of this file can cause performance problems. Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use. Because of this,
use outside of a testing or debugging environment is not recommended.
You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3
These are informational only. They do not mean that anything is wrong
with your system. To disable them, echo 4 (bit 3) into drop_caches.
I'm a bit sketchy about the details. Running
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. Ok.
So, if I want the system to start caching normally again, do I need to reset it to 0 first? My system has the value currently set to 0, which I assume is the default. Or will it reset on its own? I see at least two possibilities here, and I'm not sure which one is true:
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. The system then immediately starts caching again. I'm not sure what I would expect the value in/proc/sys/vm/drop_caches
to do if this is the case. Go back to 0 almost immediately?If
/proc/sys/vm/drop_caches
is set to 3, the system does not do any memory caching till it is reset to 0.
Which case is true?
linux virtual-memory
20
To use it with sudo:echo 3 | sudo tee /proc/sys/vm/drop_caches
– Volker Siegel
Aug 3 '14 at 22:40
Holy cow! @VolkerSiegel I've been scrubbing the Interwebs for hours and randomly found your comment. Tried it and it worked perfectly! Thanks for adding this little trick. I don't want to hijack this question but if it's not inappropriate, I'd like to ask for explanation. When I use sshpass withsudo -i && echo 3 > /proc/sys/vm/drop_caches
, I get an error:stdin: is not a tty
. Using your "sudo" method works. Why?
– harperville
Feb 26 '16 at 15:57
2
@harperville Ask a question; this is almost certainly an unrelated issue.
– Faheem Mitha
Feb 26 '16 at 16:36
1
@harperville Yes - that is a very good question - with an interesting answer, Do ask it separately! Then let me know here. Or you want me to ask the question myself and then answer it?
– Volker Siegel
Feb 26 '16 at 16:57
add a comment |
As part of doing some cold cache timings, I'm trying to free the OS cache. The kernel documentation (retrieved January 2019) says:
drop_caches
Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.
This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...) These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.
Use of this file can cause performance problems. Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use. Because of this,
use outside of a testing or debugging environment is not recommended.
You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3
These are informational only. They do not mean that anything is wrong
with your system. To disable them, echo 4 (bit 3) into drop_caches.
I'm a bit sketchy about the details. Running
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. Ok.
So, if I want the system to start caching normally again, do I need to reset it to 0 first? My system has the value currently set to 0, which I assume is the default. Or will it reset on its own? I see at least two possibilities here, and I'm not sure which one is true:
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. The system then immediately starts caching again. I'm not sure what I would expect the value in/proc/sys/vm/drop_caches
to do if this is the case. Go back to 0 almost immediately?If
/proc/sys/vm/drop_caches
is set to 3, the system does not do any memory caching till it is reset to 0.
Which case is true?
linux virtual-memory
As part of doing some cold cache timings, I'm trying to free the OS cache. The kernel documentation (retrieved January 2019) says:
drop_caches
Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches
This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.
This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...) These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.
Use of this file can cause performance problems. Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use. Because of this,
use outside of a testing or debugging environment is not recommended.
You may see informational messages in your kernel log when this file is
used:
cat (1234): drop_caches: 3
These are informational only. They do not mean that anything is wrong
with your system. To disable them, echo 4 (bit 3) into drop_caches.
I'm a bit sketchy about the details. Running
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. Ok.
So, if I want the system to start caching normally again, do I need to reset it to 0 first? My system has the value currently set to 0, which I assume is the default. Or will it reset on its own? I see at least two possibilities here, and I'm not sure which one is true:
echo 3 > /proc/sys/vm/drop_caches
frees pagecache, dentries and inodes. The system then immediately starts caching again. I'm not sure what I would expect the value in/proc/sys/vm/drop_caches
to do if this is the case. Go back to 0 almost immediately?If
/proc/sys/vm/drop_caches
is set to 3, the system does not do any memory caching till it is reset to 0.
Which case is true?
linux virtual-memory
linux virtual-memory
edited Jan 27 at 3:25
Isaac
11.8k11752
11.8k11752
asked Aug 3 '11 at 5:53
Faheem MithaFaheem Mitha
23k1880135
23k1880135
20
To use it with sudo:echo 3 | sudo tee /proc/sys/vm/drop_caches
– Volker Siegel
Aug 3 '14 at 22:40
Holy cow! @VolkerSiegel I've been scrubbing the Interwebs for hours and randomly found your comment. Tried it and it worked perfectly! Thanks for adding this little trick. I don't want to hijack this question but if it's not inappropriate, I'd like to ask for explanation. When I use sshpass withsudo -i && echo 3 > /proc/sys/vm/drop_caches
, I get an error:stdin: is not a tty
. Using your "sudo" method works. Why?
– harperville
Feb 26 '16 at 15:57
2
@harperville Ask a question; this is almost certainly an unrelated issue.
– Faheem Mitha
Feb 26 '16 at 16:36
1
@harperville Yes - that is a very good question - with an interesting answer, Do ask it separately! Then let me know here. Or you want me to ask the question myself and then answer it?
– Volker Siegel
Feb 26 '16 at 16:57
add a comment |
20
To use it with sudo:echo 3 | sudo tee /proc/sys/vm/drop_caches
– Volker Siegel
Aug 3 '14 at 22:40
Holy cow! @VolkerSiegel I've been scrubbing the Interwebs for hours and randomly found your comment. Tried it and it worked perfectly! Thanks for adding this little trick. I don't want to hijack this question but if it's not inappropriate, I'd like to ask for explanation. When I use sshpass withsudo -i && echo 3 > /proc/sys/vm/drop_caches
, I get an error:stdin: is not a tty
. Using your "sudo" method works. Why?
– harperville
Feb 26 '16 at 15:57
2
@harperville Ask a question; this is almost certainly an unrelated issue.
– Faheem Mitha
Feb 26 '16 at 16:36
1
@harperville Yes - that is a very good question - with an interesting answer, Do ask it separately! Then let me know here. Or you want me to ask the question myself and then answer it?
– Volker Siegel
Feb 26 '16 at 16:57
20
20
To use it with sudo:
echo 3 | sudo tee /proc/sys/vm/drop_caches
– Volker Siegel
Aug 3 '14 at 22:40
To use it with sudo:
echo 3 | sudo tee /proc/sys/vm/drop_caches
– Volker Siegel
Aug 3 '14 at 22:40
Holy cow! @VolkerSiegel I've been scrubbing the Interwebs for hours and randomly found your comment. Tried it and it worked perfectly! Thanks for adding this little trick. I don't want to hijack this question but if it's not inappropriate, I'd like to ask for explanation. When I use sshpass with
sudo -i && echo 3 > /proc/sys/vm/drop_caches
, I get an error: stdin: is not a tty
. Using your "sudo" method works. Why?– harperville
Feb 26 '16 at 15:57
Holy cow! @VolkerSiegel I've been scrubbing the Interwebs for hours and randomly found your comment. Tried it and it worked perfectly! Thanks for adding this little trick. I don't want to hijack this question but if it's not inappropriate, I'd like to ask for explanation. When I use sshpass with
sudo -i && echo 3 > /proc/sys/vm/drop_caches
, I get an error: stdin: is not a tty
. Using your "sudo" method works. Why?– harperville
Feb 26 '16 at 15:57
2
2
@harperville Ask a question; this is almost certainly an unrelated issue.
– Faheem Mitha
Feb 26 '16 at 16:36
@harperville Ask a question; this is almost certainly an unrelated issue.
– Faheem Mitha
Feb 26 '16 at 16:36
1
1
@harperville Yes - that is a very good question - with an interesting answer, Do ask it separately! Then let me know here. Or you want me to ask the question myself and then answer it?
– Volker Siegel
Feb 26 '16 at 16:57
@harperville Yes - that is a very good question - with an interesting answer, Do ask it separately! Then let me know here. Or you want me to ask the question myself and then answer it?
– Volker Siegel
Feb 26 '16 at 16:57
add a comment |
1 Answer
1
active
oldest
votes
It isn't sticky - you just write to the file to make it drop the caches and then it immediately starts caching again.
Basically when you write to that file you aren't really changing a setting, you are issuing a command to the kernel. The kernel acts on that command (by dropping the caches) then carries on as before.
2
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
30
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is infs/drop_caches.c
.
– Gilles
Aug 4 '11 at 0:16
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
2
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17936%2fsetting-proc-sys-vm-drop-caches-to-clear-cache%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It isn't sticky - you just write to the file to make it drop the caches and then it immediately starts caching again.
Basically when you write to that file you aren't really changing a setting, you are issuing a command to the kernel. The kernel acts on that command (by dropping the caches) then carries on as before.
2
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
30
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is infs/drop_caches.c
.
– Gilles
Aug 4 '11 at 0:16
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
2
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
add a comment |
It isn't sticky - you just write to the file to make it drop the caches and then it immediately starts caching again.
Basically when you write to that file you aren't really changing a setting, you are issuing a command to the kernel. The kernel acts on that command (by dropping the caches) then carries on as before.
2
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
30
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is infs/drop_caches.c
.
– Gilles
Aug 4 '11 at 0:16
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
2
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
add a comment |
It isn't sticky - you just write to the file to make it drop the caches and then it immediately starts caching again.
Basically when you write to that file you aren't really changing a setting, you are issuing a command to the kernel. The kernel acts on that command (by dropping the caches) then carries on as before.
It isn't sticky - you just write to the file to make it drop the caches and then it immediately starts caching again.
Basically when you write to that file you aren't really changing a setting, you are issuing a command to the kernel. The kernel acts on that command (by dropping the caches) then carries on as before.
edited Aug 3 '11 at 8:53
answered Aug 3 '11 at 8:28
TomHTomH
2,332118
2,332118
2
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
30
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is infs/drop_caches.c
.
– Gilles
Aug 4 '11 at 0:16
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
2
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
add a comment |
2
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
30
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is infs/drop_caches.c
.
– Gilles
Aug 4 '11 at 0:16
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
2
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
2
2
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
Ok, thanks. Does the value immediately change back to 0?
– Faheem Mitha
Aug 3 '11 at 8:49
30
30
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is in
fs/drop_caches.c
.– Gilles
Aug 4 '11 at 0:16
@FaheemMitha No, the value you can read is whatever you put last, but it's not used anywhere, only the action of writing matters. The source code is in
fs/drop_caches.c
.– Gilles
Aug 4 '11 at 0:16
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
Is there a specific benefit for the JVM by doing this?
– J E Carter II
Dec 21 '16 at 21:31
2
2
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
There are no benefits for applications, on the contrary: files will load slower because no cached inodes. Also, you are not low on memory: if an app needs memory it will take it from the OS cache. See linuxatemyram.com.
– dr0i
Jun 12 '18 at 9:47
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f17936%2fsetting-proc-sys-vm-drop-caches-to-clear-cache%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
20
To use it with sudo:
echo 3 | sudo tee /proc/sys/vm/drop_caches
– Volker Siegel
Aug 3 '14 at 22:40
Holy cow! @VolkerSiegel I've been scrubbing the Interwebs for hours and randomly found your comment. Tried it and it worked perfectly! Thanks for adding this little trick. I don't want to hijack this question but if it's not inappropriate, I'd like to ask for explanation. When I use sshpass with
sudo -i && echo 3 > /proc/sys/vm/drop_caches
, I get an error:stdin: is not a tty
. Using your "sudo" method works. Why?– harperville
Feb 26 '16 at 15:57
2
@harperville Ask a question; this is almost certainly an unrelated issue.
– Faheem Mitha
Feb 26 '16 at 16:36
1
@harperville Yes - that is a very good question - with an interesting answer, Do ask it separately! Then let me know here. Or you want me to ask the question myself and then answer it?
– Volker Siegel
Feb 26 '16 at 16:57