Monday 9 July 2018

Displaying Memory Usage Information With “free” Command


Memory Usage Information With “free” Command

The free utility displays the amount of physical (RAM) and swap memory in the local system. It displays columns for total, used, and free memory as well as for kernel buffers. The column labeled shared is obsolete. This utility is not available under macOS; vm_stat performs a similar function.
In the following example, the –m option causes free to display memory sizes in megabytes and the –t option adds the line labeled Total to the end of the output. You can cause free to display memory sizes in gigabytes (–g), megabytes (–m), kilobytes   (–k; the default), or bytes (–b).
$ free -mt      total                used                free                 shared            buffers        cached
Mem:             2013                748                  1264                0                      110              383
-/+ buffers/cache:                 254                  1759
Swap:                                    2044                0                      2044
Total:             4058                748                  3309
 

 One of the ways Linux takes advantage of free memory is to allocate memory it is not otherwise using to buffers and cache. Thus, the value on the Mem line in the free column will be small and is not representative of the total available memory when the kernel is working properly. As the kernel needs more memory, it reallocates memory it had allocated to buffers and cache.
The –/+ buffers/cache line gives values assuming memory used for buffers and cache is free memory. The value in the used column on this line assumes buffers and cache (110 + 383 = 493 on the Mem line) are freed; thus, the value in the used column is 254 (~748 – 493) while the value in the free column value increases to 1759
(~1,264 + 493). Unlike the value in the free column on the Mem line, as the value in the free column on the –/+ buffers/cache line approaches zero, the system is truly running out of memory.
The Swap line displays the total, used, and free amounts of swap space.

No comments:

Post a Comment