Checking the Memory Usage Linux

Checking Memory in Linux

Sometimes you want to check your memory usage and there are a lot of tools to do so. I”ll try to explain about some most useful tools to check memory usage of your system.

free

knesenko@knesenko-centos7:~$ free -m
total used free shared buffers cached
Mem: 3778 861 2916 16 84 451
-/+ buffers/cache: 325 3452
Swap: 2047 0 2047

What you can see here, is that total amount of your memory is 3778 MB325 MB are used by processes. 3452 MB are free yo use. Last line shows you the swap usage.


/proc/meminfo

Also you can check /proc/meminfo

knesenko@knesenko-centos7:~$ egrep --color 'Mem|Cache|Swap' /proc/meminfo

MemTotal: 3869004 kB

MemFree: 2986092 kB

MemAvailable: 3392864 kB

Cached: 479408 kB

SwapCached: 0 kB

SwapTotal: 2097148 kB

SwapFree: 2097148 kB

vmstat

vmstat shows you a bit more info about your memory and other resources usage.

knesenko@knesenko-centos7:~$ vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

2 0 0 2986092 87172 462452 0 0 2  8  39 73 0  0  100 0 0

procs: 
r: How many processes are waiting for CPU time.
b: Wait Queue – Process which are waiting for I/O (disk, network, user input,etc..) 

memory: 
swpd: shows how many blocks are swapped out to disk (paged). Total Virtual memory usage. 

free: Idle Memory

buff: Memory used as buffers, like before/after I/O operations
cache: Memory used as cache by the OS

swap: 
si: How many blocks per second the operating system is swapping in. i.e Memory swapped in from the disk (Read from swap area to Memory)
so: How many blocks per second the operating system is swapped Out. i.e Memory swapped to the disk (Written to swap area and cleared from Memory). In Ideal condition, We like to see si and so at 0 most of the time, and we definitely don’t like to see more than 10 blocks per second.

io: 
bi: Blocks received from block device – Read (like a hard disk) 
bo: Blocks sent to a block device – Write

system: 
in: The number of interrupts per second, including the clock. 
cs: The number of context switches per second. 

CPU: 
us: percentage of cpu used for running non-kernel code. (user time, including nice time) 
sy: percentage of cpu used for running kernel code. (system time – network, IO interrupts, etc) 
id: cpu idle time in percentage.
wa: percentage of time spent by cpu for waiting to IO.

knesenko@knesenko-centos7:~$ vmstat -s
      3869516 K total memory
      1758256 K used memory
       279100 K active memory
      1317776 K inactive memory
      2111260 K free memory
        59584 K buffer memory
      1331872 K swap cache
      2097148 K total swap
            0 K used swap
      2097148 K free swap
        15833 non-nice user cpu ticks
            9 nice user cpu ticks
        26954 system cpu ticks
      6886801 idle cpu ticks
          319 IO-wait cpu ticks
            5 IRQ cpu ticks
         2636 softirq cpu ticks
            0 stolen cpu ticks
       340359 pages paged in
      1229646 pages paged out
            0 pages swapped in
            0 pages swapped out
     10782519 interrupts
     21597473 CPU context switches
   1424333862 boot time
         8042 forks

 

Also I would recommend to use top, htop commands.