Page 1 of 1

How To: Clear cache from your RAM

Posted: Sat Dec 17, 2011 4:50 pm
by jampola
So, Gnome Shell being Gnome Shell, I notice it likes to eat up a lot of RAM with it's cache. Cache is a great thing until it doesn't make way for more useful things.

Whilst I should make you aware that it's not necessarily a bad thing (since when something NEEDS to use the ram, it should clear the old Cache out) It sometimes doesn't work that way.

An dead easily solution is to clear up some data from your ram is to use an old and trusted command I use to clear my servers RAM after an mysql dump.

Code: Select all

sudo sync; echo 3 > /proc/sys/vm/drop_caches
And if you're like me and you leave your machine on for quite a number of days at a time, it might be best to add a cron job to take care of it daily. If you're not sure what cron is, take a quick read here http://tldp.org/LDP/lame/LAME/linux-adm ... -cron.html

And here is a little before and after as an example:

Code: Select all

             total       used       free     shared    buffers     cached
Mem:          7908       --->6288<---       1619          0        206       4859
-/+ buffers/cache:       1222       6686
Swap:         8096          0       8096
And after!

Code: Select all

             total       used       free     shared    buffers     cached
Mem:          7908       --->1689<---      6218          0          2        469
-/+ buffers/cache:       1218       6689
Swap:         8096          0       8096
Hopefully this helps you guys out. If you have any questions, post them below! :)

Re: How To: Clear cache from your RAM

Posted: Sat Dec 17, 2011 5:02 pm
by DrHu
http://www.thehosthelpers.com/general-c ... -is-weird/
  • Last post Joey

    Code: Select all

    it was indeed an authorization error.
    After lots of googling I finally found this:
    sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"
    sudo sh -c "echo 2 > /proc/sys/vm/drop_caches"
    sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
    which works like a charm.
A little bit of explanation..
http://www.go2linux.org/linux/2011/01/h ... memory-880
--why you might want to use 1,2,3 or 0 for buffer cache clearing, but if you decide you need to use this command, then echo 3 is the most complete clearing switch to use..

Basically with enough RAM for your standard method of operation, neither swap activity (if any) nor cache should really affect the operation of the OS in any significant way..

On some Linux systems I did tend to use the sync command when logging out to make sure the system flushed the buffers and that I had a clean logout.

Re: How To: Clear cache from your RAM

Posted: Sat Mar 03, 2012 10:52 am
by ChickenPie4Tea
I typed in your command and then my passowrd and just got
"bash: /proc/sys/vm/drop_caches: Permission denied"
but following the second post this was not denied
sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

Re: How To: Clear cache from your RAM

Posted: Fri May 01, 2015 9:18 pm
by tone303
None of these commands work to drop the cache like they do in ubuntu

some are bash: permission denied

others dont deny permission yet simply dont work either, and turn terminal into just a ">" with no path.

This includes even sudo sh -c "echo 1 > /proc/sys/vm/drop_caches" which an above poster claims works
I have system monitor right here, doesnt work. On ubuntu you can see the cache drop in system monitor when these are used.

ideas?

Re: How To: Clear cache from your RAM

Posted: Fri May 01, 2015 9:20 pm
by tone303
Nevermind, i found the one that works in Linux Mint 17.1

It is

Code: Select all

sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Re: How To: Clear cache from your RAM

Posted: Wed Nov 15, 2017 11:00 pm
by JAnthony419
This worked like a charm for me. Now its time to build the cron rule to complete this daily for me.

Thanks
DrHu wrote:http://www.thehosthelpers.com/general-c ... -is-weird/
  • Last post Joey

    Code: Select all

    it was indeed an authorization error.
    After lots of googling I finally found this:
    sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"
    sudo sh -c "echo 2 > /proc/sys/vm/drop_caches"
    sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
    which works like a charm.
A little bit of explanation..
http://www.go2linux.org/linux/2011/01/h ... memory-880
--why you might want to use 1,2,3 or 0 for buffer cache clearing, but if you decide you need to use this command, then echo 3 is the most complete clearing switch to use..

Basically with enough RAM for your standard method of operation, neither swap activity (if any) nor cache should really affect the operation of the OS in any significant way..

On some Linux systems I did tend to use the sync command when logging out to make sure the system flushed the buffers and that I had a clean logout.

Re: How To: Clear cache from your RAM

Posted: Thu Nov 16, 2017 3:43 am
by Moem
And now it's time to close this thread, since it's old as dirt and should be resting in peace. Please do not revive such old threads; it's called necroposting and we don't do it here. Threads about older versions bring too much confusion.