Note: You are viewing an old version of this page. View the current version.

WARNING

When using VMware with a 'physical' device, modifications to that device's filesysteems may not be noticed immediately, even when unmounted! VMware uses Linux' buffer cache to store this data, and modifying the physical device outside of VMware requires you to manually flush the buffer cache, or else stale data will be noticed, and may cause filesystem corruption!


Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache...

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

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!

bin/dropcache:

#!/bin/sh

exec sudo /bin/sh -c 'sync; sync; sync; sync; echo 3 > /proc/sys/vm/drop_caches'