How to free Linux Cache

In one of our former post, we have a way to check what type of data is cached by our operating system. Is there a way for us to release memory from Linux like what we can do in Windows?

The answer is Yes, sure. Since linux-2.6.16, there’s a tunable file in /proc can be used, it’s /proc/sys/vm/drop_caches.
Writing to this file will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

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 in order to make sure all cached objects are freed.

Share this post

2 thoughts on “How to free Linux Cache

Post Comment