fallocate swapfile doesn't work

I had a swapfile configured like in https://wiki.manjaro.org/index.php?title=Swap#Creating_and_Enabling_a_Static_Swapfile. After the latest update, I noticed in htop and swapon that it's not active. When doing

sudo swapon /swapfile

I got

swapon: /swapfile: swapon failed: Invalid argument

I fixed it by recreating the swapfile using sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB instead of fallocate and it works.

Should the wiki be updated?

From swapon(8) manpage:

Files with holes

The swap file implementation in the kernel expects to be able to write to the file directly, without the assistance of the filesystem. This is a problem on files with holes or on copy-on-write files on filesystems like Btrfs.

Commands like cp(1) or truncate(1) create files with holes. These files will be rejected by swapon.

Preallocated files created by fallocate(1) may be interpreted as files with holes too depending of the filesystem. Preallocated swap files are supported on XFS since Linux 4.18.

The most portable solution to create a swap file is to use dd(1) and /dev/zero.

Also, this might be relevant:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by