How To: Clear cache from your RAM

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Locked
jampola

How To: Clear cache from your RAM

Post 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! :)
DrHu

Re: How To: Clear cache from your RAM

Post 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.
ChickenPie4Tea

Re: How To: Clear cache from your RAM

Post 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"
tone303

Re: How To: Clear cache from your RAM

Post 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?
tone303

Re: How To: Clear cache from your RAM

Post 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
JAnthony419

Re: How To: Clear cache from your RAM

Post 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.
User avatar
Moem
Level 22
Level 22
Posts: 16230
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: How To: Clear cache from your RAM

Post 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.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!
Locked

Return to “Tutorials”