$linuxjunkies
>

zswap

zswap is a Linux kernel feature that compresses pages before writing them to swap, reducing I/O and improving performance when physical memory is exhausted.

zswap intercepts pages destined for the swap device and compresses them in-memory using a compression algorithm (like LZ4 or zstd) before storing them. This creates a compressed memory pool that sits between RAM and disk swap, dramatically reducing the amount of disk I/O needed when the system runs out of physical memory.

When a compressed page is needed again, zswap decompresses it directly from this in-memory pool—much faster than reading from disk. Only when the compressed pool fills up do pages spill to actual disk swap. This is particularly valuable on systems with limited RAM or heavy workloads.

Example: on a system with 4GB RAM running memory-intensive tasks, zswap might compress 1GB of swap data down to 200–300MB in memory, avoiding costly disk access. You enable it via kernel parameters: zswap.enabled=1 at boot.

Related terms