Tuesday, February 15, 2011

Clear memory caches on Linux

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


sync should be run because this is a non-destructive operation, and dirty objects are not freeable. So you run sync in order to make sure all cached objects are freed.

No comments: