On 2014-10-22 16:08, Robert White wrote:
I actually use a swapfile on BTRFS on a regular basis on my laptop (trying to keep the number of partitions to a minimum, cause I dual boot Windows), and here's what the init script I use for it does: 1. Remove any old swap file (the fs is on an SSD, so I do this mostly to get the discard operation).So the documentation is clear that you can't mount a swap file through BTRFS (unless you use a loop device).Why isn't a NOCOW file that has been fully pre-allocated -- as with fallocate(1) -- not suitable for swapping? I found one reference to an unimplemented feature necessary for swap, but wouldn't it be reasonable for that feature to exist for NOCOW files? (or does this relate to my previous questions about the COW operation that happens after a snapshot?)
2. Use touch to create a new file. 3. Use chattr to mark the file NOCOW. 4. Use fallocate to pre-allocate the space for the file. 5. Bind the file to a loop device. 6. Format as swap and add as swapspace.This works very reliably for me, and the overhead of the loop device is relatively insignificant (because my disk is actually faster than my RAM) for my use case, and I can safely balance/defrag/fstrim the filesystem without causing issues with the swap file.
If you can avoid using a swapfile though, I would suggest doing so, regardless of which FS you are using. I actually use a 4-disk RAID-0 LVM volume on my desktop, and it gets noticeably better performance than using a swap file.
smime.p7s
Description: S/MIME Cryptographic Signature