Part II · Your system
17. Memory
hub
How much RAM you have, who is using it, and why "used" doesn't mean what you think.
On your machine
$ atfq memory RAM 10.5 GiB available of 15.5 GiB (68%) · 1.1 GiB completely free Cache 7.5 GiB in buff/cache, 604.0 MiB of it shared (tmpfs) Swap 256.0 MiB used of 8.0 GiB · swappiness 60
An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.
Commands
free -h- RAM and swap, in human units 17.1
vmstat 1- memory and swap activity every second (Ctrl-C stops)
top -o %MEM- processes sorted by memory use
swapon --show- swap areas and how full they are 17.3
sudo dmesg | grep -i oom- recent work of the OOM killer 17.2
Paths
/proc/meminfo- the kernel's memory counters, read by free and top
/proc/sys/vm/swappiness- how willing the kernel is to swap
/proc/PID/status- memory of one process (VmRSS line)
Cards
- 17.1free vs availablefree: memory nobody is using at all, not even as cache.
- 17.2The OOM killerWhen RAM and swap are both used up, the kernel's OOM ("out of memory") killer picks a process and kills it to get memory back.
- 17.3Swap and swappinessSwap is disk space the kernel uses as overflow for RAM: app memory that is rarely touched moves there.
- 17.4The page cacheThe page cache keeps file data in RAM after it has been read or written, so the next access doesn't touch the disk.
Also about this
- 1.3How virtual memory worksEvery process sees its own memory, as if it were alone: the addresses it uses are virtual.
- 3.1RAM and the memory hierarchyEvery level trades size for speed. Rough orders of magnitude: registers under 1 ns, L1 1 ns, L2 4 ns, L3 15 ns, RAM 100 ns, NVMe SSD tens of µs, network to another continent 100 ms.