---
title: "Linux memory compression explained: kernel engineer Chris Down says use zswap before buying more RAM"
url: https://badiyaa.com/linux-zswap-zram-memory-compression-explained/
published: 2026-11-20T05:44:00+00:00
modified: 2026-11-20T05:44:00+00:00
section: Tech
publisher: Badiyaa
---

# Linux memory compression explained: kernel engineer Chris Down says use zswap before buying more RAM

Linux kernel engineer Chris Down says zswap beats zram for most PCs, compressing idle memory in RAM and spilling cold pages to disk when the pool fills.

Before paying for another stick of RAM, a Linux PC can squeeze more out of the memory it already has. The kernel ships two built-in tools that compress data in memory instead of throwing it to disk, and the engineer who has spent close to a decade on that code says most people are picking the wrong one.

“If in doubt, prefer to use zswap. Only use zram if you have a highly specific reason to,” Chris Down, who works on kernel memory management and swap, wrote in [his own explainer on zswap and zram myths](https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html).

## How memory compression works

When a computer runs low on RAM, the kernel moves pages it has not touched recently out to swap space on the disk. Reading them back from an SSD is far slower than reading RAM. Compression offers a middle tier: shrink those idle pages and keep them in memory, so a 4 KB page might occupy a fraction of that space and come back in microseconds rather than a trip to storage.

The cost is processor time. Every page has to be compressed on the way in and decompressed on the way out. The [Linux kernel’s zswap documentation](https://docs.kernel.org/admin-guide/mm/zswap.html) describes the deal plainly: zswap “trades CPU cycles for potentially reduced swap I/O.”

## zram and zswap, side by side

The two tools sound alike but sit in very different places inside the kernel:

- **zram** creates a block device that lives in RAM. Anything written to it is compressed and kept in memory, and it can be formatted as swap or even used for /tmp. According to the [kernel’s zram documentation](https://docs.kernel.org/admin-guide/blockdev/zram.html), there is little point making one more than twice the size of physical memory, because it expects roughly a 2:1 compression ratio.

- **zswap** is a compressed cache that sits in front of an ordinary disk swap file or partition. Pages headed for disk are caught, compressed and held in a RAM pool. When that pool hits its size limit, the oldest pages are pushed on to the disk.

That last step is the heart of Down’s argument. A full zram device has nowhere to send cold data, so if it is paired with disk swap at a lower priority, the earliest and often least useful pages stay stuck in fast compressed RAM while newer, busier pages spill to the slow disk. He calls this LRU inversion, after the least-recently-used lists the kernel keeps.

## What the numbers show

Down gives one production example from his work at Meta. On Instagram’s Django servers, moving from no swap to disk swap with zswap in front produced roughly 5:1 compression and cut disk writes by up to 25% compared with running no swap at all. He cautions that the workload suits zswap unusually well.

The kernel documents back the SSD point too: the zswap page lists extending the life of SSDs used as swap by “drastically reducing life-shortening writes” as one of its benefits.

## When zram still makes sense

zram is not useless. Down points to embedded boards with no disk, such as a Raspberry Pi running from an SD card, and to fully diskless setups. Android runs zram on billions of phones, paired with its own low-memory killer. Fedora also defaults to zram-only swap, partly to keep passwords and keys off persistent storage, and pairs it with systemd-oomd.

His practical advice for anyone who does run zram is to avoid mixing it with disk swap and to add a userspace out-of-memory manager such as systemd-oomd or earlyoom, because the kernel’s own OOM killer can leave a machine hung for minutes.

## Trying it on a desktop

On most distributions zswap can be switched on at runtime by writing 1 to /sys/module/zswap/parameters/enabled, and the max_pool_percent setting caps how much RAM the compressed pool may use. Disk swap must exist for zswap to do anything.

For more on how Linux handles memory, see our coverage of [the Ram-Altman script that reports unused RAM on Linux PCs](https://badiyaa.com/ram-altman-script-email-sam-altman-unused-ram/) and [Linus Torvalds on the Linux 7.4-rc1 merge window](https://badiyaa.com/linus-torvalds-linux-74-ai-fixes/).

## Sources

- [Debunking zswap and zram myths](https://chrisdown.name/2026/03/24/zswap-vs-zram-when-to-use-what.html), Chris Down (author’s own blog), 2026

- [zram: Compressed RAM-based block devices](https://docs.kernel.org/admin-guide/blockdev/zram.html), The Linux Kernel documentation, 2026

- [zswap](https://docs.kernel.org/admin-guide/mm/zswap.html), The Linux Kernel documentation, 2026

*Image: Bretwa, CC BY-SA 4.0 via Wikimedia Commons*

*This article was produced with AI assistance and reviewed by our Editorial Desk. [How we work](https://badiyaa.com/editorial-policy/).*
