Droping caches in Linux for fun & profit

Linux caches some stuff in RAM that is not used by any process at the moment. That is meant to be helpful. But I noticed that for some reason when a lot of stuff is cached computer becomes noticeable slower than when caches are empty (e.g. right after the boot). So here is how to drop caches.

To free pagecache:

sync; echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

sync; echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

sync; echo 3 > /proc/sys/vm/drop_caches

You have to sync because otherwise dirty object will not be freed.

This should work with kernel 2.6.16 and newer.

Fri, 28 Aug, 2009, 19:44
Tags: