As part of doing some cold cache timings, I'm trying to free the OS cache. The kernel documentation says:
drop_caches
Writing to this will cause the kernel to drop clean caches, dentries and
inodes from memory, causing that memory to become free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation and dirty objects are not freeable, the
user should run `sync' first.
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_cachesfrees 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_cachesto do if this is the case. Go back to 0 almost immediately?If
/proc/sys/vm/drop_cachesis set to 3, the system does not do any memory caching till it is reset to 0.
Which case is true?
echo 3 | sudo tee /proc/sys/vm/drop_caches– Volker Siegel Aug 3 '14 at 22:40sudo -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