swapon() on a daxfs file fails with -EINVAL:
$ dd if=/dev/zero of=/mnt/daxfs/swapfile bs=1M count=256
$ mkswap /mnt/daxfs/swapfile
Setting up swapspace version 1, size = 256 MiB
$ swapon /mnt/daxfs/swapfile
swapon: /mnt/daxfs/swapfile: swapon failed: Invalid argument
daxfs_aops (daxfs/file.c:799) is empty, so SYSCALL_DEFINE2(swapon) bails at
if (!mapping->a_ops->read_folio) {
error = -EINVAL;
goto bad_swap_unlock_inode;
}
before setup_swap_extents() is reached, which is why dmesg stays silent. Beyond that there is also no ->swap_activate, ->swap_rw or ->bmap, so generic_swapfile_activate() would fail too.
This is consistent with how DAX filesystems behave in general: ext4_dax_aops has no ->read_folio either, and rejects swapfiles the same way.
The original report was that swapon hung, which turned out to be two separate metadata bugs rather than the syscall: st_blksize of 1 made file creation crawl at one byte per syscall, and st_blocks of 0 made util-linux refuse the file as sparse before it ever called swapon(). Both fixed in #14, so the failure is now prompt and reports an accurate errno.
Remaining question is whether swap should be supported at all. Making it work needs ->swap_activate, ->swap_deactivate and ->swap_rw (the SWP_FS_OPS path). If the answer is no, worth saying so in the README so the next person does not have to trace the syscall to find out.
Found during the review in #14.
swapon()on a daxfs file fails with-EINVAL:daxfs_aops(daxfs/file.c:799) is empty, soSYSCALL_DEFINE2(swapon)bails atbefore
setup_swap_extents()is reached, which is whydmesgstays silent. Beyond that there is also no->swap_activate,->swap_rwor->bmap, sogeneric_swapfile_activate()would fail too.This is consistent with how DAX filesystems behave in general:
ext4_dax_aopshas no->read_folioeither, and rejects swapfiles the same way.The original report was that
swaponhung, which turned out to be two separate metadata bugs rather than the syscall:st_blksizeof 1 made file creation crawl at one byte per syscall, andst_blocksof 0 made util-linux refuse the file as sparse before it ever calledswapon(). Both fixed in #14, so the failure is now prompt and reports an accurate errno.Remaining question is whether swap should be supported at all. Making it work needs
->swap_activate,->swap_deactivateand->swap_rw(theSWP_FS_OPSpath). If the answer is no, worth saying so in the README so the next person does not have to trace the syscall to find out.Found during the review in #14.