From: Austin S Hemmelgarn <ahferroin7@gmail.com>
To: Robert White <rwhite@pobox.com>,
Btrfs BTRFS <linux-btrfs@vger.kernel.org>
Subject: Re: NOCOW and Swap Files?
Date: Thu, 23 Oct 2014 07:22:01 -0400 [thread overview]
Message-ID: <5448E4D9.10903@gmail.com> (raw)
In-Reply-To: <54480ED0.9070703@pobox.com>
[-- Attachment #1: Type: text/plain, Size: 1567 bytes --]
On 2014-10-22 16:08, Robert White wrote:
> 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?)
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).
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.
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 2455 bytes --]
prev parent reply other threads:[~2014-10-23 11:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-22 20:08 NOCOW and Swap Files? Robert White
2014-10-22 20:25 ` Hugo Mills
2014-10-22 20:39 ` Robert White
2014-10-22 20:42 ` Hugo Mills
2014-10-22 20:48 ` Robert White
2014-10-23 7:34 ` Russell Coker
2014-10-23 11:22 ` 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=5448E4D9.10903@gmail.com \
--to=ahferroin7@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=rwhite@pobox.com \
/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).