Skip to content

Free memory

Terminal window
free -h
total used free shared buff/cache available
Mem: 15Gi 5.2Gi 1.1Gi 412Mi 9.3Gi 9.6Gi
Swap: 4.0Gi 0B 4.0Gi
Column Meaning
total Installed RAM visible to the kernel
used Memory in use by processes
free Memory not used for anything at all
shared Mostly tmpfs and shared memory
buff/cache Disk cache and buffers; the kernel frees it when needed
available How much memory new processes can really get

Refreshing every 2 seconds:

Terminal window
free -h -s 2
Terminal window
grep -E 'MemTotal|MemAvailable|SwapTotal|SwapFree' /proc/meminfo
Terminal window
ps aux --sort=-%mem | head -10

The RSS column is the physical memory each process is actually using, in KB.

In top, press Shift + M to sort by memory. htop, if installed, does the same in a friendlier way.

Terminal window
vmstat 1 5

Watch the si and so columns (swap in / swap out). If they stay above 0 all the time, the machine is short of RAM and is moving memory to disk, which is slow.

To see the swap devices and how much of each is in use:

Terminal window
swapon --show

When memory runs out, the kernel’s OOM killer terminates a process. It leaves a trace in the kernel log:

Terminal window
sudo dmesg -T | grep -i -E 'out of memory|killed process'
# or, on systems with systemd:
sudo journalctl -k | grep -i -E 'out of memory|killed process'
  • man free, man vmstat, man proc (the /proc/meminfo section)