Red Hat Bugzilla – Bug 1129205
fallocate to create swap file creates a file with holes
Last modified: 2014-12-17 08:02:13 EST
Description of problem:
"fallocate -l 8g swapfile" creates a file that "swapon -fv swapfile" gives error messages:
Aug 12 02:52:42 fedora-20-x86_64 kernel: [ 1392.638622] swapon: swapfile has holes
Aug 12 02:52:42 fedora-20-x86_64 kernel: swapon: swapfile has holes
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1.fallocate -l 8g swapfile
2.swapon -fv swapfile -- generates error msgs...
valid swap file without holes
Well, which FS type are you using? Does it work when you create the file by another way? What about if you create loop device from the file and then use the device for swapon?
See NOTES in swapon man page -- for example btrfs does not implement bmap() in kernel, so swapfiles on btrfs are impossible.
The fs is xfs.
How else does one create a swapfile?
Sorry for delay,
> How else does one create a swapfile?
dd if=/dev/zero of=swapfile count=8000 bs=1MiB
the problem with fallocate(1) or truncate(1) is that it uses filesystem ioctls to make the allocation fast and effective, the disadvantage is that it does not physically allocate the space -- but swapon(2) syscall requires a real space.
It seems we need a note about it to fallocate(1) man page.