free shows how much RAM and swap a Linux system is using. The output is simple, but it’s also the most misread command in Linux: “my server has only 200 MB free!” is usually perfectly healthy. Here’s how to read it.
Basic usage
free -h
total used free shared buff/cache available
Mem: 3.8Gi 1.4Gi 214Mi 52Mi 2.2Gi 2.1Gi
Swap: 2.0Gi 30Mi 2.0Gi
- total — installed RAM visible to the OS.
- used — memory used by processes (calculated as total − free − buff/cache).
- free — completely unused memory.
- shared — mostly
tmpfs(RAM-backed filesystems). - buff/cache — memory Linux uses to cache files and filesystem metadata.
- available — an estimate of how much memory new applications can use without swapping, including cache that can be dropped.
“Free” is not the number to watch — “available” is
Linux deliberately uses spare RAM as disk cache: recently read files stay in memory, making the next read much faster. When an application needs memory, the kernel drops cache instantly. So:
- Low free + high buff/cache + healthy available = normal, efficient.
- Low available (below roughly 10% of total) = real memory pressure.
In the example above, only 214 MB is “free”, but 2.1 GB is available. The server is fine.
Units and options
free -m # megabytes
free -g # gigabytes (rounded down — often misleading)
free -h # human-readable, best for reading
free -h -t # add a total line (RAM + swap)
free -h --si # powers of 1000 instead of 1024
Watch it over time
free -h -s 5 # refresh every 5 seconds
watch -n 2 free -h
Swap
Some swap usage isn’t a problem: the kernel moves rarely used pages out to make room for cache. What matters is activity — pages constantly moving in and out:
vmstat 5
Watch the si (swap in) and so (swap out) columns. Sustained non-zero values mean the system doesn’t have enough RAM for its workload, and performance suffers. See vmstat and Linux swap usage.
No swap at all (Swap: 0B) on a small server? Adding a swap file protects against out-of-memory crashes during spikes — see swap file vs partition.
Which processes use the memory?
free shows totals only. To see consumers:
ps aux --sort=-%mem | head -15
Or interactively with top (press M to sort by memory) or htop. Note that the RSS of processes sharing libraries or PHP-FPM workers sharing memory can add up to more than physical RAM — shared pages are counted in each.
Summarise per program:
ps -eo rss,comm --sort=-rss | awk 'NR>1 { m[$2] += $1 } END { for (p in m) printf "%8.0f MB %s\n", m[p]/1024, p }' | sort -rn | head
The out-of-memory killer
When available memory and swap run out, the kernel’s OOM killer terminates a process — often the largest, frequently the database. Check whether it has happened:
sudo journalctl -k | grep -iE "out of memory|killed process"
sudo dmesg -T | grep -i oom
If it has, see Linux OOM killer for how to respond.
Where the numbers come from
free reads /proc/meminfo, which has much more detail:
grep -E 'MemTotal|MemAvailable|Cached|SwapTotal|SwapFree|Dirty|Slab' /proc/meminfo
Slab (kernel object caches) can be large on file servers with many files; SReclaimable within it is reclaimable like page cache.
Dropping caches (rarely useful)
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
This empties the page cache, making “free” look bigger — and making the next disk reads slower. It’s useful for benchmarking cold-cache performance, not as a “memory cleaner”. Don’t put it in cron.
Is my server short on RAM?
Signs that it is:
- available consistently under ~10–15% of total at normal load;
- constant swap in/out in
vmstat; - OOM killer messages;
- services restarting unexpectedly.
Then reduce usage (fewer PHP/app workers, smaller database buffers, caching) or add RAM — see how much RAM your VPS needs.
Quick reference
| Task | Command |
|---|---|
| Human-readable | free -h |
| Refresh every N s | free -h -s N |
| Swap activity | vmstat 5 |
| Top memory users | ps aux --sort=-%mem | head |
| OOM events | journalctl -k | grep -i oom |
| Full details | cat /proc/meminfo |
Related: top, htop and CPU and RAM monitoring. Our VPS plans range from 2 GB to 40 GB of RAM in USA, Hong Kong and Japan.