Free memory
Quick look
Section titled “Quick look”free -h total used free shared buff/cache availableMem: 15Gi 5.2Gi 1.1Gi 412Mi 9.3Gi 9.6GiSwap: 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:
free -h -s 2Straight from the kernel
Section titled “Straight from the kernel”grep -E 'MemTotal|MemAvailable|SwapTotal|SwapFree' /proc/meminfoWhich processes are using it
Section titled “Which processes are using it”ps aux --sort=-%mem | head -10The 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.
Is the machine swapping?
Section titled “Is the machine swapping?”vmstat 1 5Watch 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:
swapon --showWas a process killed for lack of memory?
Section titled “Was a process killed for lack of memory?”When memory runs out, the kernel’s OOM killer terminates a process. It leaves a trace in the kernel log:
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'See also
Section titled “See also”man free,man vmstat,man proc(the/proc/meminfosection)