Bug 1129205

Summary: fallocate to create swap file creates a file with holes
Product: [Fedora] Fedora Reporter: George R. Goffe <grgoffe>
Component: util-linuxAssignee: Karel Zak <kzak>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 20CC: jonathan, kzak
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-12-17 13:02:13 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description George R. Goffe 2014-08-12 10:00:18 UTC
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):


How reproducible:


Steps to Reproduce:
1.fallocate -l 8g swapfile
2.swapon -fv swapfile -- generates error msgs...

Actual results:

see above

Expected results:

valid swap file without holes

Additional info:

Comment 1 Karel Zak 2014-08-12 12:50:19 UTC
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.

Comment 2 George R. Goffe 2014-08-12 16:43:16 UTC

The fs is xfs.

How else does one create a swapfile?



Comment 3 Karel Zak 2014-10-30 13:11:27 UTC
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.