Why is the cache in my memory always full?
I have 6GB RAM, i5 2.4GHZ Processor running Ubuntu 11.10. I partitioned my HD so that I have 8GB swap.
When streaming online or opening several tabs in Chromium I soon have 4GB Memory in the cache. And I think this makes my Notebook slow. When streaming a video, after a few minutes it really slows down and stumbles/jerks.
What could the problem be? How can I solve this?
P.S: initially I had 4GB and recently upgraded to 6GB, but I did not experience a significant change.
P.P.S: free -g
in the terminal prints this:
total used free shared buffers cached
Mem: 5 2 3 0 0 0
-/+ buffers/cache: 1 4
Swap: 8 0 8
Solution 1:
Caching data is RAM is supposed to make things faster, not slower - fetching things repeatedly from disk when you have unused memory is just silly. If you're spilling into swap space though, that will hit performance. You can easily tell if you're using any swap by running System Monitor
. If the swap-space graph isn't climbing at the time the problem starts, then the problem isn't memory related.
Certainly, when you stream video it will get cached in memory, but it takes quite a lot of video to fill 6Gb! I'd expect it to take more than just a few minutes to download that much data, and much more to cause a problem!
Are you sure something else isn't the problem? Say, cooling perhaps? Many notebooks have processors that are overspeced compared to the cooling system. This is good - it gives high peak performance, good for bursty traffic, while keeping the bulk down - but it can't keep up the performance for long before it is forced to dial back the clock rate or melt. Video can be fairly processor intensive, so you never know?
Anyway, you should be able to see from the memory usage whether it's swapping or not. If it is, then that's a software problem, and those can be fixed. :)
Solution 2:
I've the same problem, it seems the cache is never released... One example was when I checked out a repository and end up with a cache of 4GB
Example:
$ free -m
total used free shared buffers cached
Mem: 7949 7425 523 0 112 4433
-/+ buffers/cache: 2879 5069
Swap: 7627 2 7625
What I did was to run the code bellow (the comments are just so you know what is going on), you may create a script so you can run it when you need it:
# To free pagecache:
# echo 1 > /proc/sys/vm/drop_caches
# To free dentries and inodes:
# echo 2 > /proc/sys/vm/drop_caches
# To free pagecache, dentries and inodes:
# echo 3 > /proc/sys/vm/drop_caches
sudo sync && sudo sysctl -w vm.drop_caches=3
After I ran the code above:
$ free -m
total used free shared buffers cached
Mem: 7949 2820 5129 0 2 407
-/+ buffers/cache: 2409 5539
Swap: 7627 2 7625