How to Clear Linux Memory Cache

Need to clear cached memory for testing/troubleshooting purposes?

The following command clears both directory entry caches (dentries) and inode caches:

echo 1 > /proc/sys/vm/drop_caches && echo 2 > /proc/sys/vm/drop_caches

What Does This Command Do?

The command executes two cache-clearing operations:

echo 1 > /proc/sys/vm/drop_caches

This clears the page cache, which stores file data in memory to improve disk read performance.

echo 2 > /proc/sys/vm/drop_caches

This clears dentries and inode caches, which Linux uses to quickly locate files and directories.

A Simpler Alternative

Instead of running two separate commands, you can clear both types of caches at the same time:

echo 3 > /proc/sys/vm/drop_caches

This way you can free all reclaimable caches in one go!

0 Comments