All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Josef Bacik <josef@toxicpanda.com>, Qu Wenruo <wqu@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 02/42] btrfs: introduce write_one_subpage_eb() function
Date: Fri, 16 Apr 2021 07:25:32 +0800	[thread overview]
Message-ID: <a442f0df-d4d7-50ca-e4c3-224200ef9a70@gmx.com> (raw)
In-Reply-To: <7cff2211-b74a-647e-12f5-fb5994d9f3f0@toxicpanda.com>



On 2021/4/16 上午3:03, Josef Bacik wrote:
> On 4/15/21 1:04 AM, Qu Wenruo wrote:
>> The new function, write_one_subpage_eb(), as a subroutine for subpage
>> metadata write, will handle the extent buffer bio submission.
>>
>> The major differences between the new write_one_subpage_eb() and
>> write_one_eb() is:
>> - No page locking
>>    When entering write_one_subpage_eb() the page is no longer locked.
>>    We only lock the page for its status update, and unlock immediately.
>>    Now we completely rely on extent io tree locking.
>>
>> - Extra bitmap update along with page status update
>>    Now page dirty and writeback is controlled by
>>    btrfs_subpage::dirty_bitmap and btrfs_subpage::writeback_bitmap.
>>    They both follow the schema that any sector is dirty/writeback, then
>>    the full page get dirty/writeback.
>>
>> - When to update the nr_written number
>>    Now we take a short cut, if we have cleared the last dirty bit of the
>>    page, we update nr_written.
>>    This is not completely perfect, but should emulate the old behavior
>>    good enough.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>   fs/btrfs/extent_io.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 55 insertions(+)
>>
>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
>> index 21a14b1cb065..f32163a465ec 100644
>> --- a/fs/btrfs/extent_io.c
>> +++ b/fs/btrfs/extent_io.c
>> @@ -4196,6 +4196,58 @@ static void
>> end_bio_extent_buffer_writepage(struct bio *bio)
>>       bio_put(bio);
>>   }
>> +/*
>> + * Unlike the work in write_one_eb(), we rely completely on extent
>> locking.
>> + * Page locking is only utizlied at minimal to keep the VM code happy.
>> + *
>> + * Caller should still call write_one_eb() other than this function
>> directly.
>> + * As write_one_eb() has extra prepration before submitting the
>> extent buffer.
>> + */
>> +static int write_one_subpage_eb(struct extent_buffer *eb,
>> +                struct writeback_control *wbc,
>> +                struct extent_page_data *epd)
>> +{
>> +    struct btrfs_fs_info *fs_info = eb->fs_info;
>> +    struct page *page = eb->pages[0];
>> +    unsigned int write_flags = wbc_to_write_flags(wbc) | REQ_META;
>> +    bool no_dirty_ebs = false;
>> +    int ret;
>> +
>> +    /* clear_page_dirty_for_io() in subpage helper need page locked. */
>> +    lock_page(page);
>> +    btrfs_subpage_set_writeback(fs_info, page, eb->start, eb->len);
>> +
>> +    /* If we're the last dirty bit to update nr_written */
>> +    no_dirty_ebs = btrfs_subpage_clear_and_test_dirty(fs_info, page,
>> +                              eb->start, eb->len);
>> +    if (no_dirty_ebs)
>> +        clear_page_dirty_for_io(page);
>> +
>> +    ret = submit_extent_page(REQ_OP_WRITE | write_flags, wbc, page,
>> +            eb->start, eb->len, eb->start - page_offset(page),
>> +            &epd->bio, end_bio_extent_buffer_writepage, 0, 0, 0,
>> +            false);
>> +    if (ret) {
>> +        btrfs_subpage_clear_writeback(fs_info, page, eb->start,
>> +                          eb->len);
>> +        set_btree_ioerr(page, eb);
>> +        unlock_page(page);
>> +
>> +        if (atomic_dec_and_test(&eb->io_pages))
>> +            end_extent_buffer_writeback(eb);
>> +        return -EIO;
>> +    }
>> +    unlock_page(page);
>> +    /*
>> +     * Submission finishes without problem, if no range of the page is
>> +     * dirty anymore, we have submitted a page.
>> +     * Update the nr_written in wbc.
>> +     */
>> +    if (no_dirty_ebs)
>> +        update_nr_written(wbc, 1);
>> +    return ret;
>> +}
>> +
>>   static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
>>               struct writeback_control *wbc,
>>               struct extent_page_data *epd)
>> @@ -4227,6 +4279,9 @@ static noinline_for_stack int
>> write_one_eb(struct extent_buffer *eb,
>>           memzero_extent_buffer(eb, start, end - start);
>>       }
>> +    if (eb->fs_info->sectorsize < PAGE_SIZE)
>> +        return write_one_subpage_eb(eb, wbc, epd);
>> +
>
> Same comment here, again you're calling write_one_eb() which expects to
> do the eb thing, but then later have an entirely different path for the
> subpage stuff, and thus could just call your write_one_subpage_eb()
> helper from there instead of stuffing it into write_one_eb().

But there are some common code before calling the subpage routine.

I don't think it's a good idea to have duplicated code between subpage
and regular routine.

>
> Also, I generally don't care about ordering of patches as long as they
> make sense generally.
>
> However in this case if you were to bisect to just this patch you would
> be completely screwed, as the normal write path would just fail to write
> the other eb's on the page.  You really need to have the patches that do
> the write_cache_pages part done first, and then have this patch.

No way one can bisect to this patch.
Without the last patch to enable subpage write, bisect will never point
to this one.

And how could it be possible to implement data write before metadata?
Without metadata write ability, data write won't even be possible.

But without data write ability, metadata write can still be possible,
just doing basic touch/inode creation or even inline extent creation.

So I'm afraid metadata write patches must be before data write patches.

Thanks,
Qu

>
> Or alternatively, leave the order as it is, and simply don't wire the
> helper up until you implement the subpage writepages further down.  That
> may be better, you won't have to re-order anything and you can maintain
> these smaller chunks for review, which may not be possible if you
> re-order them.  Thanks,
>
> Josef

  reply	other threads:[~2021-04-15 23:25 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15  5:04 [PATCH 00/42] btrfs: add full read-write support for subpage Qu Wenruo
2021-04-15  5:04 ` [PATCH 01/42] btrfs: introduce end_bio_subpage_eb_writepage() function Qu Wenruo
2021-04-15 18:50   ` Josef Bacik
2021-04-15 23:21     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 02/42] btrfs: introduce write_one_subpage_eb() function Qu Wenruo
2021-04-15 19:03   ` Josef Bacik
2021-04-15 23:25     ` Qu Wenruo [this message]
2021-04-16 13:26       ` Josef Bacik
2021-04-18 19:45       ` Thiago Jung Bauermann
2021-04-15  5:04 ` [PATCH 03/42] btrfs: make lock_extent_buffer_for_io() to be subpage compatible Qu Wenruo
2021-04-15 19:04   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 04/42] btrfs: introduce submit_eb_subpage() to submit a subpage metadata page Qu Wenruo
2021-04-15 19:27   ` Josef Bacik
2021-04-15 23:28     ` Qu Wenruo
2021-04-16 13:25       ` Josef Bacik
2021-04-15  5:04 ` [PATCH 05/42] btrfs: remove the unused parameter @len for btrfs_bio_fits_in_stripe() Qu Wenruo
2021-04-16 13:46   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 06/42] btrfs: allow btrfs_bio_fits_in_stripe() to accept bio without any page Qu Wenruo
2021-04-16 13:50   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 07/42] btrfs: use u32 for length related members of btrfs_ordered_extent Qu Wenruo
2021-04-16 13:54   ` Josef Bacik
2021-04-16 23:59     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 08/42] btrfs: pass btrfs_inode into btrfs_writepage_endio_finish_ordered() Qu Wenruo
2021-04-16 13:58   ` Josef Bacik
2021-04-17  0:02     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 09/42] btrfs: refactor how we finish ordered extent io for endio functions Qu Wenruo
2021-04-16 14:09   ` Josef Bacik
2021-04-17  0:06     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 10/42] btrfs: update the comments in btrfs_invalidatepage() Qu Wenruo
2021-04-16 14:32   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 11/42] btrfs: refactor btrfs_invalidatepage() Qu Wenruo
2021-04-16 14:42   ` Josef Bacik
2021-04-17  0:13     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 12/42] btrfs: make Private2 lifespan more consistent Qu Wenruo
2021-04-16 14:43   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 13/42] btrfs: rename PagePrivate2 to PageOrdered inside btrfs Qu Wenruo
2021-04-16 14:49   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 14/42] btrfs: pass bytenr directly to __process_pages_contig() Qu Wenruo
2021-04-16 14:58   ` Josef Bacik
2021-04-17  0:15     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 15/42] btrfs: refactor the page status update into process_one_page() Qu Wenruo
2021-04-16 15:06   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 16/42] btrfs: provide btrfs_page_clamp_*() helpers Qu Wenruo
2021-04-16 15:09   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 17/42] btrfs: only require sector size alignment for end_bio_extent_writepage() Qu Wenruo
2021-04-16 15:13   ` Josef Bacik
2021-04-17  0:16     ` Qu Wenruo
2021-04-15  5:04 ` [PATCH 18/42] btrfs: make btrfs_dirty_pages() to be subpage compatible Qu Wenruo
2021-04-16 15:14   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 19/42] btrfs: make __process_pages_contig() to handle subpage dirty/error/writeback status Qu Wenruo
2021-04-16 15:20   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 20/42] btrfs: make end_bio_extent_writepage() to be subpage compatible Qu Wenruo
2021-04-16 15:21   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 21/42] btrfs: make process_one_page() to handle subpage locking Qu Wenruo
2021-04-16 15:36   ` Josef Bacik
2021-04-15  5:04 ` [PATCH 22/42] btrfs: introduce helpers for subpage ordered status Qu Wenruo
2021-04-15  5:04 ` [PATCH 23/42] btrfs: make page Ordered bit to be subpage compatible Qu Wenruo
2021-04-15  5:04 ` [PATCH 24/42] btrfs: update locked page dirty/writeback/error bits in __process_pages_contig Qu Wenruo
2021-04-15  5:04 ` [PATCH 25/42] btrfs: prevent extent_clear_unlock_delalloc() to unlock page not locked by __process_pages_contig() Qu Wenruo
2021-04-15  5:04 ` [PATCH 26/42] btrfs: make btrfs_set_range_writeback() subpage compatible Qu Wenruo
2021-04-15  5:04 ` [PATCH 27/42] btrfs: make __extent_writepage_io() only submit dirty range for subpage Qu Wenruo
2021-04-15  5:04 ` [PATCH 28/42] btrfs: add extra assert for submit_extent_page() Qu Wenruo
2021-04-15  5:04 ` [PATCH 29/42] btrfs: make btrfs_truncate_block() to be subpage compatible Qu Wenruo
2021-04-15  5:04 ` [PATCH 30/42] btrfs: make btrfs_page_mkwrite() " Qu Wenruo
2021-04-15  5:04 ` [PATCH 31/42] btrfs: reflink: make copy_inline_to_page() " Qu Wenruo
2021-04-15  5:04 ` [PATCH 32/42] btrfs: fix the filemap_range_has_page() call in btrfs_punch_hole_lock_range() Qu Wenruo
2021-04-15  5:04 ` [PATCH 33/42] btrfs: don't clear page extent mapped if we're not invalidating the full page Qu Wenruo
2021-04-15  5:04 ` [PATCH 34/42] btrfs: extract relocation page read and dirty part into its own function Qu Wenruo
2021-04-15  5:04 ` [PATCH 35/42] btrfs: make relocate_one_page() to handle subpage case Qu Wenruo
2021-04-15  5:04 ` [PATCH 36/42] btrfs: fix wild subpage writeback which does not have ordered extent Qu Wenruo
2021-04-15  5:04 ` [PATCH 37/42] btrfs: disable inline extent creation for subpage Qu Wenruo
2021-04-15  5:04 ` [PATCH 38/42] btrfs: skip validation for subpage read repair Qu Wenruo
2021-04-15  5:04 ` [PATCH 39/42] btrfs: make free space cache size consistent across different PAGE_SIZE Qu Wenruo
2021-04-15  5:04 ` [PATCH 40/42] btrfs: refactor submit_extent_page() to make bio and its flag tracing easier Qu Wenruo
2021-04-15  5:04 ` [PATCH 41/42] btrfs: allow submit_extent_page() to do bio split for subpage Qu Wenruo
2021-04-15  5:04 ` [PATCH 42/42] btrfs: allow read-write for 4K sectorsize on 64K page size systems Qu Wenruo

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=a442f0df-d4d7-50ca-e4c3-224200ef9a70@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@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.