Check Free Memory/RAM In Linux

In this quick post I will show you how to check your available or free memory/RAM, as-well as how to see what processes are taking up what percentage (top/htop). There are multiple ways to accomplish this so if I miss any please feel free to comment below so I can add them for any future visitors.

Free Command

One of the quickest and easiest ways to check available RAM in Linux as-well as available swap is by using the free command. You can use the -g argument for gigabytes (rounds down) or -m argument for megabytes (much more accurate than -g). Here is an example of the free command in use.

~# free -m
              total        used        free      shared  buff/cache   available
Mem:            992         851          61          39          80           2
Swap:             0           0           0

TOP And HTOP Commands/Utilities

The top and htop (not installed by default) utilities will allow you to check your total CPU and Memory usage, as-well as what processes are using what percentage of those resources each process is consuming. You can also do things like pressing the m button on your keyboard to sort by memory usage. Htop has more features however it is not installed by default (usually), top is included by default (usually). Here is an example of top since this is included by default. You can exit either by pressing CTRL+C.

~# top
top - 01:10:19 up 12 min,  1 user,  load average: 0.29, 0.53, 0.37
Tasks: 122 total,   2 running, 120 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  1.7 sy,  0.0 ni, 97.7 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 98.6/1016128  [|||||||||||||||||||||||||||||||||||||||||||||||||||| ]
KiB Swap:  0.0/0        [                                                     ]

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
   28 root      20   0       0      0      0 R  1.3  0.0   0:48.73 kswapd0
 2007 mike      20   0   95404   1584    616 S  0.3  0.2   0:00.18 sshd
 2447 root      20   0   40500   1580   1004 R  0.3  0.2   0:00.07 top
    1 root      20   0   38160   3192    960 S  0.0  0.3   0:02.35 systemd

Check /proc/meminfo

This is basically as close as you are going to get to “straight from the horse’s mouth”, this will also give you much more information although nothing about the processes currently running. If all else fails, this should always work.

~# cat /proc/meminfo
MemTotal:        1016128 kB
MemFree:           65808 kB
MemAvailable:      11748 kB
Buffers:            1892 kB
Cached:            64232 kB
SwapCached:            0 kB
Active:           868352 kB
Inactive:          21580 kB
Active(anon):     856292 kB
Inactive(anon):    10960 kB
Active(file):      12060 kB
Inactive(file):    10620 kB
Unevictable:        3660 kB
Mlocked:            3660 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                84 kB
Writeback:             0 kB
AnonPages:        827472 kB
Mapped:            58012 kB
Shmem:             41016 kB
Slab:              27616 kB
SReclaimable:      12016 kB
SUnreclaim:        15600 kB
KernelStack:        2864 kB
PageTables:        13976 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      508064 kB
Committed_AS:    1758424 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:    366592 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       45036 kB
DirectMap2M:     1003520 kB
DirectMap1G:           0 kB

I hope this quick guide on how to check available ram in Linux helped you. Please don’t forget to like/comment/share, thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *