linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* swapon: swapfile has holes
@ 2017-11-28 12:31 Cristian
  2017-11-28 13:05 ` Austin S. Hemmelgarn
  0 siblings, 1 reply; 2+ messages in thread
From: Cristian @ 2017-11-28 12:31 UTC (permalink / raw)
  To: linux-btrfs

Hello,

Report in:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1723449

dmesg:
[ 3.782191] swapon: swapfile has holes

Regards,
-- 
Cristian

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: swapon: swapfile has holes
  2017-11-28 12:31 swapon: swapfile has holes Cristian
@ 2017-11-28 13:05 ` Austin S. Hemmelgarn
  0 siblings, 0 replies; 2+ messages in thread
From: Austin S. Hemmelgarn @ 2017-11-28 13:05 UTC (permalink / raw)
  To: Cristian, linux-btrfs

On 2017-11-28 07:31, Cristian wrote:
> Hello,
> 
> Report in:
> https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1723449
> 
> dmesg:
> [ 3.782191] swapon: swapfile has holes

As mentioned in the linked bug report, this is a known issue.  To use a 
swap file on BTRFS, you need to:

1. Create an empty file.
2. Mark it NOCOW with `chattr +C`
3. Use fallocate to pre-allocate to the appropriate size.
4. Hook it up to a loop device.
5. Use the loop device for swap.

This is because the kernel needs a consistent block mapping for a swap 
file, since it bypasses the filesystem and accesses the block device 
directly.  However, since BTRFS has copy-on-write semantics, blocks move 
around on each write, which violates the requirement for a consistent 
block mapping, you can't use a file on a BTRFS filesystem directly as a 
swap file.

Of the above steps, you technically don't need to mark the file NOCOW or 
pre-allocate it, but those are good practice to remove random latency.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-28 13:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-28 12:31 swapon: swapfile has holes Cristian
2017-11-28 13:05 ` Austin S. Hemmelgarn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).