How To: Clear cache from your RAM

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

How To: Clear cache from your RAM

Postby jampola on 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! :)
jampola
Level 1
Level 1
 
Posts: 6
Joined: Sat Nov 26, 2011 8:18 am

Linux Mint is funded by ads and donations.
 

Re: How To: Clear cache from your RAM

Postby DrHu on 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.
User avatar
DrHu
Level 16
Level 16
 
Posts: 6292
Joined: Wed Jun 17, 2009 8:20 pm

Re: How To: Clear cache from your RAM

Postby ChickenPie4Tea on 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"
ChickenPie4Tea
Level 3
Level 3
 
Posts: 109
Joined: Sun Jan 22, 2012 6:44 pm


Return to Tutorials / Howtos

Who is online

Users browsing this forum: austin.texas and 11 guests