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.
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: 2013428 999352 113610 6188 900376 842184 Swap: 969960 524 969436This 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: 1.9Gi 976Mi 111Mi 6.0Mi 879Mi 822Mi Swap: 947Mi 0.0Ki 946MiThe -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 - 16:25:49 up 40 min, 2 users, load average: 0.08, 0.23, 0.34 Tasks: 281 total, 1 running, 280 sleeping, 0 stopped, 0 zombie %Cpu(s): 5.9 us, 17.6 sy, 0.0 ni, 76.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 1966.2 total, 108.4 free, 975.9 used, 881.9 buff/cache MiB Swap: 946.9 total, 0.5 used, 946.4 free. 842.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: 15712000 kB MemFree: 10035200 kB MemAvailable: 12567000 kB Buffers: 210000 kB Cached: 1800000 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 15712000 K total memory 2350500 K used memory 9847200 K active 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 1234 5.1 10.5 123456 23456 ? Ssl 10:00 2:30 process1 ##### 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: 2013428 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.
Comment anonymously. Login not required.
