Skip to content

btrfs: simplify the stripe buffer handling

Qu Wenruo linux-btrfs 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest4 patches 3 repliesIn review
  2. v54 patches 0 repliesSuperseded
  3. v43 patches 0 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v32 patches2 repliesSuperseded

Changes in v6 from the cover letter

- Remove an ASSERT() that is no longer required
Since there is no code that even bothers the underlying page layout anymore, the ASSERT() for the alignment of kvmalloc() returned address can be safely removed now.

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4btrfs: remove SCRUB_MAX_SECTORS_PER_BLOCKfs/btrfs/scrub.c+0 -141 reply
2/4btrfs: extract the common scrub read endio into a helperfs/btrfs/scrub.c+26 -261 reply
3/4btrfs: scrub: implement calc_sector_number() in a faster wayfs/btrfs/scrub.c+13 -121 reply
4/4btrfs: use kvmalloc() for stripe buffer of scrub_stripefs/btrfs/raid56.c fs/btrfs/raid56.h fs/btrfs/scrub.c+69 -1030 replies

Reviews trailers per patch

3 of 4 patches have a Reviewed-by or Acked-by.

PatchJohannes Thumshirn
1/4R-b
2/4R-b
3/4R-b
4/4

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

Read the v6 thread

Cover letter [PATCH v6 0/4] btrfs: simplify the stripe buffer handling

[CHANGELOG]
v6:
- Remove an ASSERT() that is no longer required
Since there is no code that even bothers the underlying page layout anymore, the ASSERT() for the alignment of kvmalloc() returned address can be safely removed now.

v5:
- Use a simpler and faster way to implement calc_sector_number() Commit 81cea6cd7041 ("btrfs: remove btrfs_bio::fs_info by extracting it from btrfs_bio::inode") uses logical bytenr as the file_offset for scrub bbios, so we have a very reliable way to determine the bytenr, without the need to iterate through all the blocks.

This removes the only the caller that iterates through the scrub block addresses, and should also completely shut sashiko up on the impossible unaligned address returned by kvmalloc(64K).

v4:
- Add a patch to extract the common handling of scrub read endios This is to reduce duplication and allow a single invalidate_kernel_vmap_range() call to be added with proper comments.

- Add a comment on why we need to call invalidate_kernel_vmap_range() for vmallocated memory
It's mostly copied from dma-api doc.

v3:
- Add a patch to remove a unused macro

- Add new ASSERT()s to make sure the kvmallocated memory is page aligned The size is 64K, which is page aligned and power of 2, thus the resulted memory should at least be page aligned.

Furthermore, we have several call sites using (BTRFS_STRIPE_LEN / PAGE_SIZE) or (BTRFS_STRIPE_LEN >> PAGE_SHIFT), add an build time assert to make sure our PAGE_SIZE is not larger than BTRFS_STRIPE_LEN.

v2:
- Fix a potential double-free during release_scrub_stripe() Reported by sashiko.

- Enlarge the scrub bbio to be able to contain the full buffer Since the buffer is allocated by kvmalloc(), it's possible that not all pages are physically contiguous.

In that case we have to enlarge the bbio to contain (BTRFS_STRIPE_LEN >> PAGE_SHIFT) bvecs.

This is to use kvmalloc() to allocate a buffer for scrub, so that we do not need to bother page-switching, and simplify the scrub progress.

Qu Wenruo (4):
btrfs: remove SCRUB_MAX_SECTORS_PER_BLOCK
btrfs: extract the common scrub read endio into a helper
btrfs: scrub: implement calc_sector_number() in a faster way
btrfs: use kvmalloc() for stripe buffer of scrub_stripe

 fs/btrfs/raid56.c |  18 +---
 fs/btrfs/raid56.h |   2 +-
 fs/btrfs/scrub.c  | 235 +++++++++++++++++++---------------------------
 3 files changed, 104 insertions(+), 151 deletions(-)
Signature · 1 line
2.54.0