Swap Management & Tuning
Swap partitions vs swapfiles, swappiness tuning, zswap, and why swap matters even with large RAM on modern Linux systems.
Overview
Swap is disk space used as an overflow for RAM. Linux uses swap not only when RAM is exhausted but also proactively to free RAM for file cache — controlled by the swappiness kernel parameter.
Types of Swap
- Swap partition — dedicated partition, kernel writes directly (slightly faster)
- Swap file — regular file on any filesystem (on ext4/XFS; btrfs has restrictions). Flexible, resizable without partition tools.
- zswap — a compressed in-RAM cache for swap pages. Compresses pages before writing to disk, reducing I/O. Transparent to applications.
Key concepts
- swappiness
- Anonymous memory
- zswap
- Swap priority
Interview questions
- Why should you have swap enabled even on a server with 256GB of RAM, and how do you tune it to minimize latency impact?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio