Linux – Does swap need to be on a contiguous LVM logical volume

linuxlvmswap

I am setting up a machine to run a number of virtual machines. I am using a single HDD with a boot partition and an LVM partition. I read on the Arch wiki that logcial volumes which will be used for swap should be setup with -C y

To create a contiguous partition, which means that your swap
space does not get partitioned over one or more disks nor over
non-contiguous physical extents.

How important is this? If i have a dozen VMs each with a contiguous logical volume for swap and a non-contiguous logical volume for /, how will having so many contiguous logical volumes affect my ability to resize logical volumes (either contiguous or non-contiguous)?

Best Answer

I am not aware of any requirement that swap space be contiguous on disk under Linux, with LVM or otherwise. I have never arranged for my swap LVs to be contiguous and have never run into any problem (it's possible that all my swap LVs just happened to be contiguous, I've never looked).

Linux supports non-contiguous swap files, it would be odd to have such a restriction on LVM volumes. I can't find any reference to this in any official documentation or anyone explaning why swap LVs should be contiguous. This has all the hallmarks of an urban legend.

The origin may lie in HP-UX, which Linux's LVM is partly inspired from, and which did (does?) require swap space to be contiguous. I don't know that this has ever been the case on Linux.

There may be a perceived performance benefit, but with 4MB extents, I very much doubt there is any performance benefit, and I can't find any benchmark.

If you have volume groups that span over multiple disks, you may want to constrain what PV the swap LV is on. But I wouldn't require a contiguous volume.

Related Question