YouTube Icon

Code Playground.

How to Check Memory Usage in Linux

CFG

How to Check Memory Usage in Linux

While investigating framework or application log jam or misconduct, one of the principal things to check is the framework memory utilization. 

This article discloses how to check RAM utilization in Linux utilizing a few unique orders. 

free Command

free is the most normally utilized order for checking the memory utilization of a Linux framework. It shows data about the aggregate, utilized, and free memory. 

For the most part, free is conjured with the - h alternative that implies print the yield in intelligible organization: 

free -h

complete utilized free shared buff/reserve accessible 

              total        used        free      shared  buff/cache   available
Mem:           3936        1087         252         130        2596        2427
Swap:             0           0           0

This is what every section mean: 

  • complete - The aggregate sum of memory that can be utilized by the applications. 
  • utilized - Used memory. It is determined as: utilized = complete - free - cushions - reserve 
  • free - Free/Unused memory. 
  • common - This section can be disregarded; it is indicated distinctly for in reverse similarity. 
  • buff/reserve - The consolidated memory utilized by the portion cushions and page store and chunks. This memory can be recovered whenever if necessary by the applications. 
  • accessible - A gauge of the memory that is accessible for beginning new applications, without trading. 

The free order prints data for the physical memory and the framework trade . 

top Command

top is an order line utility that shows ongoing data about the running cycles. It additionally shows the framework synopsis, including memory use. 

To conjure the order basically type top: 

free -h

The yield will look something like this: 

The header of the yield incorporates data about the framework's sans aggregate, and utilized physical and trade memory. 

The %MEM segment gives data about the pre-owned portion of the accessible physical memory for each running cycle. 

/proc/meminfo

The least complex approach to check the RAM memory utilization is to show the substance of the/proc/meminfo virtual record. This document is utilized by the free, top, ps , and other framework data orders. 

Utilize less or feline to see the substance of the/proc/meminfo record: 

cat /proc/meminfo

The document incorporates a lot of data about the frameworks memory and trade use: 

MemTotal:        4030592 kB
MemFree:          401804 kB
MemAvailable:    2507504 kB
...

The data from the/proc/meminfo document can be parsed and utilized in shell contents. 

sudo pip3 install ps_mem

ps_mem is a Python content that reports per-program RAM memory use. It work with both Python 2 and 3 and can be introduced with pip: 

sudo ps_mem

Running ps_mem requires chairman benefits: 

The yield will incorporate the memory utilization of each running system in rising request: 

 Private  +   Shared  =  RAM used	Program
...
 11.9 MiB +  20.2 MiB =  32.1 MiB	nginx (4)
  8.2 MiB +  42.4 MiB =  50.6 MiB	systemd-journald
 55.8 MiB + 307.2 MiB = 363.0 MiB	php-fpm7.4 (6)
233.9 MiB + 234.0 MiB = 467.9 MiB	redis-server
578.2 MiB + 578.6 MiB =   1.1 GiB	mysqld
---------------------------------
                          2.2 GiB
=================================

This content is valuable when you need to discover which running project is taking a large portion of your framework memory. 

Conclusion

We have demonstrated you a few orders that you can use to check the framework memory utilization. 

On the off chance that you have any inquiries or comments, if you don't mind leave a remark underneath.




CFG