Swapon failed: Invalid argument on a Linux system with Btrfs filesystem
This bug report leads to this discussion
So "Invalid argument" should be read as "Your filesystem do not support swap file"
as posted by malat
I have less than 50 reputation so I can not comment. But I HAVE TO update existing answers. In linux kernel 5.0.0, btrfs natively supports swapfile now. (You must set it as no-COW)
Here's some information from kernel.org: https://btrfs.wiki.kernel.org/index.php/FAQ#Does_btrfs_support_swap_files.3F
From kernel 5.0+ btrfs have native swap files support, but with some limitations. Swap file - must be fully allocated as NOCOW with no compression on one device.
This link shows how to do it: https://wiki.archlinux.org/index.php/swap#Swap_file .
DO NOT TRY IT IN LINUX < 4.21 !!!
Warning: Btrfs on Linux kernel before version 5.0 does not support swap files. Failure to heed this warning may result in file system corruption. While a swap file may be used on Btrfs when mounted through a loop device, this will result in severely degraded swap performance.
If you want to swap on a file anyway, just use btrfs-swapon