Clear RAM Memory Cache, Buffer and Swap Space on Linux

Have you ever have any process is eating away your memory and you want to clear it, Linux provides a way to flush or clear ram cache.

How to Clear Cache in Linux?

Every Linux System has three options to clear cache without interrupting any processes or services.

Clear PageCache only.

sync; echo 1 > /proc/sys/vm/drop_caches

Clear dentries and inodes.

sync; echo 2 > /proc/sys/vm/drop_caches

Clear PageCache, dentries and inodes.

sync; echo 3 > /proc/sys/vm/drop_caches

Explanation of Command

sync will flush the file system buffer. Command Separated by “;” run sequentially. The shell wait for each command to terminate before executing the next command in the sequence. As mentioned in kernel documentation, writing to drop_cache will clean cache without killing any application/service, command echo is doing the job of writing to file.

How to Clear Swap Space in Linux?

If you want to clear Swap space, you may like to run the below command.

swapoff -a && swapon -a

Share this to your friends if you found this article is useful.

Source from

4 replies
  1. steve reith
    steve reith says:

    Her is an example using free to see before and after results

    free && sync && echo 3 > /proc/sys/vm/drop_caches && free


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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