linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Austin S. Hemmelgarn" <ahferroin7@gmail.com>
To: Cristian <caravena@gmail.com>, linux-btrfs@vger.kernel.org
Subject: Re: swapon: swapfile has holes
Date: Tue, 28 Nov 2017 08:05:41 -0500	[thread overview]
Message-ID: <2b408b4e-8dfc-3d2f-18b5-8d9f6d03e4ad@gmail.com> (raw)
In-Reply-To: <CABwnbUnS0EQfq+L_cbz53OMG7VBbGC-gEt0JXJyUv9qU2RcdEQ@mail.gmail.com>

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.

      reply	other threads:[~2017-11-28 13:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28 12:31 swapon: swapfile has holes Cristian
2017-11-28 13:05 ` Austin S. Hemmelgarn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b408b4e-8dfc-3d2f-18b5-8d9f6d03e4ad@gmail.com \
    --to=ahferroin7@gmail.com \
    --cc=caravena@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).