Sunday, July 17, 2016

What commands do you use to check free memory on the linux system ?


we can check free memory in many ways . Below are the couple of examples on how we can check .

1) free command  :-

using free command it gives current total memory allocated  and current usage including cache/buffer memory usage .

[root@tstvm ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           988        194        794          0         43         49
-/+ buffers/cache:        101        887
Swap:         1983          0       1983

[root@tstvm ~]#

from the above example 

988 gb  = total memory allocated 
194 gb = current used memory 
794 gb = current free memory 

43 and 49 is buffer/cache memory .

NOTE:- Linux uses free memory for buffer/cache to keep data read/write from/to disks in memory for speed access in the future.These memory can be reclaimed in case kernel/application needs to allocation explicitly. 


2) cat /proc/meminfo


[root@tstvm ~]# cat /proc/meminfo
MemTotal:        1012548 kB
MemFree:          813080 kB
Buffers:           44428 kB
Cached:            50812 kB
SwapCached:            0 kB
Active:            67108 kB
Inactive:          44864 kB
Active(anon):      16968 kB
Inactive(anon):        4 kB
Active(file):      50140 kB
Inactive(file):    44860 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2031608 kB
SwapFree:        2031608 kB
Dirty:                 8 kB
Writeback:             0 kB
AnonPages:         16752 kB
Mapped:            11060 kB
Shmem:               236 kB
Slab:              64652 kB
SReclaimable:      12612 kB
SUnreclaim:        52040 kB
KernelStack:         776 kB
PageTables:         2912 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2537880 kB
Committed_AS:     103460 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      276296 kB
VmallocChunk:   34359446148 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:        6144 kB
DirectMap2M:     1042432 kB
DirectMap1G:           0 kB
[root@tstvm ~]#




Active memory  is the amount of buffer and cache memory  has been recently used, which is not usually reclaimed
Inactive memory is  the amount of buffer and cache memory that  has not been recently used, can be reclaimed by kernel



3) TOP command :-

using  top command you can see memory/cpu usage including the current running process. you can the each process and that perticular process memory/cpu usage .

top - 07:48:08 up 21 min,  1 user,  load average: 0.00, 0.00, 0.02
Tasks:  89 total,   1 running,  88 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1012548k total,   199864k used,   812684k free,    44456k buffers
Swap:  2031608k total,        0k used,  2031608k free,    51072k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      20   0 19356 1524 1224 S  0.0  0.2   0:01.71 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.01 ksoftirqd/0
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.01 watchdog/0
    7 root      20   0     0    0    0 S  0.0  0.0   0:02.26 events/0
    8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm
   13 root      20   0     0    0    0 S  0.0  0.0   0:00.01 sync_supers
   14 root      20   0     0    0    0 S  0.0  0.0   0:00.01 bdi-default
   15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0
   16 root      20   0     0    0    0 S  0.0  0.0   0:00.20 kblockd/0
   17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpid
   18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_notify
   19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_hotplug
   20 root      20   0     0    0    0 S  0.0  0.0   0:00.03 ata/0
   21 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ata_aux
   22 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksuspend_usbd
   23 root      20   0     0    0    0 S  0.0  0.0   0:00.17 khubd
   24 root      20   0     0    0    0 S  0.0  0.0   0:00.02 kseriod
   25 root      20   0     0    0    0 S  0.0  0.0   0:00.00 md/0
   26 root      20   0     0    0    0 S  0.0  0.0   0:00.00 md_misc/0
   27 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khungtaskd
   28 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kswapd0
   29 root      25   5     0    0    0 S  0.0  0.0   0:00.00 ksmd
   30 root      39  19     0    0    0 S  0.0  0.0   0:00.00 khugepaged
   31 root      20   0     0    0    0 S  0.0  0.0   0:00.00 aio/0
   32 root      20   0     0    0    0 S  0.0  0.0   0:00.00 crypto/0
   37 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthrotld/0
   38 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pciehpd
   40 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kpsmoused
   41 root      20   0     0    0    0 S  0.0  0.0   0:00.00 usbhid_resumer
   72 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kstriped

No comments:

Post a Comment