How to Clear RAM Memory Cache, Buffer and Swap Space on Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

91 Responses

  1. Witold says:

    What is this with echo? echo “echo 3 > /proc/sys/vm/drop_caches“. You should just use echo 3 > /proc/sys/vm/drop_caches, or echo 3 | sudo tee /proc/sys/vm/drop_caches.

    The remark that ‘3’ should not be used in production systems is ridiculous and invalid. It is fully supported and stable for decades. drop_caches is usually only useful when doing benchmarks and timing tests of file systems and block devices, or network attached storage or file systems. You shouldn’t use any drop_cache in the first place in any real production system. It is only for testing and debugging.

  2. Zeki Basbuyuk says:

    It may be necessary to go back to normal operation after this settings. See the following document from

    Returning system back to normal requires user to write “4” into drop_caches

    • Witold says:

      Zeki, no there is no need to write 4. Documentation says it clearly. 4 (bit 2), is only to disable the dmesg / kernel log messages when the drop_caches is issued. writing 1, 2 or 3 is one time thing, and immediately after (or even during) the page cache and other caches will start to be populated back according to system usage.

      I hardly see to ever need to use 4. It might be useful if you do it like every few minutes for some strange reasons, and want to avoid polluting the kernel log (dmesg) by spam of it. But it is just one line, and if you do it sporadically, there is zero reason to use 4.

  3. Steve Sybesma says:

    This is on a personal device that I’m only running one app on that’s not critical but want to make sure the performance is as good as it can be.

    The command to clear the caches doesn’t run until I add sudo. I get access denied without it. Would this be proper?

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

    • Ravi Saive says:


      Sometimes you need superuser privileges to run commands..Nothing to worry..

      • Steve Sybesma says:

        What I’m asking is WHERE I put the sudo command because it didn’t work in front of sync or echo and I didn’t realize drop-caches was an executable command that would respond to sudo. It seems to work there but I’m just making sure that’s a proper use of sudo in that syntax.

        • Steve Sybesma says:

          Actually found something that seems to work much better than what I last tried:

          sync; sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"

          The buff/cache column on free -h dropped from 340MB to 97MB and the free column went from 78MB to 217MB. Bigger difference than before.

  4. Makler says:

    su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root

    Is there a password for this after hitting enter ??? if not why does it ask me?

    and could this be applied for the home desktops too ???

  5. mainmeat says:

    You might want to correct

    swapoff -a && swapon -a


    sudo swapoff -a && sudo swapon -a
  6. Miphix says:

    When are we going to stop talking about cron, and start talking about systemd timers? It’s time, guys.

    • KPPL says:

      Well, not everybody is in love with systemd.

    • Yoandre Valdes Rodriguez says:

      If you are in love with systemd OK go ahead and use timers but don’t pretend that every body is agree with you.

      • Lucas Ramage says:

        Exactly! I literally went out of my way to comment specifically on this. Why does systemd even need a timer? It’s _supposed_ to be an init system.

    • TW says:

      When are we going to stop talking about systemd and move to openRC? It’s time, guys. Long, long past time in fact.

  7. karthik sailendra says:

    What is the tool you used to generate the Screenshot Gif

Got something to say? Join the discussion.

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

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