Server
Swap
Swap is disk space the operating system uses as overflow for memory. It prevents some crashes, and everything that touches it gets much slower.
How it is measured
Read `free -m` and `vmstat 1`. The numbers to watch are swap used, and the `si` and `so` columns, which show pages moving in and out per second. A steady non-zero `so` means the system is actively pushing memory to disk.
Used swap alone is not alarming, since old idle pages can sit there. Constant swap-in and swap-out while requests are served is thrashing.
Worked example
A 2 GB VPS runs MariaDB, PHP-FPM with 12 workers and Redis. Memory fills during a crawl at 11:00, and swap climbs to 900 MB. Database reads that took 2 ms now take 80 ms, because parts of the buffer pool were pushed to a disk with 300 IOPS.
TTFB moves from 250 ms to 6 seconds. Reducing PHP-FPM to 6 workers frees 500 MB, swap-out falls to zero, and the site recovers without a reboot.
How it differs
Swap is memory pushed onto disk to make room. Out of memory is what happens when even that runs out and something is killed. Swap excludes the kill but not the slowness. OOM excludes the gradual slowdown. Disk I/O is the underlying cost, since every swapped page is a read or write on the same device.
Common errors
Treating a swap-heavy server as healthy because it has not crashed. Disabling swap entirely and inviting abrupt kills. Putting swap on a slow shared volume. Setting swappiness without measuring. Adding swap instead of fixing the process that grew.
In practice
Graph swap-out per second and alert when it stays above zero for 5 minutes. Cap worker counts so the sum of process sizes fits in RAM, and keep a small swap file only as a cushion.