How To: Clear cache from your RAM

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
jampola
Level 1
Level 1
Posts: 6
Joined: Sat Nov 26, 2011 8:18 am

How To: Clear cache from your RAM

Postby jampola » Sat Dec 17, 2011 4:50 pm

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-admin-made-easy/using-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! :)

User avatar
DrHu
Level 17
Level 17
Posts: 7561
Joined: Wed Jun 17, 2009 8:20 pm

Re: How To: Clear cache from your RAM

Postby DrHu » Sat Dec 17, 2011 5:02 pm

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.

ChickenPie4Tea

Re: How To: Clear cache from your RAM

Postby ChickenPie4Tea » Sat Mar 03, 2012 10:52 am

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"

tone303
Level 2
Level 2
Posts: 52
Joined: Sun Apr 19, 2015 10:19 pm

Re: How To: Clear cache from your RAM

Postby tone303 » Fri May 01, 2015 9:18 pm

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?

tone303
Level 2
Level 2
Posts: 52
Joined: Sun Apr 19, 2015 10:19 pm

Re: How To: Clear cache from your RAM

Postby tone303 » Fri May 01, 2015 9:20 pm

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


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests