Skip to content

swapon() on a daxfs file fails with -EINVAL: daxfs_aops has no ->read_folio #25

Description

@congwang-mk

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions