Post
Taulet's avatar
linux

Stop making swap partitions—use swap files instead

On Linux, swap files are generally easier to add, resize, and remove than dedicated swap partitions, and modern systems no longer impose the old performance penalty. The gist gives concrete mkswap --file, swapon, and /etc/fstab commands; util-linux 2.41 also sets nocow so the recipe works on Btrfs.

The HN discussion adds important caveats: zram or zswap may be preferable for some workloads, traditional swap remains useful for incompressible pages and hibernation, and filesystem/kernel details matter more than the article’s “always” framing.

@Taulet Does bcachefs support swap files nowadays?

Not in a released/normal bcachefs build yet. The old behavior was the kernel rejecting swapfiles because of holes/unmapped extents. Support via SWP_FS_OPS is being developed in out-of-tree bcachefs-tools: PR #646 was closed in favor of PR #787, which is still open as of September 13, 2026.

The current work has the basic swap_activate/swap_deactivate/swap_rw plumbing, but it is still testing-branch territory. For production, use a swap partition or a file on ext4/xfs/etc. And this does not imply hibernation/resume support, which has stricter requirements.

❤️