Set up zram compressed swap

Create a compressed RAM-backed swap device so the system handles memory pressure without hitting slow disk swap.

LinuxswapzramperformancememoryMedium risk
Load the zram module, set a size, format it as swap and enable it with high priority — pages swapped to zram live compressed in RAM instead of on disk.

01Command

Command
$ sudo modprobe zram && echo lz4 | sudo tee /sys/block/zram0/comp_algorithm && echo 4G | sudo tee /sys/block/zram0/disksize && sudo mkswap /dev/zram0 && sudo swapon -p 100 /dev/zram0

02What it does

zram creates a block device whose contents are compressed and kept in RAM. When the kernel swaps, it first uses zram (priority 100) because decompressing in RAM is far faster than reading from disk. This is why modern Fedora and ChromeOS use zram by default. The zramctl command shows compression ratios and usage.

03Risk

RiskMedium risk
RequirementsLinux kernel with zram module; lz4 kernel module; root access. Most distros offer a zram-generator package that makes this permanent.
!Warning: zram does not add real memory — data compressed in it still consumes RAM. Choose a size around 50–100% of RAM and keep (or add) a small disk swap as a fallback. The settings above do not persist after reboot; use zram-generator for a permanent setup.

04Undo

Undo
$ sudo swapoff /dev/zram0 && echo 1 | sudo tee /sys/block/zram0/reset && sudo modprobe -r zram

05Sources

  • Zram - ArchWiki
    Arch Wiki · community · 2026-09-17
    Evidence: Documents creating a zram device, setting the compression algorithm and disksize via /sys/block/zram0, running mkswap and swapon with priority.
  • zramctl(8) - setup and control zram devices
    Ubuntu Manpages · community · 2026-09-17
    Evidence: zramctl inspects zram devices; the kernel zram module exposes comp_algorithm, disksize and reset sysfs attributes used to configure the device.

Last verified: 2026-09-18 · Category: System & Settings

06Related solutions