All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Mason <clm@fb.com>
To: ethanlien <ethanlien@synology.com>
Cc: Nikolay Borisov <nborisov@suse.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	"linux-btrfs-owner@vger.kernel.org" 
	<linux-btrfs-owner@vger.kernel.org>
Subject: Re: [PATCH] btrfs: use tagged writepage to mitigate livelock of snapshot
Date: Thu, 1 Nov 2018 13:24:15 +0000	[thread overview]
Message-ID: <67AC0ECC-B2EA-40EB-AB7B-150C7F359396@fb.com> (raw)
In-Reply-To: <6404da122f4d63c5dfa6b6c256114b28@synology.com>

On 1 Nov 2018, at 6:21, ethanlien wrote:

> Nikolay Borisov 於 2018-11-01 18:01 寫到:
>> On 1.11.18 г. 11:56 ч., ethanlien wrote:
>>> Nikolay Borisov 於 2018-11-01 16:59 寫到:
>>>> On 1.11.18 г. 8:49 ч., Ethan Lien wrote:
>>>>> Snapshot is expected to be fast. But if there are writers steadily
>>>>> create dirty pages in our subvolume, the snapshot may take a very 
>>>>> long
>>>>> time to complete. To fix the problem, we use tagged writepage for
>>>>> snapshot
>>>>> flusher as we do in the generic write_cache_pages(), so we can 
>>>>> ommit
>>>>> pages
>>>>> dirtied after the snapshot command.
>>>>
>>>> So the gist of this commit really is that you detect when 
>>>> filemap_flush
>>>> has been called from snapshot context and tag all pages at *that* 
>>>> time
>>>> as PAGECACHE_TAG_TOWRITE and then write them, ignoring any pages 
>>>> that
>>>> might have been dirtied beforehand. Your description kind of dances
>>>> around this idea without really saying it explicitly. Those 
>>>> semantics
>>>> make sense, however i'd like to be stated more explicitly in the 
>>>> change
>>>>  log.
>>>>
>>>> However, this is done at the expense of consistency, so we have 
>>>> faster
>>>> snapshots but depending the file which are stored in them they 
>>>> might be
>>>> broken (i.e a database) since they will be missing pages.
>>>>
>>>
>>> tag_pages_for_writeback() will tag all pages with 
>>> PAGECACHE_TAG_DIRTY.
>>> If a dirty
>>> page get missed here, it means someone has initiated the flush 
>>> before
>>> us, so we
>>> will wait that dirty page to complete in create_snapshot() ->
>>> btrfs_wait_ordered_extents().
>>
>> And what happens in the scenario where you have  someone dirtying 
>> pages,
>> you issue the snapshot ioctl, mark all currently dirtied pages as
>> TOWRITE and then you have more delalloc pages being dirtied following
>> initial call to tag_pages_for_writeback , you will miss those, no ?
>>
>
> We don't freeze the filesystem when doing snapshot, so there is no 
> guarantee
> the page dirtied right after we send the ioctl, will be included in 
> snapshot.
> If a page is dirtied while we scan the dirty pages and its offset is 
> before our
> current index, we miss it in our current snapshot implementation too.

This looks like a pretty good compromise to me between btrfs v0's don't 
flush at all on snapshot and today's full sync on snapshot.  The full 
sync is always going to be a little racey wrt concurrent writes.

-chris

  reply	other threads:[~2018-11-01 13:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01  6:49 [PATCH] btrfs: use tagged writepage to mitigate livelock of snapshot Ethan Lien
2018-11-01  8:59 ` Nikolay Borisov
2018-11-01  9:56   ` ethanlien
2018-11-01 10:01     ` Nikolay Borisov
2018-11-01 10:21       ` ethanlien
2018-11-01 13:24         ` Chris Mason [this message]
2018-11-01 11:57 ` Nikolay Borisov
2018-11-02  7:00   ` ethanlien
2018-11-01 18:02 ` David Sterba
2018-11-02  7:13   ` ethanlien
2018-11-02  8:43     ` Nikolay Borisov

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=67AC0ECC-B2EA-40EB-AB7B-150C7F359396@fb.com \
    --to=clm@fb.com \
    --cc=ethanlien@synology.com \
    --cc=linux-btrfs-owner@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.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.