Advertisements
According to the linux documentations, the variable drop_caches defined as, 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.
So the command to drop all caches are,
#sync; echo 3 > /proc/sys/vm/drop_caches
Or you can specify this in /etc/sysctl.conf
#echo "vm.drop_caches = 3" >> /etc/sysctl.conf
Now reload sysctl.conf
#sysctl -p
Not 100% sure about this, but your "Also the entry for sysctl.conf so that it will remember the action." sentence is not clear, or could be wrong, depending on what do you mean by it.
ReplyDeleteRemember the action could mean that the kernel will disable caching of pages, dentries and inodes, but AFAIK it will only 'remember' to execute the command once after each boot.
Some people recomend setting vm.drop_caches=3 in sysctl.conf in order for cache to be rebuilt with something more useful than stuff which got there during boot process.