public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] btrfs: add the missing preparations exposed by initial large data folio support
@ 2025-03-27 22:31 Qu Wenruo
  2025-03-27 22:31 ` [PATCH 1/4] btrfs: subpage: fix a bug that blocks large folios Qu Wenruo
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Qu Wenruo @ 2025-03-27 22:31 UTC (permalink / raw)
  To: linux-btrfs

With all the existing preparations, finally I can enable and start
initial testing (aka, short fsstress loops).

To no one's surprise, it immeidately exposed several problems:

- A critical subpage helper is still using offset_in_page()
  Which causes incorrect start bit calculation and triggered the
  ASSERT() inside subpage locking.

  Fixed in the first patch.

- Buffered write can not shrink reserved space properly
  Since we're reserving data and metadata space before grabbing the
  folio, we have to reserved as much space as possible, other than just
  reserving space for the range inside the page.

  If the folio we got is smaller than what we expect, we have to shrink
  the reserved space, but things like btrfs_delalloc_release_extents()
  can not handle it.

  Fixed in the second patch, with a new helper
  btrfs_delalloc_shrink_extents().

  This will also be a topic in in the iomap migration, iomap goes
  valid_folio() callbacks to make sure no extent map is changed during
  our buffered write, thus they can reserve a large range of space,
  other than our current over-reserve-then-shrink.

  Our behavior is super safe, but less optimized compared to iomap.

- Buffered write is not utilizing large folios
  Since buffered write is the main entrance to allocate large folios,
  without its support there will be no large folios at all.

  Addressed in the third patch.

- Long CPU busy loops inside btrfs_punch_hole_lock_range()
  It turns out that the usage of filemap_range_has_page() is never a
  good idea for large folios, as we can easily hit the following case:

          start                            end
          |                                |
    |//|//|//|//|  |  |  |  |  |  |  |  |//|//|
     \         /                         \   /
      Folio A                            Folio B

  Fixed in the fourth patch, with a helper check_range_has_page() to do
  the check with large folios in mind.

  This will also be a topic in the iomap migration, as our zero range
  behavior is quite different from the iomap one, and the
  filemap_range_has_page() behavior looks a little overkilled to me.

I'm pretty sure there will be more hidden bugs after I throw the whole
fstests to my local branch, but that's all the bugs I have so far.

Qu Wenruo (4):
  btrfs: subpage: fix a bug that blocks large folios
  btrfs: refactor how we handle reserved space inside copy_one_range()
  btrfs: prepare btrfs_buffered_write() for large data folios
  btrfs: prepare btrfs_punch_hole_lock_range() for large data folios

 fs/btrfs/delalloc-space.c |  25 ++++++
 fs/btrfs/delalloc-space.h |   3 +-
 fs/btrfs/file.c           | 184 ++++++++++++++++++++++++++++----------
 fs/btrfs/subpage.c        |   2 +-
 4 files changed, 165 insertions(+), 49 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-03-29  3:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-27 22:31 [PATCH 0/4] btrfs: add the missing preparations exposed by initial large data folio support Qu Wenruo
2025-03-27 22:31 ` [PATCH 1/4] btrfs: subpage: fix a bug that blocks large folios Qu Wenruo
2025-03-28 17:36   ` Filipe Manana
2025-03-27 22:31 ` [PATCH 2/4] btrfs: refactor how we handle reserved space inside copy_one_range() Qu Wenruo
2025-03-28 17:45   ` Filipe Manana
2025-03-27 22:31 ` [PATCH 3/4] btrfs: prepare btrfs_buffered_write() for large data folios Qu Wenruo
2025-03-28 17:51   ` Filipe Manana
2025-03-27 22:31 ` [PATCH 4/4] btrfs: prepare btrfs_punch_hole_lock_range() " Qu Wenruo
2025-03-28 17:57   ` Filipe Manana
2025-03-29  3:18     ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox