How to Check Memory Usage in Linux

When troubleshooting system or application slowdown or misbehavior, one of the first things to check is the system memory usage.
This article explains how to check RAM and swap usage in Linux, and how to find the processes behind it.
Quick Reference
| Command | Description |
|---|---|
free -h | Show memory usage in human-readable format |
free -m | Show memory usage in mebibytes |
free -g | Show memory usage in gibibytes |
free -s 5 | Refresh memory stats every 5 seconds |
ps aux --sort=-%mem | List processes by memory use, heaviest first |
cat /proc/meminfo | Show detailed memory information |
sudo ~/.local/bin/ps_mem | Show per-program RAM usage after a pipx install |
free Command
free
is the most commonly used command for checking the memory usage of a Linux system. It displays information about the total, used, and free memory.
The most common flags are -h (human-readable), -m (mebibytes), and -g (gibibytes). All of them count in powers of 1024, so add --si when you want powers of 1000 instead.
To print memory usage in human-readable format:
free -h total used free shared buff/cache available
Mem: 7.8Gi 4.3Gi 289Mi 412Mi 3.6Gi 3.4Gi
Swap: 2.0Gi 256Mi 1.8GiTo show memory in mebibytes:
free -m total used free shared buff/cache available
Mem: 7937 4435 289 412 3688 3502
Swap: 2048 256 1792To show memory in gibibytes:
free -g total used free shared buff/cache available
Mem: 7 4 0 0 3 3
Swap: 2 0 1Notice that the free column now reads 0 although the previous command reported 289 MiB. The -g option rounds down to whole gibibytes, so anything below 1 GiB disappears. Use free -m or free -h whenever the numbers are small.
Here is what each column means:
- total - The total amount of memory that can be used by the applications.
- used - Used or unavailable memory, calculated as
total - available. Becauseavailableis an estimate that includes free memory and memory expected to be reclaimable,used,free, andbuff/cacheare not separate buckets. - free - Free / Unused memory.
- shared - Memory used mostly by
tmpfsfilesystems and shared memory segments, reported asShmemin/proc/meminfo. - buff/cache - The combined memory used by kernel buffers, the page cache, and reclaimable slabs. Much of this memory can be reclaimed when applications need it, but not all of it is immediately available.
- available - An estimate of the memory that is available for starting new applications, without swapping.
The free command prints information for the physical memory and the system swap
.
top Command
top
is a command-line utility that displays real-time information about the running processes. It also shows the system summary, including memory usage.
To invoke the command simply type top:
topThe header of the output includes information about the system’s total, free, and used physical and swap memory.
The %MEM column shows the percentage of total physical memory occupied by each process’s resident memory. Press Shift+M while top is running to sort the process list by that column. If you prefer a colored, scrollable interface with mouse support, htop
presents the same figures.
Finding the Processes Using the Most Memory
The system summary tells you that memory is tight, but not what is holding it. To get that answer without opening an interactive tool, sort ps
output by the %MEM column and keep the first few lines:
ps aux --sort=-%mem | head -n 6USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mysql 1184 1.7 14.2 2317048 1155284 ? Ssl Aug28 92:41 /usr/sbin/mysqld
redis 902 0.6 5.9 1013264 479512 ? Ssl Aug28 33:12 /usr/bin/redis-server
www-data 2317 0.0 1.3 412880 108964 ? S 09:14 0:02 php-fpm: pool www
root 771 0.0 0.6 1638420 52104 ? Ssl Aug28 4:55 /usr/bin/containerd
root 1 0.0 0.1 168404 11228 ? Ss Aug28 1:38 /sbin/initThe minus sign in --sort=-%mem reverses the order, so the heaviest process comes first. RSS is the resident set size in kibibytes, the part of the process that is actually in RAM, while VSZ counts everything the process has mapped, including memory it has never touched. Here mysqld holds 1.1 GiB of resident memory and 14.2 percent of the total, which makes it the first thing to look at.
Once you have a PID, the VmRSS entry in /proc/PID/status provides another estimate of its resident memory:
grep VmRSS /proc/1184/statusVmRSS: 1155284 kBThe kernel documents VmRSS as an approximate value, and it can differ slightly from ps if the process allocates or releases memory between reads.
One caveat: RSS counts shared libraries in full for every process that maps them, so adding the column up across a process list overstates the real total. When several copies of the same program are running, the ps_mem script covered below gives a better estimate.
/proc/meminfo
The free command and the system memory summary in top read /proc/meminfo. Process-level figures shown by ps, top, and ps_mem come from files under /proc/PID/. Reading /proc/meminfo directly gives you far more system-wide detail than free prints, at the cost of having to interpret the raw fields yourself.
Use less
or cat
to view the contents of the /proc/meminfo file:
cat /proc/meminfoThe file includes a large amount of information about the system memory and swap usage:
MemTotal: 8127488 kB
MemFree: 295936 kB
MemAvailable: 3586048 kB
...The values are in kibibytes and the format is plain text, which makes the file easy to parse in shell scripts. For the same numbers already labeled and summed, vmstat -s
prints a report built from this file.
Keep in mind that MemTotal is the memory the kernel can hand out, which is a little less than the RAM fitted in the machine. When the question is about the hardware itself, how many modules are installed and how large each one is, lshw and dmidecode
read that from the firmware.
ps_mem Script
ps_mem
is a Python script that reports per-program RAM memory usage. It works with both Python 2 and 3. On Ubuntu 23.04 and later, install it with pipx to avoid conflicts with the system Python environment:
pipx install ps_memOn older releases that do not mark the system Python as externally managed, pip3 still works:
sudo pip3 install ps_memFor a full system report, run the pipx executable with administrator privileges. Use its full path because sudo usually does not include ~/.local/bin in its command search path:
sudo ~/.local/bin/ps_memIf you installed it system-wide with pip3, use sudo ps_mem instead.
The output will include the memory usage of each running program in ascending order:
Private + Shared = RAM used Program
...
11.9 MiB + 20.2 MiB = 32.1 MiB nginx (4)
8.2 MiB + 42.4 MiB = 50.6 MiB systemd-journald
55.8 MiB + 307.2 MiB = 363.0 MiB php-fpm8.3 (6)
233.9 MiB + 234.0 MiB = 467.9 MiB redis-server
578.2 MiB + 578.6 MiB = 1.1 GiB mysqld
---------------------------------
2.2 GiB
=================================This script is useful when you want to find out which running program is taking most of your system memory.
Troubleshooting
Why does free -g show 0 GB free?
The -g option rounds values down to whole gibibytes. If less than 1 GiB is free, the column shows 0. Use free -m or free -h for more precise output.
sudo ps_mem returns “command not found”pipx installs the script into ~/.local/bin, and sudo replaces your PATH with the secure_path value from /etc/sudoers, which usually does not include that directory. Call the script by its full path instead, with sudo ~/.local/bin/ps_mem.
Installed RAM does not match the total shown by Linux
A small portion of physical memory is reserved by the kernel, firmware, integrated graphics, or hardware devices. That is why the reported total can be slightly lower than the RAM installed in the system.
FAQ
What is the difference between free and available in free output?free is the amount of completely unused memory. available is an estimate of how much memory can be used for new applications without swapping. It includes memory that is currently used for buffers and cache but can be reclaimed quickly.
Why does Linux show very little free memory?
Linux uses spare memory for disk caching to speed up file access. Much of the memory shown in buff/cache can be reclaimed when applications need it. The available column estimates how much memory can be used without swapping and gives a more useful picture than free alone.
How do I check the memory usage of a specific process?
Use ps
with the --pid flag: ps -o pid,rss,comm -p PID. The rss field shows the resident set size in kibibytes. For a broader view of all processes, sudo ~/.local/bin/ps_mem groups them by program name when installed with pipx.
How do I check swap usage?
The free command shows total swap usage in the Swap: row. Use swapon --show to list each active swap file or device and its usage. For one process, run grep VmSwap /proc/PID/status; this value is approximate and does not include swapped shared memory.
Conclusion
The free command answers the overview question in one line, ps aux --sort=-%mem names the process behind it, and /proc/meminfo holds the detail you need when scripting against it.
Before you add RAM or a swap file
because free reports almost nothing free, read the available column first. It accounts for memory the kernel expects it can reclaim without swapping.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page