]> git.hungrycats.org Git - linux/commitdiff
low-space: export patch 3 (merge-reservation flush) and describe it in the cover
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 09:13:48 +0000 (05:13 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 09:13:48 +0000 (05:13 -0400)
m-reloc's "btrfs: relocation: flush fully before failing a merge
reservation" is promoted on both lanes.  The cover becomes 0/3 with a
paragraph on the fix, TESTING.md marks it promoted with the lane SHAs,
and the README has the new heads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B6wxsJn1aY7PwnhgXdz6Ec

README.md
topics/low-space/0000-cover-letter.patch
topics/low-space/0001-btrfs-print-the-error-when-reclaim-fails-to-relocate.patch
topics/low-space/0002-btrfs-hold-block-groups-free-for-relocation.patch
topics/low-space/0003-btrfs-relocation-flush-fully-before-failing-a-merge-.patch [new file with mode: 0644]
topics/low-space/TESTING.md

index ddbd958d1a6cf604d0a97087eefc6619180bf146..b145e19c0cdf387511c2d070f0f45273c5980b76 100644 (file)
--- a/README.md
+++ b/README.md
@@ -8,8 +8,8 @@ upstream at all (see the table).
 | | |
 |---|---|
 | base of every series | `0c48d26d46bd` ("btrfs: stop reading free space inodes from the commit root"), the misc-next lane base (`misc-next/testing^1`) |
-| integration branch | `misc-next/testing` `723245adb5c1` (octopus of all 19 topics) |
-| lane head | `zygo-misc-next-zb64` `2550544f9c6e`; its own commits on top of `testing` (kernel configs, `covers/`) are not exported |
+| integration branch | `misc-next/testing` `02806563b90a` (octopus of all 19 topics) |
+| lane head | `zygo-misc-next-zb64` `7278042598d8`; its own commits on top of `testing` (kernel configs, `covers/`) are not exported |
 
 The base is not a published commit: the lane rebuilds it from
 btrfs/for-next plus David Sterba's queue.  It lives in the
@@ -70,7 +70,7 @@ the integration recipe below uses.
 | `raid56-fixes` | 12 | `f7e693d10be2` | Zygo | new; replaces `covers/raid56-rbio-fixes.txt` (2 of these patches) | **patch 12 is DO-NOT-UPSTREAM** (rbio cache size debug knob) |
 | `raid56-scrub-replace` | 13 | `9970d7e44abf` | Filipe Manana, Zygo | new | patch 1 is Filipe's, already in btrfs/for-next (`ec0795c045c3`) |
 | `stripe-alloc` | 114 | `bcadbfc8ac02` | Zygo | rewritten 2026-10-22 by subtopic (rebuild planned, REORDER-PLAN.md) | RFC; subtopic 6 (debug) not for merging; stripe_meta may be dropped (STRIPE-META-CLAIMS.md) |
-| `low-space` | 2 | `57034df182f0` | Zygo | from misc-next `covers/`, current | reserve off by default |
+| `low-space` | 3 | `4f26c7c44896` | Zygo | from misc-next `covers/`, patch 3 paragraph added 2026-10-22 | reserve off by default; patch 3 fixes an upstream relocation abort (FLUSH_LIMIT merge refill) |
 | `dedupe-mtime` | 1 | `288d851bbbc2` | Ivan Kozik | new, 0/1 (drafted 2026-10-18) | Ivan's patch |
 | `dm-stripfault` | 2 | `9ab63d7ab0fa` | Zygo | new | **test fixtures, NOT for merge** (no `To:`) |
 | `allocator-hints` | 12 | `43c53b3f02db` | Kai Krakow, KeinNiemand, Zygo | new | Kai's series plus follow-ups; the authors' postings are authoritative |
@@ -204,5 +204,5 @@ The fixup adds 640 lines and removes 16, in 10 files.
 - `balance-resume` patch 3 is offered for rejection, as its cover letter
   says.
 - Re-export with `scripts/export.sh` after any lane change.  The
-  directories reflect the lane at `misc-next/testing` `723245adb5c1`.
+  directories reflect the lane at `misc-next/testing` `02806563b90a`.
   Commit the result with the misc-next SHAs that the script prints.
index e965d02569e79709f9ff4de21485498b9d7e2614..6eca19ebe21848df4d8592bbe41220446471dfe3 100644 (file)
@@ -1,7 +1,7 @@
-From 57034df182f0238f0420d4b958e4f3d0b06f7959 Mon Sep 17 00:00:00 2001
+From 4f26c7c448962f551ae85038d4ca3971d109ec9b Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:17 -0400
-Subject: [PATCH 0/2] btrfs: keep room to relocate on a full filesystem
+Date: Thu, 22 Oct 2026 05:12:25 -0400
+Subject: [PATCH 0/3] btrfs: keep room to relocate on a full filesystem
 To: linux-btrfs@vger.kernel.org
 
 A btrfs filesystem that fills up needs relocation to get out: automatic
@@ -91,20 +91,28 @@ raid1 metadata and raid5 data with raid5 metadata, under KASAN.
 System chunks are not covered: balance -m relocates them too, and a
 full filesystem can still fail there.
 
-[Candidate patch 3, not yet in this series (refs/cand/m-reloc):
-"btrfs: relocation: flush fully before failing a merge reservation".
-merge_reloc_root() refills relocation's block reserve with
-BTRFS_RESERVE_FLUSH_LIMIT, so at the fill edge a merge step can fail
-with ENOSPC, which forces the filesystem read-only, while delayed refs,
-a commit or the global reserve could have served it.  The patch uses
-BTRFS_RESERVE_FLUSH_EVICT.  If promoted, this letter needs a paragraph
-on it and the subject becomes 0/3.  It does not cover the other abort
-found at the same edge (a commit's delayed refs after a relocation frees
-a burst of tree blocks); see TESTING.md.]
-
-Zygo Blaxell (2):
+Patch 3 fixes a transaction abort in upstream relocation code that the
+same fill edge exposes, with or without the reserve.  merge_reloc_root()
+refills relocation's block reserve before each merge step with
+BTRFS_RESERVE_FLUSH_LIMIT, which runs neither delayed refs nor a commit
+and never touches the global reserve.  At the fill edge a refill then
+fails with ENOSPC and merge_reloc_roots() forces the filesystem
+read-only, although delayed refs, a commit (9 MiB was pinned) or the
+global reserve would have covered it.  On a 6-device raid5 filesystem
+under fsstress with every device allocated, background reclaim aborted this way 3 times out of 3;
+with the patch, 6 runs had no merge failure, and every refill that
+needed flushing was served by the delayed-ref states.  The patch
+refills with BTRFS_RESERVE_FLUSH_EVICT.  Its message explains why
+FLUSH_LIMIT was chosen (killability, not a deadlock), why no other mode
+fits, and why flushing here cannot deadlock.  A second abort at the same
+edge is not fixed here: a commit's delayed refs can still run out of
+metadata after a relocation pins a burst of freed tree blocks (see
+TESTING.md).
+
+Zygo Blaxell (3):
   btrfs: print the error when reclaim fails to relocate a block group
   btrfs: hold block groups free for relocation
+  btrfs: relocation: flush fully before failing a merge reservation
 
  fs/btrfs/block-group.c | 366 ++++++++++++++++++++++++++++++++++++++++-
  fs/btrfs/block-group.h |  23 +++
@@ -112,13 +120,13 @@ Zygo Blaxell (2):
  fs/btrfs/extent-tree.c |  34 +++-
  fs/btrfs/extent-tree.h |   3 +
  fs/btrfs/fs.h          |  12 ++
- fs/btrfs/relocation.c  |   2 +
+ fs/btrfs/relocation.c  |  13 +-
  fs/btrfs/space-info.c  |  67 +++++++-
  fs/btrfs/space-info.h  |  19 ++-
  fs/btrfs/super.c       |   2 +
  fs/btrfs/sysfs.c       |  48 ++++++
  fs/btrfs/volumes.c     |  31 ++++
- 12 files changed, 604 insertions(+), 9 deletions(-)
+ 12 files changed, 614 insertions(+), 10 deletions(-)
 
 
 base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
index fa9bcafcbbc6a727266b6ead71ed22e44fb3e0b3..e841b363b222da86311cbec8469e2731ef3d44e0 100644 (file)
@@ -1,7 +1,7 @@
 From bd9f6c46fa79374ba55701eec56a461cc663e23a Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
 Date: Sun, 27 Sep 2026 15:02:40 -0400
-Subject: [PATCH 1/2] btrfs: print the error when reclaim fails to relocate a
+Subject: [PATCH 1/3] btrfs: print the error when reclaim fails to relocate a
  block group
 To: linux-btrfs@vger.kernel.org
 
index bc3410712299c090ed46c8bb5db67e7611bbf8cd..e931e8c486affe5566775455a62ce64249b80064 100644 (file)
@@ -1,7 +1,7 @@
 From 57034df182f0238f0420d4b958e4f3d0b06f7959 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
 Date: Mon, 28 Sep 2026 18:14:56 -0400
-Subject: [PATCH 2/2] btrfs: hold block groups free for relocation
+Subject: [PATCH 2/3] btrfs: hold block groups free for relocation
 To: linux-btrfs@vger.kernel.org
 
 Relocating a block group needs somewhere to write its live data, and a
diff --git a/topics/low-space/0003-btrfs-relocation-flush-fully-before-failing-a-merge-.patch b/topics/low-space/0003-btrfs-relocation-flush-fully-before-failing-a-merge-.patch
new file mode 100644 (file)
index 0000000..7e1cf7a
--- /dev/null
@@ -0,0 +1,163 @@
+From 4f26c7c448962f551ae85038d4ca3971d109ec9b Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 21 Oct 2026 12:48:13 -0400
+Subject: [PATCH 3/3] btrfs: relocation: flush fully before failing a merge
+ reservation
+To: linux-btrfs@vger.kernel.org
+
+merge_reloc_root() refills the relocation block reserve before each step
+of the merge.  Since 44d354abf33e ("btrfs: relocation: review the call
+sites which can be interrupted by signal") it does so with
+BTRFS_RESERVE_FLUSH_LIMIT.  FLUSH_LIMIT only flushes delayed items and
+tries to allocate a chunk.  It does not run delayed refs, does not flush
+delalloc, does not commit the transaction to unpin what the merge and
+everybody else freed, and never falls back to the global reserve.  A
+failure here is fatal: merge_reloc_roots() handles it with
+btrfs_handle_fs_error() and the filesystem goes read-only.
+
+The merge routinely needs more than prepare_to_merge() reserved for it,
+and refills from free space.  On a filesystem with every device
+allocated, metadata free space is all in other tasks' reservations, and
+the refill loses:
+
+  BTRFS: error (device dm-6) in merge_reloc_roots:2053: errno=-28 No space left
+  BTRFS info (device dm-6 state E): forced readonly
+  BTRFS error (device dm-6 state EA): error relocating chunk 14022541312: -28
+
+This is the reclaim worker relocating a data block group of a 6-device
+raid5 filesystem (metadata raid1) with 6 MiB unallocated, under
+fsstress.  A trace of the failing merge: prepare_to_merge() reserved 704
+KiB, the merge used it up and refilled 14 times (560 KiB more), and the
+15th refill, for 32 KiB, failed.  At that moment the metadata space_info
+(256 MiB) had 160 MiB used, 9 MiB pinned and 86 MiB in may_use, of which
+27 MiB was the untouched global reserve: 16 KiB free.  Background
+reclaim is optional work; it took the filesystem down.
+
+Refill with BTRFS_RESERVE_FLUSH_EVICT instead.
+
+Why FLUSH_LIMIT was chosen.  This refill used FLUSH_ALL from
+08e007d2e577 ("Btrfs: improve the noflush reservation") until
+44d354abf33e.  That commit changed it only so that a fatal signal cannot
+interrupt the merge:  FLUSH_ALL waits for its ticket killably and
+returns -EINTR, which here would turn a killed balance into a read-only
+filesystem.  Its message already notes that the change "can be
+ENOSPC-prone", and it shrank min_reserved to compensate.  No deadlock
+was given as a reason.
+
+Why not another mode.  No existing mode is "run delayed refs and commit,
+but neither flush delalloc nor steal, and do not wait killably":
+- FLUSH_LIMIT does not run delayed refs, which is what the merge refills
+  that needed flushing in testing needed.
+- FLUSH_ALL and FLUSH_ALL_STEAL flush delalloc and commit too, through
+  the async reclaim worker, and wait killably.  That brings back the
+  -EINTR that 44d354abf33e removed.
+- FLUSH_EVICT is the priority flusher with the full list: delayed items,
+  delayed refs, delalloc, chunk allocation and a commit, in that order,
+  run in the caller's context.  It stops at the first state that serves
+  the ticket, does not wait killably, and steals from the global reserve
+  only after all of them have failed.
+In testing, every merge refill that needed flushing was served by the
+delayed-ref states (5 of 6 tickets; the sixth needed only delayed
+items).  None reached delalloc, the commit or the steal.  Those states
+run only where the old code forced the filesystem read-only.
+
+Deadlock analysis.  At the refill the merging task holds:
+- No transaction handle.  The previous step ended its transaction with
+  btrfs_end_transaction_throttle(), and the first step has not started
+  one, so current->journal_info is NULL, as FLUSH_EVICT requires.
+- No tree locks.  The path into the reloc tree holds references only
+  (the reloc tree is walked without locks, and btrfs_unlock_up_safe()
+  dropped the locks of the resume search). replace_path() unlocks the
+  subvolume tree before it returns.
+- Not reloc_mutex. merge_reloc_roots() takes it only around its list
+  splices.
+- These locks from its callers: cleaner_mutex (do_nonremap_reloc()),
+  reclaim_bgs_lock, the exclusive operation, and sb_start_write for a
+  data block group.  Writeback, ordered extent completion and
+  transaction commit take none of them.  The other takers of
+  reclaim_bgs_lock either use trylock (unused block group deletion, the
+  reclaim worker) or are relocation entry points (balance, system chunk
+  relocation, device shrink, zoned repair).  Those take it with no
+  transaction handle held, and the exclusive operation serializes them
+  with this one anyway.  The other takers of cleaner_mutex are the
+  cleaner (trylock), mount and unmount (btrfs_start_pre_rw_mount(),
+  btrfs_commit_super()) and the quota ioctl, which takes it before
+  starting a transaction.  So no flush or commit can wait on a lock that
+  the merging task holds.
+
+The same task already does each of these things in the same lock
+context:
+- prepare_to_merge() reserves with FLUSH_ALL, waiting while the async
+  reclaim worker flushes delalloc and commits, and then commits itself.
+- relocate_block_group() commits again after the merge.
+- btrfs_end_transaction_throttle() at the end of every merge step runs
+  delayed iputs.  An evicted inode reserves with FLUSH_EVICT from right
+  there.
+
+A commit in the middle of the merge is legal.  The transaction kthread,
+sync and other tasks already commit between merge steps.  Each step
+saves drop_progress and drop_level before it ends its transaction, and
+the commit writes them to the reloc root item through
+btrfs_update_reloc_root(). init_reloc_root() creates nothing while
+rc->merge_reloc_tree is set. btrfs_end_transaction_throttle() used to
+commit from this loop itself, until 302167c50b32 ("btrfs: don't end the
+transaction for delayed refs in throttle").
+
+DATA_RELOC inode.  In the UPDATE_DATA_PTRS stage its delalloc was
+written back and waited for, and its page cache invalidated, before the
+stage started (do_nonremap_reloc()), so there is nothing to flush.  In
+the MOVE_DATA_EXTENTS stage its dirty pages may still be unwritten
+during the merge.  Flushing them from here is the same writeback that
+the flusher threads, sync, or another task's FLUSH_ALL or FLUSH_EVICT
+ticket may start at any time.  It is also what do_nonremap_reloc() waits
+for right after relocate_block_group() returns.  Completing its ordered
+extents joins a transaction on the data reloc root, which is not
+shareable, so it does not take reloc_mutex.
+
+The steal is bounded. steal_from_global_rsv() leaves 10% of the global
+reserve, and each steal is at most min_reserved, which is two nodes per
+level of the reloc root (64 KiB in the trace above).  A merge that fails
+here takes the filesystem read-only.  Keeping it writable is what the
+global reserve is for, as it is for eviction.
+
+If even the global reserve cannot cover the refill, the merge fails as
+before.
+
+Reproduced with reloc-merge-enospc-test.sh (raid56-wh-harness): the
+octopus P1 sequence on 6 x 3 GiB, fsstress until the reclaim worker's
+relocations, plain relocations or balances run at the fill edge.  On the
+base, 3 of 3 reclaim runs went read-only in merge_reloc_roots().  With
+the patch, 6 runs had no merge failure.
+
+Fixes: 44d354abf33e ("btrfs: relocation: review the call sites which can be interrupted by signal")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/relocation.c | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
+index 179bac3a2dccd..87e22737405b4 100644
+--- a/fs/btrfs/relocation.c
++++ b/fs/btrfs/relocation.c
+@@ -1675,8 +1675,17 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
+       memset(&next_key, 0, sizeof(next_key));
+ 
+       while (1) {
++              /*
++               * A failure here forces the filesystem read-only (see
++               * merge_reloc_roots()), so flush everything before giving up:
++               * delayed refs, delalloc, a transaction commit to unpin what
++               * the merge has freed so far, and the global reserve as the
++               * last resort.  FLUSH_EVICT does that in our own context and,
++               * unlike FLUSH_ALL, cannot be interrupted by a signal.  We hold
++               * no transaction handle and no tree lock here.
++               */
+               ret = btrfs_block_rsv_refill(rc->block_rsv, min_reserved,
+-                                           BTRFS_RESERVE_FLUSH_LIMIT);
++                                           BTRFS_RESERVE_FLUSH_EVICT);
+               if (ret)
+                       goto out;
+               trans = btrfs_start_transaction(root, 0);
+-- 
+2.47.3
+
index bce9f9f9d5c0ca1d8be73bea24e7c6ca4c2f6e98..bc3ef2435c557f7bb37d3c4298b47a3ff59d2ea3 100644 (file)
@@ -10,10 +10,11 @@ patch 2, on a filesystem filled to ENOSPC with scattered frees, balance
 -dusage/-musage must fail with ENOSPC with the reserve off and complete
 with it on, with every acknowledged file intact either way.
 
-Candidate patch 3, NOT promoted (refs/cand/m-reloc/{mn,618}/topic,
-9971f3238ceb / 19e3ca085180; zb64 49c28497f96e / 829ecda8abee on the
-lanes 2550544f9c6e / 7626a4a10198): "btrfs: relocation: flush fully before
-failing a merge reservation".  merge_reloc_root() refills relocation's
+Patch 3, promoted 2026-10-22 (misc-next topic 4f26c7c44896, testing
+02806563b90a, zb64 7278042598d8; 6.18 topic 56b8ddb4e5e3, testing
+10892bb56322, zb64 2eb3491c9516; the trees equal the tested candidates
+refs/cand/m-reloc/{mn,618}, 9971f3238ceb / 19e3ca085180): "btrfs:
+relocation: flush fully before failing a merge reservation".  merge_reloc_root() refills relocation's
 block reserve before each merge step with BTRFS_RESERVE_FLUSH_LIMIT (no
 delayed-ref run, commit, delalloc flush or global-reserve steal), and a
 failure there forces the filesystem read-only.  At the fill edge a reclaim