Ctrl K

Linux zram and Disk-Backed Swap

Identify zram-only swap, understand why zram cannot store a hibernation image, and configure a two-layer swap setup with zram for runtime paging and disk-backed swap for hibernate.

This page documents the difference between zram swap and disk-backed swap, how to identify which kind a system uses, and the two-layer layout where zram handles runtime paging and a disk swapfile handles overflow and hibernate. The examples are from Arch Linux with zram-generator, but the same behavior applies to any distro that enables zram (Fedora enables it by default).

Initial problem

Hibernate fails even though swap exists and swapon lists it.

systemctl hibernate

Example failure:

Call to Hibernate failed: Not enough suitable swap space for hibernation available on compatible block devices and file systems

The swap size is not the cause. The swap type is. A larger zram device produces the same failure.

Check the active swap type

List the active swap devices and the zram configuration.

swapon --show
zramctl

Example output from a system with zram-only swap:

NAME       TYPE      SIZE USED PRIO
/dev/zram0 partition   4G   0B  100

NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd            4G    4K   64B   20K         [SWAP]
  • swapon reports zram with type partition. This is misleading; zram is not a disk partition.
  • If the only entry is /dev/zramN and the list contains no disk partition (/dev/nvme..., /dev/sd...) and no swapfile, the system has no disk-backed swap.

How zram works

zram is a kernel feature, not a property of the RAM hardware. It creates a virtual block device whose contents are stored compressed in RAM. Under memory pressure, the kernel compresses the least used pages and stores them in the zram device instead of writing them to disk.

  • Pages swapped out to zram remain in physical RAM in compressed form.
  • The configured size (for example 4G) is a capacity limit, not a reservation. RAM is used only for the compressed data currently stored. An empty zram device occupies a few kilobytes.
  • zram extends usable memory rather than limiting it. A 16G machine with a 4G zram device can hold roughly 18-19G of working set, at the cost of CPU time for compression. With zstd, compression is typically 2-3x and takes microseconds per page.
  • The zram-generator default size is min(RAM / 2, 4G). It is configurable in /etc/systemd/zram-generator.conf.

Why zram cannot store a hibernation image

Hibernate writes an image of RAM to persistent storage and powers the machine off. zram is stored in RAM, so its contents are lost when power is cut.

  • systemd excludes zram devices when selecting a hibernation target, regardless of their size.
  • Increasing the zram size does not change this. A 64G zram device fails the same way.
  • The only fix is adding disk-backed swap: a swapfile or a swap partition.

Two-layer swap layout

The recommended layout keeps both swap kinds, separated by swap priority.

DevicePriorityRole
/dev/zram0High (for example 100)Runtime paging, stays in RAM
/swapfileLow (for example 10 or -2)Overflow when zram is full, hibernation target
  • The kernel uses the higher priority swap first, so normal paging goes to zram.
  • The disk swap is used only when zram is full and when hibernating.
  • Size the disk swap around the machine's RAM so the hibernation image fits under memory load.

Enable hibernate

Creating the disk-backed swap is not sufficient on its own. The kernel must also be configured to find the image at the next boot.

  • Add resume=UUID=<filesystem-or-partition> to the kernel command line, plus resume_offset=<physical offset> when a swapfile is used.
  • Add the resume mechanism to the initramfs. On Arch with a busybox initrd, this is the resume mkinitcpio hook. systemd-based initrds handle resume natively.
  • Regenerate the initramfs or UKI after the change.

The full step-by-step setup, including the UKI command line and mkinitcpio changes, is in Arch Hibernate with Swapfile and UKI.

Verify

Confirm both swap layers are active and that hibernate restores the session.

swapon --show
systemctl hibernate

Expected output shape:

NAME       TYPE      SIZE USED PRIO
/swapfile  file       80G   0B   10
/dev/zram0 partition   4G   0B  100
  • Both layers are present and zram has the higher priority.
  • After systemctl hibernate, the machine powers fully off and restores the previous session on the next power on.

See also