]> git.hungrycats.org Git - linux/commitdiff
btrfs: stripe_meta: let the transaction machinery's own reservations draw on the...
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 6 Sep 2026 11:44:45 +0000 (07:44 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 18 Sep 2026 21:36:27 +0000 (17:36 -0400)
With the whole-stripe reserve counted as used for everyone but the
relocation task, a committing transaction whose handle reserve runs dry
mid-COW gets ENOSPC from btrfs_use_block_rsv(): its NO_FLUSH fallback
reservation is refused as soon as the claimable supply is below the
reserve, and the global reserve behind it has been refilled by fiat
against stripes that do not exist.  Seen on the delete phase of the
metadata fill test with relocation running: claimable 163 MiB, reserve
352 MiB, delayed refs freeing the deleted leaves, and the extent tree
COW that freeing needs aborted the transaction with ENOSPC while
163 MiB of whole stripes sat unused (no allocator canary: the allocator
was never asked).

The reserve exists to hold back user operations so relocation and the
commit that follows it have room; it must not hold back the commit.
Let NO_FLUSH, FLUSH_LIMIT (delayed refs, delayed inodes) and EMERGENCY
reservations draw on it like relocation does.  They are bounded and
kernel-internal; user reservations (FLUSH_ALL, ALL_STEAL, EVICT, DATA)
still stop at the reserve.

Assisted-by: Claude:claude-fable-5
fs/btrfs/space-info.c

index c723631149bfc107b61ca167c18c193a18b202f7..5e6dab5c1131fffdcb6f402955455ef2c16079d4 100644 (file)
@@ -1962,7 +1962,19 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
        u64 used;
        int ret = -ENOSPC;
        bool pending_tickets;
-       const bool reloc = (READ_ONCE(fs_info->reloc_task) == current);
+       /*
+        * Who may draw on the stripe_meta reserve (bytes_stripe_reserve):
+        * the relocation task, which is what the reserve is for, and the
+        * transaction machinery's own bounded reservations -- NO_FLUSH from
+        * btrfs_use_block_rsv() when a handle's reserve runs dry mid-COW,
+        * FLUSH_LIMIT for delayed refs and delayed inodes, EMERGENCY -- which
+        * a committing transaction cannot fail without aborting.  User
+        * operations (FLUSH_ALL, ALL_STEAL, EVICT, DATA) stay behind it.
+        */
+       const bool reloc = (READ_ONCE(fs_info->reloc_task) == current) ||
+                          flush == BTRFS_RESERVE_NO_FLUSH ||
+                          flush == BTRFS_RESERVE_FLUSH_LIMIT ||
+                          flush == BTRFS_RESERVE_FLUSH_EMERGENCY;
 
        ASSERT(orig_bytes, "orig_bytes=%llu", orig_bytes);
        /*