Bug 1129205 - fallocate to create swap file creates a file with holes
Summary: fallocate to create swap file creates a file with holes
Alias: None
Product: Fedora
Classification: Fedora
Component: util-linux
Version: 20
Hardware: x86_64
OS: Linux
Target Milestone: ---
Assignee: Karel Zak
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2014-08-12 10:00 UTC by George R. Goffe
Modified: 2014-12-17 13:02 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2014-12-17 13:02:13 UTC
Type: Bug

Attachments (Terms of Use)

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.

Note You need to log in before you can comment on or make changes to this bug.