Page 1 of 1

Clearing Linux memory cache

Posted: 21 Oct 2014, 00:01
by viking60
I have a box with 2 G memory and I often see that it hits the roof and uses swap from time to time. so my htop indicates that more than 90% of the memory is used.

After having used x2go that cache seems to fill up quickly and stays there (and oh boy... Steam...).
When I check out the running processes in Atop they are not taking much but there is a cache of 1.2 G.
Linux mem will be maxed from time to time and that is mostly no problem, just Linux doing its job.
(If you have the memory - use it! It does make sense).

But when you use that program that goes beyond the limit your computer can freeze up a bit and applications can crash - typically games.
There is not much harm in (occasionally) removing it and frankly the output of Atop and Htop make more sense then.

So here we go:

Code: Select all

sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches" 


..and your memory cache is gone. Htop looks nice again and in some strange way it feels way better to look at the mem in one of those programs now +1

If you do not have programs that push the limits - you do not need to do this -leave it to Linux.

But then there are those times when one program has made all lamps blink red....
Or you want to benchmark the speed of your disks - you need to clear the cache for that. (yup that cache normally makes your computer faster - not slower)
Or as a security feature.

If you want to clear your swap you can just turn it off and on again:

Code: Select all

swapoff -a
and

Code: Select all

swapon -a