mbox series

[0/2] btrfs: fix generic/563 failures with sectorsize < PAGE_SIZE

Message ID cover.1727833878.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs: fix generic/563 failures with sectorsize < PAGE_SIZE | expand

Message

Qu Wenruo Oct. 2, 2024, 1:52 a.m. UTC
The test case generic/563 always fail on 64K page sized systems with
btrfs, however there are two different causes:

- sector size == page size
  In that case, it's the test case not using aligned block size, causing
  the btrfs (and ext4) to read out the full page before buffered write.

  This is fixed by the following patch:
  https://lore.kernel.org/linux-btrfs/20240929235038.24497-1-wqu@suse.com/

- sector size < page size
  This is a problem inside btrfs, which can not handle partial uptodate
  pages, thus even if the buffered write covers a full sector, btrfs
  will still read the full page, causing unnecessary IO.
  This is btrfs specific, and ext4/xfs doesn't not have this problem.

This patchset fix the sector size < page size case for btrfs, by:

- Changing btrfs_do_readpage() to do block-by-block read
  This allows btrfs to do per-sector uptodate check, not just relying on
  the extent map checks.

- Changing both buffered read and write path to handle partial uptodate
  pages
  For the buffered write path, it's pretty straight forward, just skip
  the full page read if the range covers full sectors.

  It's the buffered read path needs the extra work, by skipping any read
  into the already uptodate sectors.

  Or we can have a dirtied range, and read (from holes) re-fill the
  dirtied range with 0, causing data corruption.

With these two patches, 4K sector sized btrfs on 64K page sized systems
can pass generic/563 now.

Although considering I have hit data corruption due to the above read
path not skipping uptodate sectors, I'm wondering should I put the full
page read skip code under EXPERIMENTAL flags.

At least this is only affecting subpage cases, the more common x86_64
cases will not be affected.

Qu Wenruo (2):
  btrfs: make btrfs_do_readpage() to do block-by-block read
  btrfs: allow buffered write to skip full page if it's sector aligned

 fs/btrfs/extent_io.c | 43 ++++++++++++++++++-------------------------
 fs/btrfs/file.c      |  5 +++--
 2 files changed, 21 insertions(+), 27 deletions(-)