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

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. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  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...

34 Responses

  1. prashant says:

    Hey I have working servers on VM’s but after some days it got slow. So I have to reboot every 7 days or whenever we face error..

    There is no user login after 11-am so can I use eco 3? with ram and swap clearing on and off ?

    • Ravi Saive says:

      @Prashant,

      Yes, you can use echo 3 command to clear your RAM cache and buffer to free up some space to function server properly..

      • prashant says:

        @Ravi
        i tried and checked and worked fine echo but some VMs start using Swap memory i.e “swapoff -a && swapon -a” gave some error regarding volume group.

        I will post that when i will get same error and any way thanks cause mainly i use echo 1 but still i need some vms to restart.

        lets see if this echo 3 can fix that issue

  2. mssupport says:

    This is not working fine for us. So could you provide some alternate for this.

  3. Ole Tange says:

    When you would use this:

    When measuring performance it can be important to do that in a reproducible way. Caches can often mess up these results.

    So one of the situations where you would drop all caches, is if you have more ways to do the same thing, and are trying to figure out which way is the fastest:

    echo 3 | sudo tee /proc/sys/vm/drop_caches
    time do_the_thing version1
    echo 3 | sudo tee /proc/sys/vm/drop_caches
    time do_the_thing version2
    
  4. Gonzalo Oviedo Lambert says:

    Very clear explanation. Thank you.

  5. Bee Kay says:

    Oh, that was fun. I like getting 10GB of RAM back in one command…!

  6. Pavel Pulec says:

    Are you sure that it can corrupt the database? I think that database can be pretty slow but no file should be corrupted.

  7. Viril Calimlim says:

    Hi Avishek,

    Great article. Just a little correction maybe on the crontab entry. Is it really 2pm? Cheers! :)

Got something to say? Join the discussion.

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

Join Over 300K+ Linux Users
  1. 202,035
  2. 9,267
  3. 38,621

Are you subscribed?