From linuxatemyram.com:
If your applications want more memory, they just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram!
This isn't true. Something is eating the RAM, and won't give it back. The use case is Chromium or Firefox with lots of tabs, then quit them. There will be additional RAM taken up than before the browser was run.
A few numbers to show what I mean:
On bootup: <2GB used, usually ~1.7GB.
Open a bunch of tabs in FF/Chromium, eventually more than 8GB are used
Quit FF/Chromium, and 3.5GB are used.
What is the 3.5-1.7= 1.8GB? Let's call it X.
Is X a memory cache? A memory leak? Why do both Firefox and Chromium reproduce the exact seem results?
Opening tabs eventually completely fills my 8GB RAM, system freezes, then eventually tabs die/freeze/crash, freeing just enough memory to continue.
The correct function, that I wish Ubuntu had, would be giving whatever the hell X is back to applications when they want RAM to run. However, when I launch an app, and most of the RAM has been eaten up by X, whether it was created by either of the 2 most mainstream browsers, no RAM is reclaimed from X. It remains until I reboot.
Use of "free" and other tools has not helped me diagnose WTF X is.
Any ideas?
Free outputs:
About a minute after quitting chromium.
total used free shared buff/cache available
Mem: 8035708 4037332 2202604 1014656 1795772 2713256
Swap: 12441592 0 12441592
A little while later.
total used free shared buff/cache available
Mem: 8035708 2497680 4168392 552812 1369636 4715280
Swap: 12441592 0 12441592
A day later, moments after a fill up to 7.9GB and all the tabs crash.
total used free shared buff/cache available
Mem: 8035708 5855132 739016 1012864 1441560 923084
Swap: 12441592 975712 11465880
After a similar fill-up and crash.
total used free shared buff/cache available
Mem: 8035708 5777812 638932 714256 1618964 1273920
Swap: 12441592 0 12441592
Some time later, opened chromium, ran it for a few hours (not to max RAM), closed it:
total used free shared buff/cache available
Mem: 8035708 737080 5869896 438592 1428732 6604848
Swap: 12441592 524436 11917156
Right after boot:
total used free shared buff/cache available
Mem: 8035708 689232 6449124 322912 897352 6769772
Swap: 12441592 0 12441592
After Chromium quits:
total used free shared buff/cache available
Mem: 8035708 967988 5677848 531960 1389872 6284744
Swap: 12441592 336 12441256
There is no issue as far as I can see. The “available” memory behaves as expected. As applications claim more memory, the available memory decreases; once they quit, the available memory jumps up again.
It's also normal for the system to become sluggish or the user interface to stall entirely while the system accesses the swap space, especially if the device backing it is slow. Hard disk drives are typically worse than flash storage because of their high access latency.
Both Chromium/Chrome and Firefox are known to use lots of memory with lots of tabs open. Either add more RAM to your system or reduce the number of open tabs severely. You may be able to mitigate the issue with a faster swap space backing device.
You can query the virtual memory manager for current memory statistics with
free -h
(-h
is for human-readable number formatting). You can list the (N-1) processes taking up the most memory withps aux --sort -rss | head -n N
or withtop
and adjusted sorting.You may also be interested in How do you find out which program is using too much memory?