Why is the cache in my memory always full?
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
Related videos on Youtube
Tobias
Updated on September 18, 2022Comments
-
Tobias over 1 year
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
-
Sergey over 12 yearsWhat do you mean by "RAM Cache" and how do you tell that it's getting full?
-
irumata over 12 yearsCan you please run
free -g
(in terminal) when you experience the problem and include the output of the command in your question. -
Tobias over 12 yearsOn my upper panel I have an applet that indicates RAM and CPU usage grafically. When I click it, it tells me that: "Mem: 2GB Cache 4GB"
-
ams over 12 years
free -g
says you've 3GB of free RAM. Memory is not your problem! -
Tobias over 12 yearsOk great thanks for clearing that up, but perhaps because in that moment I was not streaming online? I just had chromium running.
-
Tobias over 12 yearsI am watching a movie right now (VLC) no other apps running and the Cache is filled with 4,4GB Ram. This is what the terminal tells me after entering "free -l" total used free shared buffers cached Mem: 5984648 5270160 714488 0 82852 4223604 Low: 5984648 5270160 714488 High: 0 0 0 -/+ buffers/cache: 963704 5020944 Swap: 8787964 12 8787952
-
Joshua Pinter over 6 yearsThis line is super key to understanding real performance:
Swap Used: 0
. This means that your swap file hasn't been hit yet. Let your system use your memory however it wants, including caching the hell out of it. It's really only when you start using the Swap file that you have run out of memory. Until that, your system is going to take from the cached memory as it needs to.
-
-
Tobias over 12 yearsI am using just 1,8% of SWAP. Cooling is not the problem as I have a cooling pad with two fans. I know video is processor intensive but i5 quad core 2,4GH and 6GB RAM should definitively be enough for smooth streaming.
-
Tobias over 12 yearsIndeed, when I restart the browser, the streaming runs smoothly again, however just for 10minutes. Then I have to restart the browser again.
-
Tobias over 12 yearsThe Processes used: Chromium 250MB Chromium 214 MB Chromium 150Mb, compiz 119 MB, zeitgeist-daemon 111 MB, chromium 70Mb, exe 24% of CPU and 60MB, Rhythmbox 50MB, ubuntuone-syndaemon 26MB etc..
-
ams over 12 years1.8% of swap suggests to me that your problem is not that you've run out of RAM. I agree, as long as your processor has not been throttled, it ought to be able to do the job.
-
Tobias over 12 yearsOk than perhaps it is the Browser itself?
-
Tobias over 12 yearsThanks for your answers I will try to use another browser and let you know if the issue persists. Thanks again, you were very helpful and kind, I really appreciate!
-
Adam Kroczyk over 12 yearsIm afraid your problem may be caused by the browser itself. Consider switching to Firefox or any of your choice, users opinion over the web says Chromium consumes about 3x more memory than any other 'top line' browser. Give it a try. Install, open the same number of tabs and compare...
-
Tobias over 12 yearsI'll dp that. Thanks very much for the suggestion. all the best
-
Caesium over 12 yearsThis is not a problem, this is how the page cache works. It will keep things cached as long as possible, but release items automatically when memory pressure from other applications increases. Clearing it up manually is unnecessary.
-
Carlo over 12 yearsIt may be so but in that case the algorithm is not that good. Why would I've more than 4GB of cache and start to use swap?
-
Carlo over 12 yearsOn the subject, I like this article: link
-
Carlo over 12 yearsIn my current case I'm checking out a huge repository and all files are getting cached until it fills up the memory, once there it starts to swap instead of release cache...
-
Steve Dee about 10 yearsI used to take an interest in kernel development .. Pretty sure this is still "by design." If the kernel thinks that part of a file is more likely to be accessed again soon than some anonymous data, it would swap the anon data and keep the page cache. Whether it's making the right decision is a different question, of course :)
-
inf3rno about 8 years@Carlo This is interesting, I use now 14.04 on a server and there is no swap. It would take 200MB more to reach the memory limits, I am wondering what will happen after that...