All of lore.kernel.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: David Sterba <dsterba@suse.cz>
Cc: Michael Ruiz <michael@mruiz.dev>,
	linux-btrfs@vger.kernel.org, osandov@fb.com
Subject: Re: Linux swap file not activating after reboot
Date: Thu, 16 Jan 2020 12:43:29 -0800	[thread overview]
Message-ID: <20200116204329.GA269122@vader> (raw)
In-Reply-To: <20200116185539.GZ3929@twin.jikos.cz>

On Thu, Jan 16, 2020 at 07:55:39PM +0100, David Sterba wrote:
> On Wed, Jan 15, 2020 at 04:34:02PM -0800, Michael Ruiz wrote:
> > Hi,
> >  I have a //@swap subvolume and i have a swapfile within it. I mount the 
> > subvolume like such in fstab:
> > 
> > `rw,ssd,nofail,noautodefrag,nodatacow,nodatasum,subvolid=1234,subvol=/@swap`
> > 
> > It mounts correctly, but 1/15/20 4:20 PM kernel I get: 
> > 
> > `BTRFS warning (device dm-0): swapfile must not be copy-on-write`
> 
> There are two reasons why the message is printed, one is when the file
> does not have the C attribute and another one when the the existing file
> extents need to be COWed (same case as if the file is NOCOW and has been
> snapshotted).
> 
> Plain reboot will not change the C attribute, so either there's a
> snapshot of /@snap or the check of a used swapfile is wrong.
> 
> I tested it here, a swapfile that got almost full after a stress test,
> followed by reboot and swapon (without any change to the file) was ok.
> 
> Doing a snapshot and swapon resulted in the message you saw.
> 
> After deleting the snapshot and waiting until it gets cleaned, swapon
> did not activate the file anymore. Filefrag or fiemap don't report any
> shared extents so here I' expect that the file should be in a valid
> state for swapon.
> 
> Omar, any ideas?

Hm, we're hitting this check in can_nocow_extent():

        if (btrfs_file_extent_generation(leaf, fi) <=
            btrfs_root_last_snapshot(&root->root_item))

That check was added in 78d4295b1eee ("btrfs: lift some
btrfs_cross_ref_exist checks in nocow path") as an optimization. Even if
we comment that out, we'll hit the similar check in
btrfs_cross_ref_exist():

        /* If extent created before last snapshot => it's definitely shared */
        if (btrfs_extent_generation(leaf, ei) <=
            btrfs_root_last_snapshot(&root->root_item))

That's not quite right in exactly this case that the snapshot has been
deleted. Apparently we've been doing unnecessary COW for this case. I'll
need to think about how to safely avoid these checks without too much of
a performance hit.

Thanks for the report!

  reply	other threads:[~2020-01-16 20:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16  0:34 Linux swap file not activating after reboot Michael Ruiz
2020-01-16  0:51 ` Qu Wenruo
2020-01-16 18:55 ` David Sterba
2020-01-16 20:43   ` Omar Sandoval [this message]
2020-01-17  0:44     ` Michael Ruiz
2020-01-17 13:47       ` David Sterba

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=20200116204329.GA269122@vader \
    --to=osandov@osandov.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=michael@mruiz.dev \
    --cc=osandov@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.