Monitoring memory usage on Linux keeps applications responsive and reduces the chance of sudden out-of-memory conditions that can terminate important services. Understanding how much RAM and swap space are in use makes it easier to troubleshoot slow systems, size workloads correctly, and spot memory leaks before they become critical.
The kernel exposes memory statistics through the /proc/meminfo interface and makes them available to tools such as free, top, htop, and vmstat. These utilities summarize total and available memory, show how much is used for page cache and buffers, and reveal whether the system is relying on swap space. Most of them are available by default on common Linux distributions.
Graphical utilities like GNOME System Monitor or KDE System Monitor provide similar information in a desktop-friendly way, but terminal-based tools remain the standard choice on servers and remote systems where no GUI is present. Reading memory statistics is safe, but some commands benefit from sudo access to see all processes, and high memory pressure visible in these outputs should be treated as a sign to optimize workloads or upgrade resources.
Related: How to check memory pressure in Linux
Related: How to clear memory usage in Linux
Steps to monitor memory activity in Linux:
- Open a terminal on the Linux system with an account that can run administrative commands when needed.
- Display overall memory usage using the free command.
$ free total used free shared buff/cache available Mem: 12235596 1282048 2062508 31420 9145720 10953548 Swap: 4194300 0 4194300This output summarizes physical RAM and swap, including memory used for page cache and buffers.
- View memory usage in a human-readable format.
$ free -h total used free shared buff/cache available Mem: 11Gi 1.2Gi 2.0Gi 30Mi 8.7Gi 10Gi Swap: 4.0Gi 0B 4.0GiThe -h option prints sizes in GiB and MiB, which is easier to interpret than raw kilobytes.
- Monitor real-time memory usage using the top command.
$ top top - 22:13:55 up 7 days, 20:53, 0 user, load average: 1.25, 0.62, 0.39 Tasks: 22 total, 1 running, 21 sleeping, 0 stopped, 0 zombie %Cpu(s): 7.3 us, 4.9 sy, 0.0 ni, 86.6 id, 0.0 wa, 0.0 hi, 1.2 si, 0.0 st MiB Mem : 11948.8 total, 2047.4 free, 1218.7 used, 8931.4 buff/cache MiB Swap: 4096.0 total, 4096.0 free, 0.0 used. 10730.1 avail Mem
Press q to exit top; the MiB Mem line shows total, free, used, and cached memory in real time.
- Run htop for an interactive, colorized view of per-process memory usage.
$ htop
htop presents CPU and memory meters at the top and allows sorting by columns such as RES and VIRT using function keys.
- Check detailed memory statistics from the kernel using the /proc file system.
$ cat /proc/meminfo MemTotal: 12235596 kB MemFree: 2098164 kB MemAvailable: 10989204 kB Buffers: 552040 kB Cached: 7682940 kB ##### snipped #####
Fields such as MemTotal, MemAvailable, Buffers, and Cached explain how physical memory is divided between applications and cache.
- View memory and paging activity using the vmstat command.
$ vmstat -s 12235596 K total memory 1219756 K used memory 1512796 K active memory 7425304 K inactive memory 2124800 K free memory ##### snipped #####vmstat adds information about swap and paging, which helps detect thrashing and sustained swap activity.
- Sort running processes by memory usage using the ps command.
$ ps aux --sort=-%mem | head USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 23 0.0 0.1 83888 23280 ? S<s 14:01 0:00 /usr/lib/systemd/systemd-journald root 1 0.0 0.1 21740 12688 ? Ss 14:01 0:04 /sbin/init ##### snipped #####
Sorting by %MEM surfaces the heaviest consumers of RAM so that tuning can focus on the most demanding processes.
- Compare MemTotal from /proc/meminfo with totals reported by free or top to confirm that memory statistics are consistent.
$ grep MemTotal /proc/meminfo MemTotal: 12235596 kB
A small difference between tools is normal due to rounding and units, but large discrepancies can indicate measurement misunderstandings such as including or excluding cache.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
