Support Services - How does Linux use Memory

By default, Linux has the tendency to use all memory. Over time, free memory will be going towards zero. The more time the system is running, the lower the free RAM is supposed to be.

Linux uses RAM for two purposes:

  1. To allocate space for running application (think about opening a new tab in chrome), which is what almost everyone understands as the purpose of RAM and;

  2. Disk caching, which is the operation of moving a file from disk to RAM in order to allow quick access (this is why the first time that you load chrome on a linux computer it will be slow, but if you close it and reopen it, the second time will be faster, the application is actually read from memory rather than from the disk).

The second use for RAM is why Linux tends to go towards zero free memory. This is because it will keep applications in RAM as much as it can.

 

What would happen if the Free is zero and an application needs more memory?
(For this, we will use an example, let's say a new tab is created in chrome)

  1. Linux will check its disk caching and clear something that has been stored for quick access and give it to the application.

  2. Linux will always give memory to applications that are requesting more memory and use either free or disk caching memory to do so.

 

When SWAP memory comes into place:
SWAP is used when an application is requesting more memory and Linux has no free or disk caching memory that it could use to give it more, as such it falls back to use SWAP.

Is having SWAP usage an issue?
This depends, if Linux is actively using SWAP, then the answer is yes. In this case, you will increase the memory.  However, the key word here is "actively" as in you see in free output that Linux IS using SWAP and either it is increasing or decreasing.

Now, there is a caveat here:
If you just run a report in Switchvox that you requested a XML file having the last 2 years of calls, you will see swap being used because the memory utilization just to get that file created will be large.If you see swap usage only when you do this, it's normal and no need to be concerned.

Please note that once Linux has allocated something to swap, it may keep it allocated even when it's not activity using it.

Below is an example:
                total           used           free           shared        buff/cache      available
Mem:       16093728    1833288      849072      938488       13411368       12893396
Swap:       8191996     72448         8119548

Note that Linux claims that it has used 72448 in SWAP. This does not mean there is a memory issue, it just means that at some point the system was forced to use swap. Since there is 13411368 in buff and cache, we know for a fact that the system is fine in terms of memory.
More than likely here, the swap usage happened during a nightly backup process, as such it may be expecting that during the backup the memory will temporarily have full utilization.

Related content