All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@lst.de>, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Cc: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 08/15] btrfs: refactor end_bio_extent_readpage
Date: Wed, 18 May 2022 06:22:54 +0800	[thread overview]
Message-ID: <5dc10aca-29ce-9318-c8f9-9ea83b35dde1@gmx.com> (raw)
In-Reply-To: <20220517145039.3202184-9-hch@lst.de>



On 2022/5/17 22:50, Christoph Hellwig wrote:
> Untangle the goto mess and remove the pointless 'ret' local variable.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   fs/btrfs/extent_io.c | 87 +++++++++++++++++++++-----------------------
>   1 file changed, 41 insertions(+), 46 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index f96d5b7071813..1ba2d4b194f2e 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -3028,7 +3028,6 @@ static void end_bio_extent_readpage(struct bio *bio)
>   	 */
>   	u32 bio_offset = 0;
>   	int mirror;
> -	int ret;
>   	struct bvec_iter_all iter_all;
>
>   	ASSERT(!bio_flagged(bio, BIO_CLONED));
> @@ -3039,6 +3038,7 @@ static void end_bio_extent_readpage(struct bio *bio)
>   		struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>   		const u32 sectorsize = fs_info->sectorsize;
>   		unsigned int error_bitmap = (unsigned int)-1;
> +		bool repair = false;
>   		u64 start;
>   		u64 end;
>   		u32 len;
> @@ -3076,55 +3076,23 @@ static void end_bio_extent_readpage(struct bio *bio)
>   			if (is_data_inode(inode)) {
>   				error_bitmap = btrfs_verify_data_csum(bbio,
>   						bio_offset, page, start, end);
> -				ret = error_bitmap;
> +				if (error_bitmap)
> +					uptodate = false;
>   			} else {
> -				ret = btrfs_validate_metadata_buffer(bbio,
> -					page, start, end, mirror);
> +				if (btrfs_validate_metadata_buffer(bbio,
> +						page, start, end, mirror))
> +					uptodate = false;
>   			}
> -			if (ret)
> -				uptodate = false;
> -			else
> -				clean_io_failure(BTRFS_I(inode)->root->fs_info,
> -						 failure_tree, tree, start,
> -						 page,
> -						 btrfs_ino(BTRFS_I(inode)), 0);
>   		}
>
> -		if (likely(uptodate))
> -			goto readpage_ok;
> -
> -		if (is_data_inode(inode)) {
> -			/*
> -			 * If we failed to submit the IO at all we'll have a
> -			 * mirror_num == 0, in which case we need to just mark
> -			 * the page with an error and unlock it and carry on.
> -			 */
> -			if (mirror == 0)
> -				goto readpage_ok;
> -
> -			/*
> -			 * submit_data_read_repair() will handle all the good
> -			 * and bad sectors, we just continue to the next bvec.
> -			 */
> -			submit_data_read_repair(inode, bio, bio_offset, bvec,
> -						mirror, error_bitmap);
> -
> -			ASSERT(bio_offset + len > bio_offset);
> -			bio_offset += len;
> -			continue;
> -		} else {
> -			struct extent_buffer *eb;
> -
> -			eb = find_extent_buffer_readpage(fs_info, page, start);
> -			set_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags);
> -			eb->read_mirror = mirror;
> -			atomic_dec(&eb->io_pages);
> -		}
> -readpage_ok:
>   		if (likely(uptodate)) {
>   			loff_t i_size = i_size_read(inode);
>   			pgoff_t end_index = i_size >> PAGE_SHIFT;
>
> +			clean_io_failure(BTRFS_I(inode)->root->fs_info,
> +					 failure_tree, tree, start, page,
> +					 btrfs_ino(BTRFS_I(inode)), 0);
> +
>   			/*
>   			 * Zero out the remaining part if this range straddles
>   			 * i_size.
> @@ -3141,14 +3109,41 @@ static void end_bio_extent_readpage(struct bio *bio)
>   				zero_user_segment(page, zero_start,
>   						  offset_in_page(end) + 1);
>   			}
> +		} else if (is_data_inode(inode)) {
> +			/*
> +			 * Only try to repair bios that actually made it to a
> +			 * device.  If the bio failed to be submitted mirror
> +			 * is 0 and we need to fail it without retrying.
> +			 */
> +			if (mirror > 0)
> +				repair = true;

In fact, you can do it even better, by also checking the number of
copies the bio has.

That what I missed in my all patchset, and completely relies on the
mirror based loop to exit.

> +		} else {
> +			struct extent_buffer *eb;
> +
> +			eb = find_extent_buffer_readpage(fs_info, page, start);
> +			set_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags);
> +			eb->read_mirror = mirror;
> +			atomic_dec(&eb->io_pages);
>   		}
> +
> +		if (repair) {
> +			/*
> +			 * submit_data_read_repair() will handle all the good
> +			 * and bad sectors, we just continue to the next bvec.
> +			 */
> +			submit_data_read_repair(inode, bio, bio_offset, bvec,
> +						mirror, error_bitmap);
> +		} else {
> +			/* Update page status and unlock */
> +			end_page_read(page, uptodate, start, len);
> +			endio_readpage_release_extent(&processed,
> +					BTRFS_I(inode), start, end,
> +					PageUptodate(page));

Another reason I'm not introducing the end_sector_io().

Here the code looks super familiar with end_sector_io(), but due to the
@processed interface, it's not compatible with end_sector_io(), or we
will do the unlock with way more io_tree operations with much smaller
range, thus reduces performance.

Thanks,
Qu

> +		}
> +
>   		ASSERT(bio_offset + len > bio_offset);
>   		bio_offset += len;
>
> -		/* Update page status and unlock */
> -		end_page_read(page, uptodate, start, len);
> -		endio_readpage_release_extent(&processed, BTRFS_I(inode),
> -					      start, end, PageUptodate(page));
>   	}
>   	/* Release the last extent */
>   	endio_readpage_release_extent(&processed, NULL, 0, 0, false);

  reply	other threads:[~2022-05-17 22:23 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17 14:50 simple synchronous read repair Christoph Hellwig
2022-05-17 14:50 ` [PATCH 01/15] btrfs: introduce a pure data checksum checking helper Christoph Hellwig
2022-05-17 14:59   ` Johannes Thumshirn
2022-05-18  8:44     ` Christoph Hellwig
2022-05-20  8:45   ` Nikolay Borisov
2022-05-20 16:24     ` Christoph Hellwig
2022-05-17 14:50 ` [PATCH 02/15] btrfs: quit early if the fs has no RAID56 support for raid56 related checks Christoph Hellwig
2022-05-17 15:00   ` Johannes Thumshirn
2022-05-18 17:07   ` Anand Jain
2022-05-20  8:47   ` Nikolay Borisov
2022-05-20 16:25     ` Christoph Hellwig
2022-05-20 22:36       ` Qu Wenruo
2022-05-17 14:50 ` [PATCH 03/15] btrfs: save the original bi_iter into btrfs_bio for buffered read Christoph Hellwig
2022-05-17 14:50 ` [PATCH 04/15] btrfs: remove duplicated parameters from submit_data_read_repair() Christoph Hellwig
2022-05-17 15:35   ` Johannes Thumshirn
2022-05-20 10:05   ` Nikolay Borisov
2022-05-17 14:50 ` [PATCH 05/15] btrfs: add a helper to iterate through a btrfs_bio with sector sized chunks Christoph Hellwig
2022-05-17 15:27   ` Johannes Thumshirn
2022-05-18  8:46     ` Christoph Hellwig
2022-05-18 10:07       ` Qu Wenruo
2022-05-20 16:27         ` Christoph Hellwig
2022-05-21  1:16           ` Qu Wenruo
2022-05-17 14:50 ` [PATCH 06/15] btrfs: make repair_io_failure available outside of extent_io.c Christoph Hellwig
2022-05-17 15:18   ` Johannes Thumshirn
2022-05-17 14:50 ` [PATCH 07/15] btrfs: factor out a helper to end a single sector from submit_data_read_repair Christoph Hellwig
2022-05-17 15:18   ` Johannes Thumshirn
2022-05-17 22:17   ` Qu Wenruo
2022-05-17 14:50 ` [PATCH 08/15] btrfs: refactor end_bio_extent_readpage Christoph Hellwig
2022-05-17 22:22   ` Qu Wenruo [this message]
2022-05-18  8:48     ` Christoph Hellwig
2022-05-17 14:50 ` [PATCH 09/15] btrfs: factor out a btrfs_csum_ptr helper Christoph Hellwig
2022-05-17 15:24   ` Johannes Thumshirn
2022-05-18  8:45     ` Christoph Hellwig
2022-05-17 14:50 ` [PATCH 10/15] btrfs: add a btrfs_map_bio_wait helper Christoph Hellwig
2022-05-17 15:37   ` Johannes Thumshirn
2022-05-17 22:26   ` Qu Wenruo
2022-05-18  8:47     ` Christoph Hellwig
2022-05-17 14:50 ` [PATCH 11/15] btrfs: set ->file_offset in end_bio_extent_readpage Christoph Hellwig
2022-05-17 22:47   ` Qu Wenruo
2022-05-17 14:50 ` [PATCH 12/15] btrfs: add new read repair infrastructure Christoph Hellwig
2022-05-17 23:04   ` Qu Wenruo
2022-05-18  8:54     ` Christoph Hellwig
2022-05-18 10:20       ` Qu Wenruo
2022-05-18 12:48         ` Christoph Hellwig
2022-05-19  9:36     ` Christoph Hellwig
2022-05-19 10:41       ` Qu Wenruo
2022-05-19 10:45         ` Nikolay Borisov
2022-05-19 10:46           ` Qu Wenruo
2022-05-19 10:50         ` Christoph Hellwig
2022-05-19 11:27           ` Qu Wenruo
2022-05-20  6:43         ` Why btrfs no longer allocate the extent at the beginning of an empty chunk (was: Re: [PATCH 12/15] btrfs: add new read repair infrastructure) Qu Wenruo
2022-05-20 15:25     ` [PATCH 12/15] btrfs: add new read repair infrastructure Christoph Hellwig
2022-05-17 14:50 ` [PATCH 13/15] btrfs: use the new read repair code for direct I/O Christoph Hellwig
2022-05-17 14:50 ` [PATCH 14/15] btrfs: use the new read repair code for buffered reads Christoph Hellwig
2022-05-17 14:50 ` [PATCH 15/15] btrfs: remove io_failure_record infrastructure completely Christoph Hellwig

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=5dc10aca-29ce-9318-c8f9-9ea83b35dde1@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --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.