Friday, 24 July 2009

Dropping the page and/or inode Cache on Linux

Sometimes I want to run some I/O benchmarks but I don't want cached data from previous test runs to interfere with subsequent tests. Fortunately Linux provides a mechanism to drop cached data as follows (run the commands as root):

Freeing the page cache:

# echo 1 > /proc/sys/vm/drop_caches

Free dentries and inodes:

# echo 2 > /proc/sys/vm/drop_caches

Free the page cache, dentries and the inodes:

# echo 3 > /proc/sys/vm/drop_caches

The notes I've read on this seem to indicate that one should always run sync before doing this; quote "this is a non-destructive operation and dirty objects are not freeable, so the user should run sync(8) first." So now you know!

No comments:

Post a comment