/swap.img w/fallocate has holes

Bug #1781781 reported by Ebbex on 2018-07-15
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init
Medium
Unassigned
curtin
Medium
Unassigned

Bug Description

The /swap.img file on an XFS root filesystem is not being used. The dmesg says it "has holes".

From the swapon manpage;

The swap file implementation in the kernel expects to be able to write to the file directly, without the assistance of the filesystem. This is a problem on preallocated files (e.g. fallocate(1)) on filesystems like XFS or ext4, and on copy-on-write filesystems like btrfs.

It is recommended to use dd(1) and /dev/zero to avoid holes on XFS and ext4.

I've tracked down this commit which seems to be a step in the right direction;

https://github.com/CanonicalLtd/curtin/commit/a909966f9c235282267024e86adf404dab83ccfe

Related branches

Ebbex (eb4x) wrote :

So I've checked it out, and ext4 seems to work fine with fallocate. It could perhaps be considered a filesystem-bug as it seems that some xfs-developers are aware of the issue; https://www.spinics.net/lists/linux-mm/msg147100.html But it would be beneficial to have a work-around until that gets sorted.

Ryan Harper (raharper) wrote :

Yes, from my reading, this is an xfs (btrfs) specific issue w.r.t how they don't handle converting a fallocated file into swap space.

I think we'll likely do the following:

1) add a integration test which does swapfile enablment via fallocate for each fs and confirms that the target system can use it as swap; we expect this to fail when rootfs is either btrfs or xfs.

2) update curtin swap creation code to check the target filesystem format and for btrfs or xfs filesystems, skip fallocate and use dd instead.

Alternatively, one can use a swap partition instead of a file on the filesystem which avoids this path; that may be preferred to avoid dd'ing gigabytes of data.

Changed in curtin:
importance: Undecided → Medium
status: New → Confirmed
Scott Moser (smoser) wrote :

The same basic issue is in cloud-init
and had a MP proposed at
 https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354680

Changed in cloud-init:
status: New → Confirmed
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers