HeadlinesBriefing favicon HeadlinesBriefing.com

Zswap vs Zram: Expert Advice on Linux Swap

Hacker News •
×

Linux memory management experts are clarifying widespread confusion regarding compressed swap mechanisms, strongly advising users to prefer zswap over zram for general desktop and server use. Zswap integrates directly into the kernel's memory management, offering compression in RAM before transparently tiering cold data to disk swap. This design allows the system to gracefully manage pressure and maintain hot data in faster storage.

Zram operates differently; it functions as a standalone, fixed-capacity compressed block device. When zram fills up, the kernel has little leverage, often forcing active working sets onto slow disk swap—a scenario worse than having no compression at all. This block device approach causes problems because the kernel applies disk-oriented assumptions, like aggressive read-ahead, which actively works against the locality of compressed pages in zram.

Developers utilizing zram alongside disk swap risk pushing active processes to slow storage while stale pages remain locked in fast, compressed RAM. For systems needing that absolute memory isolation, like specialized embedded setups, zram might fit, but generally requires an external OOM manager like systemd-oomd to prevent system hangs. On servers, zram memory usage breaks cgroup isolation because it isn't properly charged to any group.

Ultimately, the architectural difference dictates the recommendation: zswap provides automatic, intelligent tiering, whereas zram provides a hard capacity wall. Unless you have a specialized need, sticking with zswap avoids kernel behaviors that actively degrade performance by mismanaging page locality. Many online recommendations favoring zram for SSD wear reduction miss this performance pitfall, making zswap the safer default.