Btrfs Restoring Support For Swap Files With Linux 4.21

Written by Michael Larabel in Linux Storage on 12 December 2018 at 03:27 AM EST. 79 Comments
The Btrfs file-system hasn't supported Swap files on it in early a decade, but that support will be restored again with the upcoming Linux 4.21 kernel.

Btrfs hasn't supported Swap files on it since 2009 thus making swap partitions necessary unless having a mix of file-systems on your box (or not caring about any swap capabilities), but now with Linux 4.21 that support will be restored for allowing swap files to be reside on Btrfs.

The change by Facebook's Omar Sandoval explains, "Btrfs has not allowed swap files since commit 35054394c4b3 ("Btrfs: stop providing a bmap operation to avoid swapfile corruptions"). However, now that the proper restrictions are in place, Btrfs can support swap files through the swap file a_ops, similar to iomap in commit 67482129cdab ("iomap: add a swapfile activation function"). For Btrfs, activation needs to make sure that the file can be used as a swap file, which currently means that it must be fully allocated as NOCOW with no compression on one device. It must also do the proper tracking so that ioctls will not interfere with the swap file. Deactivation clears this tracking."

That support is now queued into btrfs-next ahead of the upcoming Linux 4.21 merge window.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via

Popular News This Week