Skip to content

btrfs: split bio at btrfs_map_bio() time

Qu Wenruo linux-btrfs 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest18 patches 8 repliesIn review
  2. v217 patches 8 repliesSuperseded
  3. v117 patches 5 repliesSuperseded

Changes in v3 from the cover letter

- Rebased to latest misc-next
Now add extra patch to remove the btrfs_get_io_geometry() call used by encoded read.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/18btrfs: update an stale comment on btrfs_submit_bio_hook()fs/btrfs/inode.c+7 -11 reply
2/18btrfs: save bio::bi_iter into btrfs_bio::iter before any endiofs/btrfs/compression.c fs/btrfs/disk-io.c fs/btrfs/extent_io.c +3 more+32 -00 replies
3/18btrfs: use correct bio size for error message in btrfs_end_dio_bio()fs/btrfs/inode.c+10 -30 replies
4/18btrfs: refactor btrfs_map_bio()fs/btrfs/volumes.c+41 -260 replies
5/18btrfs: move btrfs_bio_wq_end_io() calls into submit_stripe_bio()fs/btrfs/compression.c fs/btrfs/disk-io.c fs/btrfs/inode.c +2 more+52 -310 replies
6/18btrfs: replace btrfs_dio_private::refs with btrfs_dio_private::pending_bytesfs/btrfs/btrfs_inode.h fs/btrfs/inode.c+38 -390 replies
7/18btrfs: introduce btrfs_bio_split() helperfs/btrfs/extent_io.c fs/btrfs/extent_io.h fs/btrfs/volumes.h+123 -40 replies
8/18btrfs: make data buffered read path to handle split bio properlyfs/btrfs/extent_io.c fs/btrfs/inode.c fs/btrfs/volumes.h+41 -190 replies
9/18btrfs: make data buffered write endio function to be split bio compatiblefs/btrfs/extent_io.c+12 -120 replies
10/18btrfs: make metadata write endio functions to be split bio compatiblefs/btrfs/extent_io.c+29 -140 replies
11/18btrfs: make dec_and_test_compressed_bio() to be split bio compatiblefs/btrfs/compression.c+5 -90 replies
12/18btrfs: return proper mapped length for RAID56 profiles in __btrfs_map_block()fs/btrfs/raid56.c fs/btrfs/raid56.h fs/btrfs/scrub.c +2 more+30 -120 replies
13/18btrfs: allow btrfs_map_bio() to split bio according to chunk stripe boundariesfs/btrfs/volumes.c+32 -180 replies
14/18btrfs: remove buffered IO stripe boundary calculationfs/btrfs/extent_io.c+2 -220 replies
15/18btrfs: remove stripe boundary calculation for compressed IOfs/btrfs/compression.c+5 -440 replies
16/18btrfs: remove the stripe boundary calculation for direct IOfs/btrfs/inode.c+24 -890 replies
17/18btrfs: remove the stripe boundary calcluation for encoded IOfs/btrfs/inode.c+1 -190 replies
18/18btrfs: unexport btrfs_get_io_geometry()fs/btrfs/volumes.c fs/btrfs/volumes.h+4 -70 replies

Reviews trailers per patch

1 of 18 patches has a Reviewed-by or Acked-by.

PatchChristoph Hellwig
1/18R-b
2/18
3/18
4/18
5/18
6/18
7/18
8/18
9/18
10/18
11/18
12/18
13/18
14/18
15/18
16/18
17/18
18/18

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/18] btrfs: split bio at btrfs_map_bio() time

This patchset be fetched from this branch:

https://github.com/adam900710/linux/tree/bio_split

[CHANGELOG]
RFC->v1:
- Better patch split
Now patch 01~06 are refactors/cleanups/preparations.
While 07~13 are the patches that doing the conversion while can handle both old and new bio split timings.
Finally patch 14~16 convert the bio split call sites one by one to newer facility.
The final patch is just a small clean up.

- Various bug fixes
During the full fstests run, various stupid bugs are exposed and fixed.

v2:
- Fix the error paths for allocated but never submitted bios There are tons of error path that we allocate a bio but it goes bio_endio() directly without going through btrfs_map_bio(). New ASSERTS() in endio functions require a populated btrfs_bio::iter, thus for such bios we still need to call btrfs_bio_save_iter() to populate btrfs_bio::iter to prevent such ASSERT()s get triggered.

- Fix scrub_stripe_index_and_offset() which abuses stripe_len and mapped_length

v3:
- Rebased to latest misc-next
Now add extra patch to remove the btrfs_get_io_geometry() call used by encoded read.

[BACKGROUND]

Currently btrfs never uses bio_split() to split its bio against RAID stripe boundaries.

Instead inside btrfs we check our stripe boundary every time we allocate a new bio, and ensure the new bio never cross stripe boundaries.

This will make later iomap integration much easier, currently Goldwyn is using btrfs_bio_clone() to clone bio from iomap, then using the cloned bio to do buffered read/write.

With this patchset, it will be much easier to integrate later iomap work.

[PROBLEMS]

Although this behavior works fine, it's against the common practice used in stacked drivers, and is making the effort to convert to iomap harder.

There is also an hidden burden, every time we allocate a new bio, we uses BIO_MAX_BVECS, but since we know the boundaries, for RAID0/RAID10 we can only fit at most 16 pages (fixed 64K stripe size, and 4K page size), wasting the 256 slots we allocated.

[CHALLENGES]

To change the situation, this patchset attempts to improve the situation by moving the bio split into btrfs_map_bio() time, so upper layer should no longer bother the bio split against RAID stripes or even chunk boundaries.

But there are several challenges:

- Conflicts in various endio functions
We want the existing granularity, instead of chained endio, thus we must make the involved endio functions to handle split bios.

Although most endio functions are already doing their works independent of the bio size, they are not yet fully handling split bio.

This patch will convert them to use saved bi_iter and only iterate the split range instead of the whole bio.
This change involved 3 types of IOs:

* Buffered IO
Including both data and metadata
* Direct IO
* Compressed IO

Their endio functions needs different level of updates to handle split bios.

Furthermore, there is another endio, end_workqueue_bio(), it can't handle split bios at all, thus we change the timing so that btrfs_bio_wq_end_io() is only called after the bio being split.

- Checksum verification
Currently we rely on btrfs_bio::csum to contain the checksum for the whole bio.
If one bio get split, csum will no longer points to the correct location for the split bio.

This can be solved by introducing btrfs_bio::offset_to_original, and use that new member to calculate where we should read csum from.

For the parent bio, it still has btrfs_bio::csum for the whole bio, thus it can still free it correctly.

- Independent endio for each split bio
Unlike stack drivers, for RAID10 btrfs needs to try its best effort to read every sectors, to handle the following case: (X means bad, either unable to read or failed to pass checksum verification, V means good)

Dev 1 (missing) | D1 (X) |

  Dev 2 (OK)	  | D1 (V) |
  Dev 3 (OK)	  | D2 (V) |
  Dev 4 (OK)	  | D2 (X) |

In the above RAID10 case, dev1 is missing, and although dev4 is fine, its D2 sector is corrupted (by bit rot or whatever).

If we use bio_chain(), read bio for both D1 and D2 will be split, and since D1 is missing, the whole D1 and D2 read will be marked as error, thus we will try to read from dev2 and dev4.

But D2 in dev4 has csum mismatch, we can only rebuild D1 and D2 correctly from dev2:D1 and dev3:D2.

This patchset resolve this by saving bi_iter into btrfs_bio::iter, and uses that at endio to iterate only the split part of an bio. Other than this, existing read/write page endio functions can handle them properly without problem.

- Bad RAID56 naming/functionality
There are quite some RAID56 call sites relies on specific behavior on __btrfs_map_block(), like returning @map_length as stripe_len other than real mapped length.

This is handled by some small cleanups specific for RAID56.

Qu Wenruo (18):
btrfs: update an stale comment on btrfs_submit_bio_hook()
btrfs: save bio::bi_iter into btrfs_bio::iter before any endio
btrfs: use correct bio size for error message in btrfs_end_dio_bio()
btrfs: refactor btrfs_map_bio()
btrfs: move btrfs_bio_wq_end_io() calls into submit_stripe_bio()
btrfs: replace btrfs_dio_private::refs with
btrfs_dio_private::pending_bytes
btrfs: introduce btrfs_bio_split() helper
btrfs: make data buffered read path to handle split bio properly
btrfs: make data buffered write endio function to be split bio
compatible
btrfs: make metadata write endio functions to be split bio compatible
btrfs: make dec_and_test_compressed_bio() to be split bio compatible
btrfs: return proper mapped length for RAID56 profiles in

    __btrfs_map_block()

btrfs: allow btrfs_map_bio() to split bio according to chunk stripe
boundaries
btrfs: remove buffered IO stripe boundary calculation
btrfs: remove stripe boundary calculation for compressed IO
btrfs: remove the stripe boundary calculation for direct IO
btrfs: remove the stripe boundary calcluation for encoded IO
btrfs: unexport btrfs_get_io_geometry()

 fs/btrfs/btrfs_inode.h |  10 +-
 fs/btrfs/compression.c |  70 +++----------
 fs/btrfs/disk-io.c     |  11 +-
 fs/btrfs/extent_io.c   | 214 ++++++++++++++++++++++++++------------
 fs/btrfs/extent_io.h   |   2 +
 fs/btrfs/inode.c       | 230 +++++++++++++++--------------------------
 fs/btrfs/raid56.c      |  14 ++-
 fs/btrfs/raid56.h      |   2 +-
 fs/btrfs/scrub.c       |  14 +--
 fs/btrfs/volumes.c     | 144 +++++++++++++++++++-------
 fs/btrfs/volumes.h     |  74 +++++++++++--
 11 files changed, 452 insertions(+), 333 deletions(-)
Signature · 1 line
2.35.1