Arch Linux

Please read this before reporting a bug:

Do NOT report bugs when a package is just outdated, or it is in Unsupported. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!

FS#66921 - [linux] "Swapfile has holes" on Linux 5.7

Attached to Project: Arch Linux
Opened by Alan Orth (stickyboy) - Saturday, 06 June 2020, 16:59 GMT
Last edited by freswa (frederik) - Saturday, 06 June 2020, 19:43 GMT
Task Type Bug Report
Category Packages: Testing
Status Assigned
Assigned To Tobias Powalowski (tpowa)
Jan Alexander Steffens (heftig)
Levente Polyak (anthraxx)
Architecture x86_64
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 10
Private No



Upgrading my system from core/linux 5.6.15.arch1-1 to testing/linux 5.7.arch1-1 and my swapfile doesn't work. At boot systemd shows this message during startup:

Jun 06 19:47:05 laptop kernel: swapon: swapfile has holes

If I reboot back into Linux 5.6 the swapfile works.

Additional info:
* 5.7.arch1-1
* Swapfile on ext4
This task depends upon

Comment by Alan Orth (stickyboy) - Monday, 08 June 2020, 15:18 GMT Comment by John Shand (jshand2019) - Thursday, 11 June 2020, 01:00 GMT
Hi there, i have found the same issue and have some logs for you. however, my system is set up with a swapfile instead of a swap partition
Comment by John Shand (jshand2019) - Thursday, 11 June 2020, 01:02 GMT
here is another
Comment by Paulo Fino (burafino) - Thursday, 11 June 2020, 20:44 GMT
Same here. Using a swapfile on ext4 SSD with no encryption.
Just updated to 5.7.2 from core, rebooted and saw error messages on boot:
`[FAILED] Failed to activate swap /swap.`
`[DEPEND] Dependency failed for Swap.`
And another message in the log after logging in:
`swapon: swapfile has holes`.
Comment by Ayr0 (ayr0) - Friday, 12 June 2020, 04:04 GMT
I also experienced this when upgrading to linux 5.7.2. Downgrading solved the issue for me.
I'm pretty certain there are no holes in my swap file. I reformatted my swapfile just to make sure.

Swapfile on ext4 SSD LVM (unencrypted).

Comment by Wes Fournier (wes.fournier) - Friday, 12 June 2020, 04:14 GMT
I was able to fix this by re-creating my swap file with dd. See the Note regarding Kernel 5.7 at

"Note: dynamic space allocation such as using fallocate is not supported, as it causes problems with some file systems such as F2FS[1] and will likely fail to activate at boot time with error "swapon: swapfile has holes" as of kernel 5.7. Hence, contiguous allocation, such as dd, is the only reliable way to allocate a swap file.[2]"
Comment by Axel Navarro (navarroaxel) - Friday, 12 June 2020, 17:18 GMT
So, this is a «won't fix» ticket.

Commands to create/recreate the swapfile with root privileges:

rm /swapfile #deletes old swapfile
# 2GB swapfile in MiB
dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile # enables the swapfile right now
echo '/swapfile none swap defaults 0 0' | tee --append /etc/fstab # configs the swapfile in startup
Comment by Parsec (parsec82) - Friday, 12 June 2020, 19:32 GMT
Same problem with upgrade to linux 5.7 and solved with navarroaxel procedure
Comment by Javier (je-vv) - Saturday, 13 June 2020, 01:17 GMT
Just to notify that by creating the swap file with dd, instead of fallocate, things just work fine. Thanks !
Comment by Vulf (vulf) - Saturday, 13 June 2020, 10:54 GMT
Encountered the same problem after upgrading to 5.7.2. Resolved it using navarroaxel 's solution. Thank you!
Comment by AMM (amish) - Saturday, 27 June 2020, 12:44 GMT
I had created /swapfile using fallocate for many of servers I maintain. It was working fine till now.

But now on one of my server after upgrading 5.7, I get same error that "swapfile has holes".

man for "swapon" does not mention ext4 having any issue. And also kernel bug report says it was regression error introduced in 5.7. So it is likely a kernel bug and not ext4/swapon incompatibility.

I am wondering if I should go ahead and re-create /swapfile on all servers using dd? (which will need a downtime which I am trying to avoid)
I should wait for kernel fix? (if it is really the fix)

Thank you.
Comment by AMM (amish) - Sunday, 28 June 2020, 04:00 GMT
Assuming you have enough space on disk, here is safe method to convert your swap file with holes to one without holes (without any system downtime, without running out of memory and avoiding any program getting closed by kernel due to OOM)

(This is to be done before kernel upgrade and reboot. This will make sure that swap setup will not fail after reboot)
(If you have already upgraded and rebooted i.e. swap setup has already failed then @navarroaxel method above is enough)

# STEP 1:
# create new temporary swap file with same size as existing one (e.g. 4GB)
dd if=/dev/zero of=/swapfilenew bs=1M count=4096 status=progress
chmod 600 /swapfilenew && mkswap /swapfilenew && swapon /swapfilenew

# STEP 2:
# turn off existing swapfile
# this will take a while as existing swap data will be migrated to physical RAM and/or new swap file
swapoff /swapfile

# STEP 3:
# re-create /swapfile
rm /swapfile && dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile

# STEP 4:
# transfer the swap data back, if necessary and remove temporary swap file
swapoff /swapfilenew && rm /swapfilenew

You may be able to directly rename (mv) /swapfilenew to /swapfile after STEP 2 and in that case STEP 3 and STEP 4 are not required. But I am sure if renaming a swap file while it is still in use can cause any problem or not.
Comment by Jan Alexander Steffens (heftig) - Tuesday, 30 June 2020, 09:22 GMT
Doesn't seem like upstream likes the patch mentioned in the bug, so I'm not backporting that one.