hn.today

Swap, ZRAM, Zswap and Hibernate on NixOS

blog.matthewbrunelle.com72 points22 comments
Screenshot of Swap, ZRAM, Zswap and Hibernate on NixOS

This explains how to set up swap, zram, zswap and hibernate on NixOS for desktop and laptop use, with a focus on getting suspend-then-hibernate to work reliably. It emphasizes that hibernation requires disk-backed swap to store the memory image and that swap files versus swap partitions matter because the resume path must be known before filesystems mount; NixOS now understands swap file offsets and can handle UEFI resume metadata. Practical setup examples contrast a simple swap partition on a desktop with an encrypted LUKS + btrfs subvolume swap file on a laptop, and point out that swap files can be made to work but add complexity.

The recommended approach is to use zswap backing a disk-backed swap and to tune the kernel swappiness higher (the author uses 100) rather than using zram (zramSwap), which is inappropriate when you plan to hibernate. A minimal NixOS config enabling zswap and setting swappiness is sufficient. Compression choice matters: kernel defaults to lzo, NixOS defaults to zstd for better ratio, and lz4 is fastest; the tradeoff is speed versus how many pages can stay compressed in RAM (fewer disk writes). Recent NixOS defaults have simplified the needed configuration.

Read on blog.matthewbrunelle.com22 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Security

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.