2

I've 4 GiB RAM, and System Monitor shows 3.8 GiB. I think 200 MiB is for GPU. But I've never seen Memory usage more than 3.0 GiB. If memory usage is close to 3 GiB, it uses Swap, and when it reaches to 3 GiB computer freezes (I'm using Idea IDE).

I've disabled vm.swappiness (with swapoff -a). Didn't help. Then tried swappiness=0, swappiness=1, swappiness=20.

When I added extra 4 GiB, I saw memory usage 5 GiB. Now I've only 4 GiB RAM.

I'm using Ubuntu 14.04. Why System Monitor doesn't show 3.7 or 3.8 GiB memory usage? enter image description here

3 Answers 3

4

If you disable swappiness, your RAM will get more full. If you increase swappiness, the data in RAM will get paged out to the swap partition when your ram reaches a certain level. Ram will get full but it's not always a problem. If you really want to do something about it, you can run the following command to clear your cash:

(warning: If you have installed profile-sync-daemon, close firefox and run the command sudo service psd stop before you run the following command!)

echo "3" | sudo tee /proc/sys/vm/drop_caches

This will clear your cash even though most of the time it's not necessary especially if swappiness is enabled. People are usually alarmed when they see high RAM usage on a linux desktop but the developers insist that the system will actually run faster because what is in the ram is cached data that can easily and quickly be retrieved by the system. When the system is in heavy use, those cached files get transfered to swap.


The reason you don't see as much RAM in use as before is because Linux is designed to most efficiently make use of and take advantage of the available system resources. So, if you had 12GB of RAM you might see 8 or even 9GB of RAM use instead. Alot of the RAM in use is used for caching and is not usually necessary to run the immediate desktop.

As for the system showing 3GB of RAM in use, run the following command and you should get a more accurate number:

free

system-monitor says I'm using 1.4GB of RAM and the actual RAM in use including buffers/cache is 2.7GB, almost twice the reported figure. This number is often much higher as the cache will sometimes grow to more than 50% of the total. Also, system monitor reports my total RAM at 4.7 when the actual number is closer to 4.9GB.


To help diagnose your issue you can install htop and iotop to get a better idea of what's going on when you have problems. To install:

sudo apt-get install iotop htop

To run:

sudo iotop

or

sudo htop

From my own experience I've always achieved better system performance using swap and have run into problems (system freezes) when swap is disabled. In fact, this is most likely why your computer freezes. Without swap, the system has no way to continue using RAM after becoming full. Turning swappiness down too low can also cause excessive paging and thrashing of the hard drive if have alot of RAM in use. This problem will sometimes show up as excessive kworker activity using iotop.

2
  • Thanks. free command helped me to understand about cache, buffer in RAM. I've installed Kubuntu 14.10 and now RAM usage is 3.2 GiB. No freezing. I'm doing what I was doing with my comp in Ubuntu 14.04 and it's working smoothly so far.
    – Ikrom
    Oct 29, 2014 at 7:32
  • Hi, @mchid would you mind having a look at my RAM related issue on ubuntu 16.04. My problem is in fact the opposite: my system is freezing on 100% RAM usage, here it is askubuntu.com/questions/1032045/…
    – pltrdy
    May 17, 2018 at 12:02
2

This tool is not including disk cache in what it is reporting as "free". Your system is swapping in order to maintain a reasonably sized disk cache.

Please see my answer to this question for more information. Here's an excerpt:

Each application can use some of your memory. Linux uses all otherwise unoccupied memory (except for the last few Mb) as "cache". This includes the page cache, inode caches, etc. This is a good thing - it helps speed things up heaps. Both writing to disk and reading from disk can be sped up immensely by cache.

Ideally, you have enough memory for all your applications, and you still have several hundred Mb left for cache. In this situation, as long as your applications don't increase their memory use and the system isn't putting too much pressure on the cache, there is no need for any swap.

Once applications claim more RAM, it simply goes into some of the space that was used by cache, shrinking the cache. De-allocating cache is cheap and easy enough that it is simply done in real time - everything that sits in the cache is either just a second copy of something that's already on disk, so can just be deallocated instantly, or it's something that we would have had to flush to disk within the next few seconds anyway, thus there is zero performance hit in re-allocating cache to applications.

So, when someone refers to "free" RAM, this may or may not include cache, since cache will only occupy "free" RAM. This is not a situation that is specific to Linux - all modern operating systems work this way. The different operating systems might just report free RAM differently: some include the cache as part of what they consider "free" and some may not.

When you talk about free RAM, it's a lot more meaningful to include cache, because it practically is free - it's available should any application request it. On Linux, the free command reports it both ways - the first line includes cache in the used RAM column, and the second

...

Once you have used up enough memory that there is not enough left for a smooth-running cache, Linux may re-allocate some unused application memory from RAM to swap in order to regain some memory for cache.

It doesn't do this according to a definite cutoff though. It's not like you reach a certain percentage of allocation then Linux starts swapping. It has a rather "fuzzy" algorithm. It takes a lot of things into account, which can best be described by "how much pressure is there for memory allocation". If there is a lot of "pressure" to allocate new memory, then it will increase the chances some will be swapped to make more room. If there is less "pressure" then it will decrease these chances.

Note: what I said above applies not just to Linux but to virtually all modern computer operating systems, including Windows, Mac OS, etc.

1

You can change or modify de value of the parameter vm.min_free_kbyte in /etc/sysctl.conf

This controls the amount of memory that is kept free for use by special reserves including “atomic” allocations (those which cannot wait for reclaim).

You can set a small value and see how it goes.

You can see more information in this post.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .