Linux: How to clear the cache from memory

Red Hat Enterprise Linux 4.6 and 5.0 introduced /proc/sys/vm/drop_caches, which allows the pagecache and slabcache to be cleared on demand.

To free the 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

It is recommended that sync be run prior to passing the values to /proc/sys/vm/drop_caches. Enabling drop_caches can cause deadlock if the system is under heavy memory and I/O load. It is not recommended to use this feature on system experiencing heavy load.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.