Operations 6 min read

Boost Linux Performance with zSwap, zRAM, and zstd Compression

Memory compression techniques like Linux's zSwap, zRAM, and the zstd algorithm reduce I/O latency and extend RAM capacity by compressing swap pages, offering performance gains while introducing trade‑offs such as CPU overhead and configuration complexity, and this guide explains their principles, advantages, drawbacks, and activation steps.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Linux Performance with zSwap, zRAM, and zstd Compression

Compression reduces space usage; memory compression specifically compresses RAM to save space. Because I/O is much slower than RAM, frequent I/O operations affect flash lifespan and system performance. Memory compression smooths I/O transitions, improving performance.

Introducing zSwap Technology

zSwap

is a Linux kernel feature that provides a compressed write‑back cache for swapped pages. Instead of moving pages to a swap device, zSwap compresses them and stores them in a dynamically allocated RAM pool, delaying or avoiding writes to the swap device and reducing I/O at the cost of extra CPU cycles for compression. zSwap allows Linux to use RAM more efficiently, effectively increasing memory capacity without significantly increasing CPU usage. It exists in the kernel but is disabled by default; enabling it requires modifying configuration files.

Main Memory Compression Techniques

zSwap – A compressed cache between memory and flash that grows on demand and evicts pages using LRU order when the pool is full.

zRAM – Creates a compressed block device that resides entirely in RAM; because compression/decompression is faster than I/O, it is widely used on mobile devices. However, its size must be configured, and heavy compression can increase CPU usage and affect memory fragmentation.

zCache – Proposed by Oracle, it compresses file pages between memory and block devices, similar to zSwap but focuses on file pages rather than anonymous pages.

Introducing zstd Compression Algorithm

Zstandard

(zstd) is a real‑time compression algorithm offering high compression ratios with fast decoding. It supports a wide range of speed/compression trade‑offs and provides dictionary compression for small data. The library is open‑source under the BSD license.

How to Enable zSwap

# edit grub as root
sudo vim /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash zswap.enabled=1 zswap.compressor=zstd zswap.zpool=z3fold"

# update grub
sudo update-grub

# install zstd and Z3fold
sudo apt install checkinstall build-essential
sudo apt install zstd   # not the latest version

# edit the modules file
sudo vim /etc/initramfs-tools/modules
... 
zstd
zstd_compress
z3fold

# update initramfs
sudo update-initramfs -u -k all

# restart PC and verify ZSWAP is enabled
cat /sys/module/zswap/parameters/enabled
# should output Y

# verify ZSWAP uses zstd and z3fold
sudo dmesg | grep -i zswap:
[    1.059997] zswap: loaded using pool zstd/z3fold

Reference Links

Improving Elementary OS Performance using ZSWAP, zstd and z3fold

Linux 内存压缩浅析之原理

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxzstdsystem performancezRAMmemory compressionzSwap
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.