Set up zram compressed swap
Create a compressed RAM-backed swap device so the system handles memory pressure without hitting slow disk swap.
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/zram002What 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
!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 zram05Sources
- Zram - ArchWikiEvidence: 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 devicesEvidence: 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