Lesson 11 of 19 ↓
- 1.Fedora + Distrobox + Arch + AUR Setup Guide
- 2.Enabling Hibernate on Linux
- 3.A Practical Git Workflow
- 4.Useful Linux Commands & Tips
- 5.Mirroring Your Android Screen with Scrcpy
- 6.Downloading Media with Yt-dlp
- 7.Consistent C/c++ Style with Clang-format
- 8.Auto-mounting Drives at Boot
- 9.Customizing Grub
- 10.Linux Swap Files Explained
- 11.Zram: Compressed Swap in Ram
- 12.Custom App Launch Behavior Via .desktop Files
- 13.Custom Mime Icons in Gnome
- 14.Fixing Missing Dock Icons (startupwmclass)
- 15.Installing Questasim for Hdl Simulation
- 16.Building Python 2 From Source
- 17.Auto-Starting WhatsApp and Telegram (Minimized or Tray)
- 18.Custom Neovim Configuration Guide
- 19.Running Windows Applications on Linux Seamlessly with WinBoat (Docker)
2 min read
Zram: Compressed Swap in Ram
zram creates a compressed block device that lives entirely in RAM and is typically used as swap. Because it's RAM-backed and compressed, swapping to it is far faster than swapping to disk — it buys extra headroom under memory pressure without the latency hit of a real disk-backed swap file (see the swap-file lesson in this track for the disk-backed alternative).
Install
Ubuntu/Debian uses zram-tools:
sudo apt install zram-tools
sudo systemctl enable --now zramswap.serviceFedora uses systemd-zram-generator instead:
sudo dnf install zram-generatorFedora may already ship a default zram config — creating a config file overrides those defaults.
Configure
Ubuntu/Debian (/etc/default/zramswap):
sudo nvim /etc/default/zramswap# Compression algorithm
# speed: lz4 > zstd > lzo
# compression: zstd > lzo > lz4
# available algorithms: /sys/block/zram0/comp_algorithm
ALGO=zstd
# Percentage of total RAM to use for zram
PERCENT=75
# Fixed size in MiB (ignored when PERCENT is set)
#SIZE=256
# Swap priority (higher = preferred first)
PRIORITY=100sudo systemctl restart zramswap.serviceFedora (/etc/systemd/zram-generator.conf):
sudo nvim /etc/systemd/zram-generator.conf[zram0]
zram-size = min(ram, 12288)This uses zram up to the size of RAM, capped at 12 GB, with the kernel's default compression algorithm — specifying one explicitly is optional; the default is stable and well-tested.
sudo systemctl daemon-reexec
sudo rebootVerify
swapon --show # confirm zram swap is active
zramctl # inspect zram devices
cat /sys/block/zram0/comp_algorithm # check the active algorithmNote
- On Fedora, no manual service start is needed after reboot — the systemd generator sets zram up early at boot.
- For most desktop workloads, the kernel's default compression algorithm is more than sufficient; there's rarely a need to tune it further.
- Priority: Always ensure
zramhas a higher priority (e.g.,PRIORITY=100) than traditional disk swap files/partitions, so compressed RAM is consumed before writing to SSD/HDD storage.
References: kernel.org zram docs, systemd/zram-generator
Comments
Loading the discussion…