cd ~/>cat multi-boot-partitioning-zram-vs-swap.md

Multi-boot partitioning / zram vs swap

#linux#zram#swap#void#kernel

The swap partition is gone

There is no swap partition in the layout at [Multi-boot partitioning / The layout]. Swap is handled entirely by zram: a compressed in-memory block device that the kernel treats as a swap device. It is faster than disk swap by orders of magnitude, does not consume partition table entries, and does not produce disk I/O under memory pressure.

What zram is

zram creates a block device backed by RAM. When the kernel swaps pages out to a zram device, those pages are compressed and stored in RAM — not on disk. The compression algorithm is configurable; zstd is the correct choice for the combination of compression ratio and speed.

The current configuration:

zramctl
NAME       ALGORITHM DISKSIZE  DATA  COMPR  TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd        23.3G  9.1G  3.2G    3.3G      16 [SWAP]

23.3G device size, zstd, priority 100. The kernel hits this before any disk swap.

The math

32G of physical RAM. zram configured at ~72% of RAM = 23.3G swap device.

zstd typically achieves 3:1 to 4:1 compression on memory page content (which tends to be text, code, and data structures — all compressible). At 3:1:

  • 23.3G swap device
  • Actual RAM consumed when full: 23.3G ÷ 3 ≈ 7.8G
  • Net usable memory increase: ~15.5G (the swap space minus the RAM used to store it)

This is not free memory — it trades CPU cycles for compression. Under sustained memory pressure, zram consumes CPU time compressing and decompressing pages. For a desktop workload, this is rarely perceptible.

Priority

When multiple swap devices exist, the kernel uses priority to determine which to fill first. Higher priority = filled first.

swapon --show
NAME       TYPE      SIZE  USED PRIO
/dev/zram0 partition 23.3G  0B   100

Priority 100 ensures zram is used before any disk swap (which defaults to -2). If a swap file or partition were added later, zram would still be exhausted first, keeping the I/O pattern sane.

Void Linux setup

On Void, the zramen package provides the runit service and configuration for zram:

xbps-install zramen
ln -s /etc/sv/zramen /var/service/

Configuration in /etc/zramen.conf:

ZRAM_ALGORITHM=zstd
ZRAM_SIZE=23300M
ZRAM_PRIORITY=100

The service creates the zram device on boot and enables it as swap. No other configuration is needed.

Removing the swap partition

The swap partition was removed from fstab. If a swap partition were still present:

# disable it first
swapoff /dev/nvme0n1p_X

# then remove the fstab entry
# remove the UUID= line pointing to swap

After removing from fstab, the partition entry can be deleted with parted or gdisk and the space reclaimed. In this layout, that space was merged into the btrfs pool.

When you still need disk swap

Two cases where zram alone is insufficient:

Hibernation. Suspend-to-disk requires writing the entire RAM contents to a swap device, then restoring on resume. The swap device must be at least as large as RAM, and it must be on disk — zram itself lives in RAM and is gone when the machine powers off. If hibernation is required, a swap partition or swap file of at least 32G is necessary. zram is compatible with disk swap; you use both, with disk swap at a lower priority.

RAM-constrained machines. On a machine with 4G or 8G of RAM, dedicating a significant fraction to zram leaves little headroom for actual workloads. A 4G machine with 2G of zram has only 2G available for applications before memory pressure begins. Disk swap provides a safety valve that doesn’t eat into available RAM. On machines with 16G or more, this concern is minimal.

This machine has 32G and does not hibernate. zram handles everything.

// END OF TRANSMISSION
See you, Space Cowboy.

Connection closed. Returning to terminal...