Skip to content

btrfs: simple enhancement and fix for delalloc range

Qu Wenruo linux-btrfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: replace double boolean parameters of cow_file_range()fs/btrfs/inode.c+17 -152 replies
2/3btrfs: make btrfs_cleanup_ordered_extents() to support large foliosfs/btrfs/inode.c+4 -21 reply
3/3btrfs: fix the wrong parameter for btrfs_cleanup_ordered_extents()fs/btrfs/inode.c+1 -11 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchBoris Burkov
1/3R-b
2/3R-b
3/3R-b

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

Read the v1 thread

Cover letter [PATCH 0/3] btrfs: simple enhancement and fix for delalloc range

When debugging the rare DEBUG_WARN() inside btrfs_writepage_cow_fixup(), I just found several small things to fix/enhance:

- The double boolean parameters of cow_file_range()
A simple enhancement with a single @flags to replace the two booleans.

- Inefficient folio iteration of btrfs_cleanup_ordered_extents() Enhance that function to support large folios better.

- Wrong parameters for btrfs_cleanup_ordered_extents() of nocow_one_range()
Due to the wrong parameter (end other than length), we may clear Ordered flags for range out of our control, which can be some page under writeback and cause the DEBUG_WARN() inside btrfs_writepage_cow_fixup().

However the call trace doesn't match the one I hit, which is normally cow_file_range() failure inside fallback_to_cow().
Not the failure from nocow_one_range().

Although I already have an idea why the DEBUG_WARN() in btrfs_writepage_cow_fixup() is triggered, the fix will be a little more complex.

The root cause is that btrfs_cleanup_ordered_extents() is called on unlocked folios inside run_delalloc_nocow().

As run_delalloc_nocow() can fallback to COW path, and succeeded cow_file_range() will unlock the folios, we have no other way but to do the cleanup on unlocked folios.

This has a small race window, where the unlocked folio is already under writeback, and we cleared the ordered flag halfway, thus triggerring the error.

The proper fix is to make run_delalloc_nocow() to keep folios (and io tree range) locked until the full range is finished, just like how cow_file_range() works, but that will be a much more complex series.

So for now just handle the small-and-simple enhancement and fix.

Qu Wenruo (3):
btrfs: replace double boolean parameters of cow_file_range()
btrfs: make btrfs_cleanup_ordered_extents() to support large folios
btrfs: fix the wrong parameter for btrfs_cleanup_ordered_extents()

 fs/btrfs/inode.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
Signature · 1 line
2.50.0