How to Check Memory Usage In Linux

Share this Article :

There are a few commands that can help us to check the memory usage in linux server. The usage including free memory, used physical memory, swap memory and also buffers used by the kernel.

1. Type top command at ssh login or terminal.

    [[email protected] ~]# top
    

Sample outputs:

    top - 23:35:48 up  1:36,  1 user,  load average: 0.00, 0.01, 0.02
    Tasks:  67 total,   1 running,  66 sleeping,   0 stopped,   0 zombie
    Cpu(s):  0.4%us,  1.8%sy,  0.1%ni, 95.6%id,  2.1%wa,  0.1%hi,  0.0%si,  0.0%st
    Mem:    604324k total,   329952k used,   274372k free,    65428k buffers
    Swap:  1052248k total,        0k used,  1052248k free,   208324k cached
    
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
        1 root      15   0  2156  640  548 S  0.0  0.1   0:01.03 init
        2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0
        3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
        4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
        5 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/0
        6 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khelper
        7 root      11  -5     0    0    0 S  0.0  0.0   0:00.00 kthread
       10 root      10  -5     0    0    0 S  0.0  0.0   0:00.01 kblockd/0
       11 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid
      170 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 cqueue/0
      173 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 khubd
      175 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kseriod
      240 root      15   0     0    0    0 S  0.0  0.0   0:00.00 khungtaskd
      241 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pdflush
      242 root      15   0     0    0    0 S  0.0  0.0   0:00.20 pdflush
      243 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kswapd0
      244 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 aio/0
    

2. Type vmstat command at ssh login or terminal

    [[email protected] ~]# vmstat
    

Sample outputs:

    procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
     r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
     0  0      0 273256  65688 208884    0    0    79    39 1039   84  0  2 96  2  0
    

3. Display free memory in bytes, KB, MB, or GB

usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit

Also Read :   How to Change Web Server Mode using zmtlsctl on Zimbra

Type below command if you want to displays a line containing the totals memory in MB:

    [[email protected] ~]# free -m -t
    

Sample outputs:

                 total       used       free     shared    buffers     cached
    Mem:           590        323        266          0         64        204
    -/+ buffers/cache:         54        535
    Swap:         1027          0       1027
    Total:        1617        323       1294
    

4. Cat the /proc/meminfo to get the memory usage information as below:

    [[email protected] ~]# cat /proc/meminfo
    

Sample outputs:

    MemTotal:       604324 kB
    MemFree:        272512 kB
    Buffers:         66040 kB
    Cached:         209256 kB
    SwapCached:          0 kB
    Active:          61864 kB
    Inactive:       222596 kB
    HighTotal:           0 kB
    HighFree:            0 kB
    LowTotal:       604324 kB
    LowFree:        272512 kB
    SwapTotal:     1052248 kB
    SwapFree:      1052248 kB
    Dirty:            1032 kB
    Writeback:           0 kB
    AnonPages:        9172 kB
    Mapped:           6468 kB
    Slab:            39896 kB
    PageTables:        972 kB
    NFS_Unstable:        0 kB
    Bounce:              0 kB
    CommitLimit:   1354408 kB
    Committed_AS:    76248 kB
    VmallocTotal:   417784 kB
    VmallocUsed:      4052 kB
    VmallocChunk:   413304 kB
    HugePages_Total:     0
    HugePages_Free:      0
    HugePages_Rsvd:      0
    Hugepagesize:     4096 kB
    


Leave a Reply