How to check memory utilization in Linux

How do I check memory utilization in Linux using command-line and GUI options?

We have physical RAM such as 16GB and swap memory. Swap memory is nothing but disk space that allows your Linux computer to run more applications simultaneously than will fit into the system memory (RAM). This page explains various commands to check memory usage and utilization in Linux using command-line and GUI tools.

Commands to check memory utilization in Linux

Your Linux system must run at an optimal level. Memory plays a critical role in a Linux system. A developer or seasoned sysadmin must know the total amount of free and used physical, including swap memory in the server. It would be best if you kept an eye on buffers and caches used by the kernel too.

The /proc/meminfo file

The /proc/meminfo file reports statistics about memory usage on Linux. Use the cat command/less command or grep command/egrep command as follows on your Linux box:
cat /proc/meminfo
more /proc/meminfo

How to check memory utilization in Linux
Each line of the /proc/meminfo file consists of a parameter name, followed by a colon, the parameter value, and an option unit of measurement. For example, “kB“.

Understanding memory utilization parameters

Fields description table
Parameter Description
MemTotal Total usable RAM (i.e., physical RAM minus a few reserved bits and the kernel binary code).
MemFree The sum of LowFree+HighFree.
MemAvailable (since Linux 3.14) An estimate of how much memory is available for starting new applications, without swapping.
Buffers Relatively temporary storage for raw disk blocks that shouldn’t get tremendously large (20MB or so).
Cached In-memory cache for files read from the disk (the page cache). Doesn’t include SwapCached.
SwapCached Memory that once was swapped out, is swapped back in but still also is in the swap file.
Active Memory that has been used more recently and usually not reclaimed unless absolutely necessary.
Inactive Memory which has been less recently used. It is more eligible to be reclaimed for other purposes.
HighTotal Total amount of highmem. Highmem is all memory above ~860MB of physical memory. Highmem areas are for use by user-space programs, or for the page cache. The kernel must use tricks to access this memory, making it slower to access than lowmem.
HighFree Amount of free highmem.
LowFree Amount of free lowmem.
SwapTotal Total amount of swap space available.
SwapFree Amount of swap space that is currently unused.
Dirty Memory which is waiting to get written back to the disk.
Writeback Memory which is actively being written back to the disk.
AnonPages Non-file backed pages mapped into user-space page tables.
Mapped Files which have been mapped into memory (with mmap(2)), such as libraries.
Shmem Amount of memory consumed in tmpfs(5) filesystems.
KReclaimable Kernel allocations that the kernel will attempt to reclaim under memory pressure. Includes SReclaimable (below), and other direct allocations with a shrinker.
Slab In-kernel data structures cache. (See slabinfo(5).)
SReclaimable Part of Slab, that might be reclaimed, such as caches.
SUnreclaim Part of Slab, that cannot be reclaimed on memory pressure.
KernelStack Amount of memory allocated to kernel stacks.
PageTables Amount of memory dedicated to the lowest level of page tables.
NFS_Unstable NFS pages sent to the server, but not yet committed to stable storage.
Bounce Memory used for block device “bounce buffers”.
WritebackTmp Memory used by FUSE for temporary writeback buffers.
CommitLimit This is the total amount of memory currently available to be allocated on the system, expressed in kilobytes. This limit is adhered to only if strict overcommit accounting is enabled (mode 2 in /proc/sys/vm/overcommit_memory). The limit is calculated according to the formula described under /proc/sys/vm/overcommit_memory.
Committed_AS The amount of memory presently allocated on the system. The committed memory is a sum of all of the memory which has been allocated by processes, even if it has not been “used” by them as of yet. A process which allocates 1GB of memory (using malloc(3) or similar), but touches only 300MB of that memory will show up as using only 300MB of memory even if it has the address space allocated for the entire 1GB. This 1GB is memory which has been “committed” to by the VM and can be used at any time by the allocating application. With strict overcommit enabled on the system (mode 2 in /proc/sys/vm/overcommit_memory), allocations which would exceed the CommitLimit will not be permitted. This is useful if one needs to guarantee that processes will not fail due to lack of memory once that memory has been successfully allocated.
VmallocTotal Total size of vmalloc memory area.
VmallocUsed Amount of vmalloc area which is used. Since Linux 4.4, this field is no longer calculated, and is hard coded as 0. See /proc/vmallocinfo.
VmallocChunk Largest contiguous block of vmalloc area which is free. Since Linux 4.4, this field is no longer calculated and is hard coded as 0. See /proc/vmallocinfo.
LazyFree Shows the amount of memory marked by madvise(2) MADV_FREE.
AnonHugePages Non-file backed huge pages mapped into user-space page tables.
ShmemHugePages Memory used by shared memory (shmem) and tmpfs(5) allocated with huge pages
ShmemPmdMapped Shared memory mapped into user space with huge pages.
CmaTotal Total CMA (Contiguous Memory Allocator) pages.
CmaFree Free CMA (Contiguous Memory Allocator) pages.
HugePages_Total The size of the pool of huge pages.
HugePages_Free The number of huge pages in the pool that are not yet allocated.
HugePages_Rsvd This is the number of huge pages for which a commitment to allocate from the pool has been made, but no allocation has yet been made. These reserved huge pages guarantee that an application will be able to allocate a huge page from the pool of huge pages at fault time.
HugePages_Surap This is the number of huge pages in the pool above the value in /proc/sys/vm/nr_hugepages. The maximum number of surplus huge pages is controlled by /proc/sys/vm/nr_overcommit_hugepages.
Hugepagesize The size of huge pages.
DirectMap4k Number of bytes of RAM linearly mapped by kernel in 4kB pages.
DirectMap4M Number of bytes of RAM linearly mapped by kernel in 4MB pages.
DirectMap2M Number of bytes of RAM linearly mapped by kernel in 2MB pages.
DirectMap1G x86 with CONFIG_X86_64 and CONFIG_X86_DIRECT_GBPAGES enabled.

We can filter out the file using the grep command or egrep command as follows:
grep -E --color 'Mem|Cache|Swap' /proc/meminfo
Linux proc meminfo file

Using free command to check used and free memory utilization

The output of /proc/meminfo is powerful but not user friendly. Hence, we must use the free command. The free command shows amount of free and used memory in the Linux system. For instance:
Want to see human-readable output? Try:
free -h
free --human

Sample outputs:

              total        used        free      shared  buff/cache   available
Mem:           94Gi        15Gi       672Mi       428Mi        78Gi        77Gi
Swap:            0B          0B          0B
The displayed columns are as follows:
Column Description
total Total installed memory
used Used memory (calculated as total – free – buffers – cache)
free Unused memory (MemFree and SwapFree in /proc/meminfo)
shared Memory used mostly by tmpfs (Shmem in /proc/meminfo)
buffers Memory used by kernel buffers (Buffers in /proc/meminfo)
cache Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
buff/cache Sum of buffers and cache
available Estimation of how much memory is available for starting new applications, without swapping.

We can repeat printing free command output every N seconds. For example, print output every 5 seconds and exit after ten such repetitions (counts) on screen:
free -s 5 -c 10
We can control output of free command as follows:
free [option]
free -k
free -g
free -m

Controlling free command output [option]
Option Show output in
-b, --bytes bytes
--kilo kilobytes
--mega megabytes
--giga gigabytes
--tera terabytes
--peta petabytes
-k, --kibi kibibytes
-m, --mebi mebibytes
-g, --gibi gibibytes
--tebi tebibytes
--pebi pebibytes

vmstat command

The vmstat command is powerful, and it shows information about Linux hardware, such as:

  • Processes
  • Memory
  • Paging
  • Block IO
  • Traps
  • Disks
  • CPU activity

Open the terminal and type the following command:
Sample session from my Ubuntu Linux desktop:

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 11434840 2567516 10238916    0    0    26    75  142   55 13  5 82  0  0

Pass the -w to see wide output on screen:
vmstat -w

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     11405404      2567988     10324528    0    0    26    75  142   58  13   5  82   0   0
Field Description
swpd the amount of virtual memory used.
free the amount of idle memory.
buff the amount of memory used as buffers.
cache the amount of memory used as cache.
inact the amount of inactive memory. (-a option)
active the amount of active memory. (-a option)
si Amount of memory swapped in from disk (/s).
so Amount of memory swapped to disk (/s).

top and htop command

The top and htop commands provide a dynamic real-time view of a running Linux system. This includes information about:

  • Hardware and CPU utilization
  • Linux uptime
  • Memory and swap utilization
  • System processes and more

Please note that the htop is not installed by default. But you can install it on CentOS, Debian, Ubuntu, and other operating systems easily.

Run the following command:

Report memory usage with shared memory divided proportionally

The smem tool reports:

  • Physical memory usage taking shared memory pages into account. Unshared memory is reported as the USS (Unique Set Size).
  • Shared memory is divided evenly among the processes sharing that memory.
  • The unshared memory (USS) plus a process’s proportion of shared memory is reported as the PSS (Proportional Set Size).
  • The USS and PSS only include physical memory usage. They do not include memory that has been swapped out to disk.
  • Memory can be reported by a process, by a user, by mapping, or systemwide. Both text mode and graphical output are available.

One can install smem using the apt command/apt-get command on a Debian/Ubuntu Linux:
sudo apt install smem
Run it as follows:
# show whole system #
smem -w
# show meme usage about specifc user #
smem -u vivek
smem -u nginx
# get help #
man smem
smem --help

User     Count     Swap      USS      PSS      RSS 
vivek      139        0  7593240  8210344 13017360

Checking memory utilization in Linux using the GUI

System Monitor is a GUI Linux app that shows you what programs are running and how much processor time, memory, and disk space are being used. We can open the System Monitor from the Activities overview. Press the Super key on your keyboard. You can see your windows and applications in the overview. You can also just start typing to search your applications, such as System Monitor. The Resources tab tells you how much of your computer’s memory (RAM) is being used. To check which processes are using the most memory: Click the Processes tab. Click the Memory column header to sort the processes according to memory use.

See documentation for more info.

Summing up

You learned how to find Linux memory (RAM) utilization on Linux using GUI and CLI tools.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Robert Feb 25, 2021 @ 20:15

    Nice article, thank you for giving so detailed explanation.

    I often forget how to check this and this article helped me understand better the options I have.

  • Rafael Feb 26, 2021 @ 2:58

    Great article!!!

  • James Feb 26, 2021 @ 13:26

    Consider using instead of more or less as you can split the data into columns and sort it.

  • James Leon Feb 26, 2021 @ 15:25

    One switch I found useful on the ‘free’ command is:
    --si Use kilo, mega, giga etc (power of 1000) instead of kibi, mebi, gibi
    (power of 1024).

  • James Leon Feb 26, 2021 @ 15:29

    CORRECTION: On my comment above, it’s actually two dashes for “free –si” but it didn’t come through when I pasted it in and there is no edit link.

    Excellent article!

  • James Leon Feb 26, 2021 @ 15:37
    free -h --si
                  total        used        free      shared  buff/cache   available
    Mem:           3.7G        859M        1.9G        192M        977M        2.5G
    Swap:          511M          0B        511M


    man free
    --si   Use kilo, mega, giga etc (power of 1000) instead of kibi,  mebi,  gibi
                  (power of 1024).
  • Emilia Meyer Feb 27, 2021 @ 10:01

    Tolle Informationen. Ich schätze diese Seite.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum