Updated: 11 October 2026 · Applies to: Debian 13, Ubuntu 24.04 and 26.04, AlmaLinux 10, Rocky Linux 9 and Fedora 44 (procps-ng 3.3.17 to 4.0.6, htop 3.3 and 3.4, systemd 259)
To check memory usage in Linux, run free -h and look at the available column: that is the memory programs can still use. Linux fills spare RAM with disk cache (buff/cache) and hands it back as soon as a program needs it, so a small free figure is normal and not a problem. For a live view sorted by memory, run top and press Shift+M.
1. Check memory usage with free
$ free -h
total used free shared buff/cache available
Mem: 3.7Gi 621Mi 842Mi 71Mi 2.6Gi 3.1Gi
Swap: 1.2Gi 6.2Mi 1.2Gi
This is a lab example from our 4 GB test machine. Only 842 MiB is completely unused, but 3.1 GiB is available, because most of the 2.6 GiB cache can be released. What each column means, according to the free manual (procps-ng 4.0.4):
- total: usable RAM (and swap on the second line).
- used: used or unavailable memory, calculated as total minus available.
- free: memory nobody uses at all, not even the cache.
- shared: mostly tmpfs, such as
/dev/shmand a RAM-based/tmp. - buff/cache: kernel buffers, page cache and reclaimable slab. Add
-wto see buffers and cache in separate columns. - available: an estimate of how much memory new programs can get without swapping. Watch this one.
Useful options, all tested on Debian 13:
free -m # in MiB instead of auto units free -h -t # adds a Total line for RAM + swap free -h -s 2 -c 5 # print every 2 seconds, 5 times free -h -L # one line: SwapUse, CachUse, MemUse, MemFree free -h --si # powers of 1000 (4.0G) instead of 1024 (3.7Gi)
To get the percentage of memory in use (total minus available, divided by total):
$ free | awk '/Mem:/ {printf "%.1f%% used\n", ($2-$7)/$2*100}'
16.3% used
On minimal AlmaLinux, Rocky Linux and Fedora images, the shell answered free: command not found. Install it with sudo dnf install procps-ng (on Debian and Ubuntu the package is procps).
2. Read the raw numbers in /proc/meminfo
free, top and most monitoring tools read /proc/meminfo. You can read it yourself, which is handy in scripts:
$ grep -E 'MemTotal|MemFree|MemAvailable|^Cached|Buffers|Swap(Total|Free)' /proc/meminfo MemTotal: 3910520 kB MemFree: 863008 kB MemAvailable: 3273592 kB Buffers: 149344 kB Cached: 2185880 kB SwapTotal: 1228776 kB SwapFree: 1222428 kB
According to the Linux kernel documentation, MemAvailable is "an estimate of how much memory is available for starting new applications, without swapping", calculated from free memory, reclaimable slab, the file cache and the low watermarks. This one-liner prints the used percentage and the available memory from it:
$ awk '/MemTotal/ {t=$2} /MemAvailable/ {a=$2} END {printf "Used: %.1f%% Available: %.0f MiB\n", (t-a)/t*100, a/1024}' /proc/meminfo
Used: 16.3% Available: 3197 MiB
3. Watch memory live with top or htop
Run top. The two header lines show the same figures as free (avail Mem is the available column). Press Shift+M to sort processes by %MEM, and q to quit. For a one-off list, for example in a ticket or a script, use batch mode:
$ top -b -n 1 -o %MEM | head -5 top - 12:24:57 up 11 days, 5:55, 0 users, load average: 1.68, 1.99, 1.18 Tasks: 5 total, 1 running, 3 sleeping, 0 stopped, 1 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 3818.9 total, 842.8 free, 622.0 used, 2707.6 buff/cache MiB Swap: 1200.0 total, 1193.8 free, 6.2 used. 3196.9 avail Mem
In the process list, RES is the physical memory a process uses and VIRT is everything it has reserved, which is usually much larger and not a reason to worry. More options are in top command usage and examples.
htop shows the same with coloured memory bars. Install it with sudo apt install htop on Debian and Ubuntu, sudo dnf install htop on Fedora, and on AlmaLinux or Rocky Linux enable EPEL first (sudo dnf install epel-release). Press F6 to choose the sort column.
4. See memory trends and swapping with vmstat
$ vmstat -S M 1 3 procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu------- r b swpd free buff cache si so bi bo in cs us sy id wa st gu 0 0 6 842 145 2561 0 0 14 196 75 1 1 1 95 0 3 0 0 0 6 842 145 2561 0 0 0 0 81 154 0 0 100 0 0 0 0 0 6 842 145 2561 0 0 0 10624 309 701 3 7 81 2 7 0
This prints three reports one second apart, in MiB. The first line is the average since boot; the next lines show the current state. vmstat -S M 5 keeps printing every 5 seconds until you press Ctrl+C. swpd is swap in use; si and so are memory swapped in and out per second. Occasional non-zero values are fine, but if si and so stay above zero the server is short of RAM and will feel slow. vmstat -s -S M prints a summary list instead. See understand more about vmstat.
5. Check the memory usage of a process or service
- The ten processes using the most memory (RSS is in KiB):
ps -eo pid,user,%mem,rss,comm --sort=-rss | head -n 11
- One process by its PID:
$ ps -o pid,rss,vsz,%mem,cmd -p 5513 PID RSS VSZ %MEM CMD 5513 1408 2580 0.0 sleep 300 $ grep -E 'VmRSS|VmHWM|VmSwap' /proc/5513/status VmHWM: 1408 kB VmRSS: 1408 kB VmSwap: 0 kBVmHWMis the highest RSS the process has reached andVmSwapis how much of it is in swap. Find the PID withpgrep nginxorpidof nginx. - A whole service, including all its child processes (systemd counts the service's control group):
$ systemctl status cron --no-pager | grep Memory Memory: 356K (peak: 1.8M)systemd-cgtop -mlists all services sorted by memory. - RSS counts shared libraries in full for every process, so adding up RSS overstates the total. On Debian and Ubuntu,
smem(packagesmem) shows PSS, which divides shared memory fairly:smem -t -k.
For more ways to rank processes see find top running processes by memory and CPU usage and list running processes with ps, top, htop and pgrep.
6. Check swap and installed RAM
$ swapon --show NAME TYPE SIZE USED PRIO /dev/sda2 partition 1.2G 6.2M -2
No output means the server has no swap; see increase swap space with a swap file. To see the installed memory, sudo lshw -short -C memory printed 4GiB System memory in our test, while dmidecode -t memory needs access to real hardware and failed inside a container. On a VPS, total is the RAM of your plan; Virtualizor also shows it in the panel (view VPS details in Virtualizor).
Ubuntu desktop and containers
- Ubuntu desktop: the commands above work in Terminal. The graphical way is the System Monitor app, Resources tab, which draws a Memory and Swap graph (gnome-system-monitor 49 on Ubuntu 26.04).
- Docker or Podman containers:
freeinside a container shows the host's memory. In our test a container limited to 256 MB still showed 3.7Gi total. Read the limit and the real usage from the cgroup instead:cat /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory.current(bytes).
When memory runs out
If available memory falls close to zero and swap is full, the kernel's OOM killer stops a process to save the server. Check the kernel log for it:
sudo journalctl -k | grep -i "killed process"
According to the kernel source, the log line reads Out of memory: Killed process followed by the process ID and the program name. See what is the OOM killer. Then reduce the memory the services use, or move to a plan with more RAM. Clearing the cache by hand rarely helps, because Linux already gives cache back when programs need it; when it does make sense, see how to free up Linux memory safely.
Official documentation: free(1) and the /proc filesystem (meminfo).