Linux memory figures often alarm newcomers because "free" looks tiny. Usually that is healthy.
free
$ free -h
total used free shared buff/cache available
Mem: 7.7Gi 2.9Gi 400Mi 200Mi 4.4Gi 4.5Gi
Swap: 2.0Gi 0B 2.0Gi-h prints human-readable units.
freeis memory not used for anything at allbuff/cacheis memory holding file data and kernel buffers, much of which can be reclaimedavailableestimates how much new programs could use without swapping
Look at available, not free. The kernel uses spare memory as cache to avoid slow disk reads, and gives it back when programs need it.
The same figures are in /proc/meminfo:
$ grep -E 'MemTotal|MemAvailable' /proc/meminfo
MemTotal: 8039212 kB
MemAvailable: 4718592 kBSwap
Swap is disk space the kernel can use to hold memory pages that do not fit in RAM. Some swap in use is not a problem by itself. Constant movement is. Run:
vmstat 1 5The si and so columns show memory swapped in and out per second. Values that stay well above zero, together with low available memory, mean the system is short of RAM. swapon --show lists the swap areas.
Who is using it
$ ps -eo pid,rss,vsz,comm --sort=-rss | head -3
PID RSS VSZ COMMAND
1893 512300 3401220 firefox
912 168000 2201000 dockerdRSS (resident set size) is the physical memory the process has in RAM, in KiB. VSZ is all the address space it has mapped, much of which may never be used. Shared pages count in the RSS of each process, so adding the column up overstates the total.
When memory runs out
If the kernel cannot free enough memory, the OOM killer (out of memory) ends a process to recover. If a program vanishes unexpectedly, check the kernel log:
sudo dmesg | grep -i 'out of memory'On systemd machines, journalctl -k shows kernel messages too.
Try it
Run free -h and note free and available. Press M in top to find your biggest processes. The processes and cron lab is a place to try these commands.
Check your understanding
Monitoring memory
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.