Pages

Search This Blog

Showing posts with label available memory. Show all posts
Showing posts with label available memory. Show all posts

Friday, September 4, 2020

Memory/RAM usage in GNU/Linux¶

 

The Memory calculation in Linux (/Unix) is different from that of Windows OS

Memory that is: You'd call it: Linux calls it:
used by applications                      
Used Used
used, but can be made available Free (or Available) Used (and Available)
not used for anything Free Free

What is procps? 

procps is a package that provides command line and full screen utilities for browsing procfs, a "pseudo" file system dynamically generated by the kernel to provide information about the status of entries in its process table (such as whether the process is running, stopped, or a "zombie"). 

As you know the different commands to check the process states such as ps, free, vmstat etc, all these commands use this procps package to provide the output.

procps contains free, kill, pkill, pgrep, pmap, ps, pwdx, skill, slabtop, snice, sysctl, tload, top, uptime, vmstat, w, and watch. 

 

Memory usage calculation

For ex: Below is the output of free command (procps version < 3.3)

[root@RGIUSMARTWEB ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         11912      11194        718          0        214       9354
-/+ buffers/cache:       1624      10287
Swap:        17999          9      17990
[root@RGIUSMARTWEB ~]#

The used mem is calculated as Total - free, i.e. 11912 - 718 = 11194(size in mbs). Actually, in *nix these used_mem is that of cached and buffers which can be reclaimable by the programs or apps in user-space.

So, the used memory by the apps/pgms in user-space is calculated as used = total - free - cached - buffers
i.e. 11912 - 718 - 214 - 9354 = 1626

Hence the real available memory for the apps/pgms in user-space is total - used, i.e., 11912 - 1626 = 10286
So 10286 mb is free in above scenario.

The upgraded version of procps includes an available column which shows the above value derived using the same method.
The Mem used(kb_main_used) field value is now calculated like this:
used = total - free - cached - buffers
Previously, it used to be:
used = total - free

Below is the output of free command with procps version 3.3.10

[root@RGIUSMARTWEB procps-ng-3.3.10]# free -m
              total        used        free      shared  buff/cache   available
Mem:          11912        1253         611           0       10047       10381
Swap:         17999           9       17990
[root@RGIUSMARTWEB procps-ng-3.3.10]#

Please note the 'available' column which matches the previous value calculated, available=10381 (little change is due to the slab/cache difference)

Newer linux kernels has the MemAvailable segment in /proc/meminfo which shows the somewhat same range of value.

As of the new available field, for Linux kernels older than 2.6.27, its value is the same as the free value, but for the later versions of the Kernel, its a bit different:

Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)

Kernel commit for /proc/meminfo (hey! look who has made that commit..)

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773

Newer versions of procps package (> 3.3) has the available column which shows an accurate value of memory available for applications and programs in userspace

Procps package commit with available column: --> https://gitlab.com/procps-ng/procps/commit/6cb75efef85f735b72e6c96f197f358f511f8ed9

References:
https://www.linuxatemyram.com/
https://www.dynatrace.com/news/blog/improved-host-memory-metrics-now-include-reclaimable-memory/

GNU, Unix, Linux, *nix, FOSS, F(L)OSS,..

Woah, that's a long list keywords..and yes, these are some of the basic terms that comes in the minds of programmers or sysadmins(i gues...