We're moving away from swap partitions on our Linux servers

October 13, 2022

We have a reasonable number of Linux servers, almost all of them running various versions of Ubuntu. Like pretty much everyone configuring Linux servers, we give them some swap space; the Linux kernel traditionally is much happier if it has a bit of swap space (cf), although you don't want too much. For a long time we used a separate disk partition for this (or a mirrored pair of them in a separate software RAID mirror device), although Linux distributions themselves were increasingly moving to using swap files located in the root filesystem (sometimes rather excessively large ones; the Ubuntu 20.04 and 22.04 installers use 4 GB even for machines with only 4 GB of RAM). We didn't have any particularly strong reasons for using a swap partition instead of a swap file; it was just what we'd started out with and what we were used to.

(We've been running various flavours of Unix machines for a very long time, so we've been setting up swap partitions since before Linux had swap files at all, much less when they were well regarded on software RAID.)

This time around, that's been changing in our Ubuntu 22.04 installs. Again, it's not for any particular reason, it's mostly merely that it's a bit more annoying work to set up an additional mirrored partition for swap. Swap files appear to work fine, including on a mirrored root filesystem, and I've read that they're basically just as efficient as swap partitions these days (I don't know if this is true). Plus, adjusting the size of a swap file after you've finished installing a system is a lot easier than doing something with a swap partition.

(If you're willing to use swap files anyway you can always add more swap space with a swap file even if you started with a swap partition. However, if your swap partition is too big, shrinking it or limiting how much of it gets used is more annoying.)

I suspect that we're lagging well behind the adoption curve for swap files over swap partitions, and that other places transitioned years ago. Certainly I believe Ubuntu has been defaulting to swap files since at least 20.04 LTS. We might have made the transition then if we'd built more 20.04 machines, but world events intervened and we mostly skipped it (it didn't help that our Exim machines had no choice but to skip 20.04).

PS: Fedora 36 defaults to swap on ZRAM, which is even more of a radical change than Ubuntu moving to a swap file. Swap on ZRAM hasn't exploded on my Fedora machines, but we'd probably never use it on our Ubuntu servers for various reasons.

PPS: My cynical side suspects that Ubuntu 22.04 defaults to using a swap file partly because Canonical is increasingly focusing on the cloud market, and I expect that in the cloud, configuring a swap file is easier than a swap partition. Although I really don't understand that 4 GB swap file size given the cloud; I would think it'd be far too big for typical cloud VM setups.

Written on 13 October 2022.
« We are stuck with egrep and fgrep (unless you like beating people)
Two views of CPU utilization (a realization) »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Oct 13 23:59:39 2022
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.