ZRAM on Linux and Proxmox – More Performance

Diagram showing ZRAM usage in Linux and Proxmox to reduce disk I/O and improve system performance
Image source: ChatGPT
Table of Contents
  1. The problem: classic swap is slow
  2. Memory hierarchy: how fast is storage really?
  3. The solution: ZRAM
  4. Why ZRAM is so effective
  5. Especially useful in practice
  6. Docker and virtual machines
  7. Proxmox hosts
  8. Raspberry Pi and systems with SD cards
  9. Installation on Debian / Ubuntu
  10. Configuration
  11. Check the setup
  12. Remove the swapfile (recommended)
  13. Check ZRAM status
  14. Set swappiness deliberately
  15. Practical recommendations
  16. Conclusion
ZRAM is one of the simplest optimizations for Linux systems with limited memory. This article explains why compressed RAM often beats classic swap and when ZRAM is especially useful.

There are optimizations that cost nothing but noticeably improve stability and performance. For me, ZRAMZRAM is compressed memory that is used as a fast replacement for classic swap.

More in the IT glossary ->
belongs exactly in that category.

ZRAM is a Linux kernel module that creates compressed swap directly in memory (RAM).

I discovered it almost by accident on one of my systems and was surprised by how large the effect actually was.

The problem: classic swap is slow

Linux uses swap when physical RAM becomes scarce. Traditionally, this swap sits on an SSD or, in the worst case, on an SD card.

The problem: even fast SSDs are orders of magnitude slower than RAM.

Memory hierarchy: how fast is storage really?

Storage type Typical access time in nanoseconds (ns) Compared to RAM
CPU L1 cache ~1 ns 1 ~1/80
CPU L2 cache ~4 ns 4 ~1/20
CPU L3 cache ~15 ns 15 ~1/5
Memory (RAM) ~80 ns 80 1x (reference)
VRAM (GDDR) ~150 ns 150 ~2x
NVMe SSD ~50 µs 50.000 ~600x
SATA SSD ~100 µs 100.000 ~1.250x
SD / microSD card ~10 ms (1-50 ms) 10.000.000 ~125.000x+
Hard disk (HDD) ~8 ms (5-10 ms) 8.000.000 ~100.000x
CD / DVD ~120 ms (80-200 ms) 120.000.000 ~1.500.000x

These values are typical reference values and can vary depending on hardware and access pattern. The important part is the order of magnitude.

The consequences:

  • high latency
  • noticeable stutters
  • I/O wait
  • unnecessary write load on the storage device

The solution: ZRAM

ZRAM is compressed RAM that is used as swap.

Instead of writing data to a slow storage medium, it is stored compressed in RAM. This effectively creates “more RAM” without additional hardware.

Why ZRAM is so effective

The decisive advantage lies in the combination of:

  • very low latency (RAM instead of SSD)
  • compression (more usable memory)

Typical effect:

  • less I/O
  • longer SSD / SD card lifetime
  • faster than any swapfile
  • calmer system behavior
  • no noticeable hangs under load

Especially useful in practice

In practice, ZRAM does not have the same effect on every system. The benefit is especially strong where many processes run at the same time or memory becomes scarce for short periods.

Docker and virtual machines

On systems with many containers or virtual machines, such as Docker hosts or Proxmox systems, ZRAM is especially effective.

These systems often see short memory spikes:

  • containers start or are rebuilt
  • services scale for a short time
  • multiple systems access resources at the same time

ZRAM absorbs exactly these situations cleanly without forcing the system into slow I/O. The result is much more stable behavior under load.

Proxmox hosts

On Proxmox hosts, another effect comes into play: multiple VMs share the same physical memory.

If individual systems need more RAM for a short time, ZRAM prevents the host from falling back to slow disk swap and keeps all VMs running smoothly.

Raspberry Pi and systems with SD cards

On a Raspberry Pi, the benefit is almost even greater.

Classic swap often sits on an SD card, which is not only slow but also sensitive to many write operations.

ZRAM massively reduces that write load and creates a noticeably calmer system at the same time.

Especially on smaller Raspberry systems with little RAM, the difference is tangible.

Installation on Debian / Ubuntu

sudo apt update
sudo apt install zram-tools

Configuration

sudo vi /etc/default/zramswap

Recommended settings:

# Compression algorithm
ALGO=lz4

# RAM share (in percent)
# Example: 4 GB RAM → PERCENT=50 → 2 GB ZRAM
PERCENT=50

# High priority
PRIORITY=100

Then enable and start the service:

sudo systemctl enable zramswap
sudo systemctl restart zramswap

Check the setup

swapon --show

Example:

NAME       TYPE       SIZE USED PRIO
/dev/zram0 partition 15,6G 1,6G  100

A classic swapfile makes ZRAM unnecessary in many cases, or even slows things down.

sudo swapoff -a

Remove the entry from /etc/fstab:

/swapfile none swap sw 0 0

Then delete it:

sudo rm /swapfile

Check ZRAM status

zramctl

Here you can see, among other things:

  • ZRAM size
  • compressed data
  • used RAM
  • algorithm

Set swappiness deliberately

echo "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl -p /etc/sysctl.d/99-swappiness.conf

Practical recommendations

System Recommendation
Raspberry Pi ALGO=lz4
PERCENT=50
Definitely remove swapfile (SD card!)
Desktop / laptop ALGO=zstd possible
PERCENT=50-75
optional small swapfile as fallback
Server ZRAM useful under memory pressure
optionally keep a small swapfile
Docker / VM ALGO=zstd
PERCENT=40
PRIORITY=100
Proxmox host ALGO=zstd
PERCENT=25
PRIORITY=100

Especially on smaller systems like Raspberry Pi or Proxmox hosts, ZRAM can offer noticeable benefits – similar to optimizing your network infrastructure.

Even on existing systems, there is often still a lot of performance potential to unlock. These kinds of optimizations are a core part of my work with Catarix IT.

Conclusion

ZRAM is one of the simplest and most effective optimizations on Linux.

Especially on systems with limited RAM or high load, it creates noticeably calmer and more stable behavior without additional hardware and without downsides.

For me, ZRAM has become part of the standard configuration, whether on a Raspberry Pi, desktop or Proxmox host.

On systems with many containers or VMs, network infrastructure also matters. You can find a practical example here: Wi-Fi problems and airtime.

Was this article helpful?
(13 Likes)