Free Linux Memory by Dropping Caches

Linux Kernels 2.6.16 and up provide a way to instruct the kernel to drop the page cache, inode and dentry caches on command. This tip can help free Linux memory without a reboot.

Note: This is a non-destructive operation. Dirty objects are not freeable, hence; you must run sync beforehand.

To use /proc/sys/vm/drop_caches, you simply echo a number to it.

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