]> www.infradead.org Git - users/jedix/linux-maple.git/commit
btrfs: prepare btrfs_punch_hole_lock_range() for large data folios
authorQu Wenruo <wqu@suse.com>
Thu, 27 Mar 2025 08:50:01 +0000 (19:20 +1030)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:40 +0000 (14:30 +0200)
commit1e5773e0bab761c853eaf7286394905a544ef02d
tree148daa52be1aebed13b812893ff6ed31ecfa50b0
parentbe8ef7990c6775c2bb1374abbde8f5408c527eba
btrfs: prepare btrfs_punch_hole_lock_range() for large data folios

The function btrfs_punch_hole_lock_range() needs to make sure there is
no other folio in the range, thus it goes with filemap_range_has_page(),
which works pretty fine.

But if we have large folios, under the following case
filemap_range_has_page() will always return true, forcing
btrfs_punch_hole_lock_range() to do a very time consuming busy loop:

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

In the above case, folio A and B contain our start/end indexes, and there
are no other folios in the range.  Thus we do not need to retry inside
btrfs_punch_hole_lock_range().

To prepare for large data folios, introduce a helper,
check_range_has_page(), which will:

- Shrink the search range towards page boundaries
  If the rounded down end (exclusive, otherwise it can underflow when @end
  is inside the folio at file offset 0) is no larger than the rounded up
  start, it means the range contains no other pages other than the ones
  covering @start and @end.

  Can return false directly in that case.

- Grab all the folios inside the range

- Skip any large folios that cover the start and end indexes

- If any other folios are found return true

- Otherwise return false

This new helper is going to handle both large folios and regular ones.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c