| `resize-missing` | 1 | | Qu Wenruo, rewritten by Zygo | Zygo's Signed-off-by to be added before sending |
| `reflink-inline-fixes` | 2 | | Zygo | |
| `replace-finish-deadlock` | 2 | | Zygo | two dev-replace deadlocks since v6.3 (Fixes tags); Cc stable is Zygo's call |
+| `scrub-commit-pause` | 1 | | Zygo | scrub/replace read extents a commit freed; needs discard=sync, harmless noise, costly fix: offered for reviewers' judgement; Fixes tag, no Cc stable (Zygo 11-11) |
## Applying one series
delalloc-fixes dev-extent-defrag prealloc-size raid56-fixes read-repair-fixes
raid56-scrub-replace reclaim-fixes stripe-alloc low-space
allocator-hints read-policies replace-fixes dev-stats resize-missing
- reflink-inline-fixes replace-finish-deadlock"
+ reflink-inline-fixes replace-finish-deadlock scrub-commit-pause"
declare -A ON=([raid56-scrub-replace]=read-repair-fixes
[stripe-alloc]=reclaim-fixes [low-space]=stripe-alloc)
### What the fixup contains
-The fixup adds 636 lines and removes 2, in 6 files. None of it is new
+The fixup adds 667 lines and removes 2, in 7 files. None of it is new
code: it is what `-X ours` drops from conflicting hunks, put back.
1. **stripe-alloc (in low-space) merged after raid56-fixes** conflicts in
(both add Kconfig options, devinfo sysfs attributes and `volumes.c`
code), as on the 6.18 lane. Most of the fixup's lines are
read-policies code that `-X ours` dropped from the conflicting hunks.
+4. **scrub-commit-pause merged after raid56-scrub-replace** conflicts in
+ `scrub.c`: the new `scrub_pause_point()` goes in front of
+ `scrub_raid56_parity_stripe()`, where raid56-scrub-replace adds
+ `scrub_raid56_copy_parity_rows()`; keep both, the copy helper first.
+ The fixup puts back `scrub_pause_point()` (31 lines).
## Before sending
list that `scripts/export.sh` prints.
- `balance-resume` patch 4 and `dev-stats` are offered for rejection, as
their cover letters say.
+- `scrub-commit-pause` is left to the reviewers' judgement (rare
+ discard=sync prerequisite, harmless impact, a cost at every commit
+ pause), as its cover letter says; the lanes keep it either way.
- `resize-missing` needs Zygo's Signed-off-by.
- Re-export with `scripts/export.sh` after any lane change, and commit
the result with the misc-next SHAs that the script prints.
+void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info);
#endif
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 44fbdeb676da9fe256b1ba396db0eae47465fc30..e8489435da3cb305a45070b56234ec94eae6da27 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2543,6 +2543,37 @@ static bool scrubbed_by_other(struct scrub_ctx *sctx, struct btrfs_device *dev)
+ return ret;
+ }
+
++/*
++ * Let a waiting transaction commit go ahead, with nothing of ours left that
++ * the commit could invalidate.
++ *
++ * The extent and csum paths of @sctx hold leaves of the commit roots, and the
++ * queued stripes were filled from them. A transaction commit switches the
++ * commit roots and unpins the extents freed by the transaction (with
++ * discard=sync it also discards them) before it lets the scrub continue. A
++ * stripe read after that, or a search continued in a leaf of the old commit
++ * root, would find extents that are no longer allocated, and with discard read
++ * back zeros where it expects a tree block or data with a csum: bogus
++ * uncorrectable errors, and a dev-replace cancels on the first metadata one.
++ *
++ * So finish the queued stripes and drop the paths before pausing; the next
++ * search starts at the new commit root.
++ */
++static int scrub_pause_point(struct scrub_ctx *sctx)
++{
++ struct btrfs_fs_info *fs_info = sctx->fs_info;
++ int ret;
++
++ if (!atomic_read(&fs_info->scrub_pause_req))
++ return 0;
++
++ ret = flush_scrub_stripes(sctx);
++ btrfs_release_path(&sctx->extent_path);
++ btrfs_release_path(&sctx->csum_path);
++ scrub_blocked_if_needed(fs_info);
++ return ret;
++}
++
+ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ struct btrfs_device *scrub_dev,
+ struct btrfs_block_group *bg,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 1644b1edfe15a6f98308e7377a40e9ebd520274d..90b62d7d59ffe1546cf1e27a5dd5cc873acc96cd 100644
--- a/fs/btrfs/sysfs.c
-From 850a7c69a81a4b461ebbbf4a97e124d071e1eb54 Mon Sep 17 00:00:00 2001
+From 0c648f0b012b529ce47aaf8c0700051b8f492252 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 10 Nov 2026 11:44:18 -0500
+Date: Wed, 11 Nov 2026 01:05:07 -0500
Subject: [PATCH 0/2] btrfs: device replace hangs at the end with the bio counter held
To: linux-btrfs@vger.kernel.org
-From 850a7c69a81a4b461ebbbf4a97e124d071e1eb54 Mon Sep 17 00:00:00 2001
+From 0c648f0b012b529ce47aaf8c0700051b8f492252 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 8 Nov 2026 20:40:09 -0500
Subject: [PATCH 2/2] btrfs: do not hold the bio counter across the data csum
To: linux-btrfs@vger.kernel.org
Device replace can hang forever at the end, after "replace status"
-already reports it finished, when data is read while it finishes:
+already reports it finished, when data is read while it finishes.
+This happens with any RAID profile:
btrfs replace start btrfs_rm_dev_replace_blocked <- btrfs_dev_replace_finishing
reader btrfs_bio_counter_inc_blocked <- btrfs_submit_bbio
first, and replace finishing waits for the first to be dropped. Every
other bio submission then blocks behind them.
-On a 4-device RAID5 with one device missing, mounted with thread_pool=64,
-8 O_DIRECT readers and 2 writers, replacing the missing device hung in
-round 7. The counter was 2, and exactly two readers were sleeping in
-the nested btrfs_bio_counter_inc_blocked() under btrfs_lookup_bio_sums().
-This does not depend on the RAID profile.
+It was reproduced on a 4-device RAID5 with one device missing,
+mounted with thread_pool=64, 8 O_DIRECT readers and 2 writers:
+replacing the missing device hung in round 7. The counter was 2, and
+exactly two readers were sleeping in the nested
+btrfs_bio_counter_inc_blocked() under btrfs_lookup_bio_sums().
The counter only keeps the result of btrfs_map_block() valid until the
bio is submitted. So drop it, and the mapping, for the csum lookup, take
--- /dev/null
+From e74d5a2d0a4cbe60b92734b54c2a392e79ce2b4d Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 11 Nov 2026 01:05:08 -0500
+Subject: [PATCH 0/1] btrfs: scrub: do not read extents a transaction commit freed
+To: linux-btrfs@vger.kernel.org
+
+Scrub and dev-replace read a block group from extent items found in the
+extent tree commit root, through paths kept for the whole block group,
+and queue up to 128 stripes before the last of them is read. A
+transaction commit can pass the scrub's pause point in between: it
+switches the commit roots and unpins the extents the transaction freed
+before the scrub continues, and with discard=sync it also discards them.
+The scrub then reads those freed extents from its queued stripes and
+from the old leaf. With discard=sync they read back zeros, so a scrub
+of a busy filesystem reports uncorrectable errors that are not there,
+and a replace cancels with -EIO on the first such tree block:
+
+ scrub: tree block 65617920 mirror 1 has bad bytenr, has 0 want 65617920
+ scrub: stripe 65601536 has unrepaired metadata sector at logical 65617920
+ btrfs_scrub_dev(/dev/loop0, 1, /dev/mapper/rddelay) failed -5
+
+How much this matters is for reviewers to judge:
+
+- It needs discard=sync. With the default discard=async, or with
+ nodiscard, the freed range still holds its old content when the
+ scrub reads it (the block group is read-only during its scrub), and
+ nothing shows.
+- Nothing is lost. The blocks read are free and referenced by nothing,
+ so no reader of the filesystem sees them; btrfs check and a second
+ scrub are clean. The harm is spurious uncorrectable scrub errors on
+ a healthy filesystem, and a replace that cancels on a busy
+ discard=sync filesystem.
+- The fix is not free. Each time a commit wants to pass, the scrub
+ first reads (and repairs, and for a replace writes) everything it has
+ queued, up to 128 stripes, and drops both paths, so the next search
+ starts again from the root of the new commit root. On a busy
+ filesystem that happens at every commit while a block group is
+ scrubbed, and commits wait for the queued reads.
+
+We found it as an occasional replace cancel in our discard=sync replace
+tests. With the patch those runs are clean; it is sent on its own so it
+can be dropped without touching anything else.
+
+Reproducer: a raid1 filesystem (nodesize 64K, to make one extent tree
+leaf cover more tree blocks) with 100000 small files, mounted
+discard=sync, scrubbed or replaced while the files are rewritten,
+deleted and renamed and the filesystem is synced every 50 ms. On
+v7.3.3 10 of 10 replaces cancel and 5 of 10 scrubs report uncorrectable
+errors; with the patch 0 of 30 each. At the default 16K nodesize the
+hit rate is much lower (3 of 30 scrubs). The same reproduces on
+misc-next. The stale paths came with 1dc4888e725d ("btrfs: scrub: avoid
+unnecessary extent tree search preparing stripes", v6.6), which the
+patch names in its Fixes tag.
+
+Zygo Blaxell (1):
+ btrfs: scrub: do not let a transaction commit pass under queued
+ stripes
+
+ fs/btrfs/scrub.c | 42 +++++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 37 insertions(+), 5 deletions(-)
+
+
+--
+2.47.3
+
--- /dev/null
+From e74d5a2d0a4cbe60b92734b54c2a392e79ce2b4d Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 10 Nov 2026 22:12:36 -0500
+Subject: [PATCH 1/1] btrfs: scrub: do not let a transaction commit pass under
+ queued stripes
+To: linux-btrfs@vger.kernel.org
+
+Scrub and dev-replace find extents in the commit root of the extent tree,
+through paths kept in the scrub context for the whole block group
+(sctx->extent_path, sctx->csum_path), and fill up to SCRUB_TOTAL_STRIPES
+stripes before the last of them is read. A transaction commit waits in
+btrfs_scrub_pause() until the scrub reaches the top of the
+scrub_simple_mirror() loop, and then switches the commit roots and unpins
+the extents the transaction freed before btrfs_scrub_continue(). With
+discard=sync btrfs_finish_extent_commit() also discards them.
+
+Nothing on the scrub side notices. The stripes it queued before the pause
+are read afterwards, and the search continues in a leaf of the old commit
+root, so the scrub reads extents that are no longer allocated. Without
+discard that is harmless: the block group is read-only while it is
+scrubbed, so the freed range is not reused and still holds what the scrub
+expects. With discard=sync the range reads back zeros on every mirror:
+
+ BTRFS warning (device loop0): scrub: tree block 65617920 mirror 1 has bad bytenr, has 0 want 65617920
+ BTRFS error (device loop0): scrub: unable to fixup (regular) error at logical 65617920 on dev /dev/loop0 physical 65617920
+ BTRFS error (device loop0): scrub: stripe 65601536 has unrepaired metadata sector at logical 65617920
+ BTRFS error (device loop0): btrfs_scrub_dev(/dev/loop0, 1, /dev/mapper/rddelay) failed -5
+
+A scrub reports uncorrectable errors on a healthy filesystem, and a
+dev-replace cancels on the first such metadata sector. The freed blocks
+are not referenced by anything, so no reader of the filesystem sees them;
+btrfs check and a second scrub after the churn are clean.
+
+Before a pause, finish the queued stripes and release both paths, so that
+a commit can only pass with nothing of the scrub's still referring to the
+old commit root, and the next search starts from the new one. The parity
+scrub of RAID56 has its own paths, but its pause point is reached with data
+stripes queued too, so it uses the same helper.
+
+The stale path came with 1dc4888e725d ("btrfs: scrub: avoid unnecessary
+extent tree search preparing stripes"); the queued stripes are older.
+
+scrub-stale-extent-test.sh (raid56-wh-harness) fills a raid1 filesystem
+(nodesize 64K) with 100000 small files, mounts it with discard=sync, and
+runs a scrub or a replace while the files are rewritten, deleted and
+renamed and the filesystem is synced every 50 ms. On v7.3.3 10 of 10
+replaces cancel and 5 of 10 scrubs report uncorrectable errors; with this
+patch 0 of 30 each. Without discard, or with discard=async, nothing shows.
+
+Fixes: 1dc4888e725d ("btrfs: scrub: avoid unnecessary extent tree search preparing stripes")
+---
+ fs/btrfs/scrub.c | 42 +++++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 37 insertions(+), 5 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 98362c91bce43..4f3c49ca36758 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2142,6 +2142,37 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
+ return ret;
+ }
+
++/*
++ * Let a waiting transaction commit go ahead, with nothing of ours left that
++ * the commit could invalidate.
++ *
++ * The extent and csum paths of @sctx hold leaves of the commit roots, and the
++ * queued stripes were filled from them. A transaction commit switches the
++ * commit roots and unpins the extents freed by the transaction (with
++ * discard=sync it also discards them) before it lets the scrub continue. A
++ * stripe read after that, or a search continued in a leaf of the old commit
++ * root, would find extents that are no longer allocated, and with discard read
++ * back zeros where it expects a tree block or data with a csum: bogus
++ * uncorrectable errors, and a dev-replace cancels on the first metadata one.
++ *
++ * So finish the queued stripes and drop the paths before pausing; the next
++ * search starts at the new commit root.
++ */
++static int scrub_pause_point(struct scrub_ctx *sctx)
++{
++ struct btrfs_fs_info *fs_info = sctx->fs_info;
++ int ret;
++
++ if (!atomic_read(&fs_info->scrub_pause_req))
++ return 0;
++
++ ret = flush_scrub_stripes(sctx);
++ btrfs_release_path(&sctx->extent_path);
++ btrfs_release_path(&sctx->csum_path);
++ scrub_blocked_if_needed(fs_info);
++ return ret;
++}
++
+ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ struct btrfs_device *scrub_dev,
+ struct btrfs_block_group *bg,
+@@ -2164,8 +2195,9 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ if (ret < 0)
+ return ret;
+
+- if (atomic_read(&fs_info->scrub_pause_req))
+- scrub_blocked_if_needed(fs_info);
++ ret = scrub_pause_point(sctx);
++ if (ret < 0)
++ return ret;
+
+ spin_lock(&bg->lock);
+ if (test_bit(BLOCK_GROUP_FLAG_REMOVED, &bg->runtime_flags)) {
+@@ -2294,7 +2326,6 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
+ struct btrfs_device *device,
+ u64 physical, int mirror_num)
+ {
+- struct btrfs_fs_info *fs_info = sctx->fs_info;
+ const u64 logical_end = logical_start + logical_length;
+ u64 cur_logical = logical_start;
+ int ret = 0;
+@@ -2311,8 +2342,9 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
+ if (ret < 0)
+ break;
+
+- if (atomic_read(&fs_info->scrub_pause_req))
+- scrub_blocked_if_needed(fs_info);
++ ret = scrub_pause_point(sctx);
++ if (ret < 0)
++ break;
+
+ spin_lock(&bg->lock);
+ if (test_bit(BLOCK_GROUP_FLAG_REMOVED, &bg->runtime_flags)) {
+--
+2.47.3
+
--- /dev/null
+# Testing: scrub-commit-pause
+
+One patch, "btrfs: scrub: do not let a transaction commit pass under queued
+stripes" (Fixes 1dc4888e725d, v6.6). Scrub and dev-replace find extents in
+the extent tree commit root through paths kept for the whole block group
+(`sctx->extent_path`, `sctx->csum_path`) and fill up to 128 stripes before
+reading them. A transaction commit passes the scrub's pause point (top of
+the `scrub_simple_mirror()` loop, and of `scrub_raid56_parity_stripe()` on
+7.x), switches the commit roots and unpins the extents it freed
+(`btrfs_finish_extent_commit()`; discard=sync discards them) before
+`btrfs_scrub_continue()`. The scrub then reads the freed extents from its
+queued stripes and from the old leaf. With discard=sync they read back
+zeros on every mirror: "tree block N mirror M has bad bytenr, has 0",
+uncorrectable errors on a healthy filesystem, and a dev-replace cancels
+with -EIO on the first such metadata sector. The patch adds
+`scrub_pause_point()`: when a commit is waiting, `flush_scrub_stripes()`
+and release both paths, then block.
+
+## Value (Zygo's ruling, 2026-11-11)
+
+- Cost: every commit pause during a scrub flushes up to 128 queued stripes
+ (read, repair, and for a replace the target write-back) and drops the
+ cached paths, so the next search re-descends from the new commit root.
+- Prerequisite: discard=sync only. discard=async (the default on SSDs)
+ and nodiscard leave the freed range's old content in place while its
+ block group is RO for the scrub; both controls are 0/10.
+- Impact: mostly harmless statistical noise. No acked-data loss, no
+ ENOSPC: only the scrub walk reaches the freed blocks; btrfs check, a
+ second scrub and every acked file are clean after every hit. Harm =
+ spurious uncorrectable scrub errors and a cancelled replace.
+- Own topic, so the upstream export can be dropped on its own if upstream
+ says it is not worth the cost. The lanes keep it either way: it removes
+ this noise from our discard=sync scrub/replace tests (the rh1108
+ replace-discard dsync-raid1 "1 of 17" FAIL). No Cc stable.
+
+## To verify
+
+Scrub and replace of a raid1 filesystem mounted discard=sync, while
+metadata is churned and the filesystem committed every 50 ms, must not
+report errors or cancel; without discard nothing changes; check, a second
+scrub and every acked file stay clean either way.
+
+## Reproducer
+
+raid56-wh-harness `scrub-stale-extent-test.sh` (+ `scrub-stale-churn.py`):
+2 x 8 GiB loop raid1/raid1, mkfs -K -n 65536, 100 dirs x 1000 files
+(inline 1000 B, 2% 128 KiB); per iteration mount discard=sync, churn
+(rewrite / delete / rename whole dirs) + `btrfs filesystem sync` every
+50 ms during one `btrfs scrub start -B` or `btrfs replace start -B -K`.
+HIT = scrub klog errors, scrub uncorrectable > 0, or replace canceled.
+Post checks: btrfs check, ro scrub -r, verify of every acked file.
+
+## Results without and with the patch (rd1110, 2026-11-10)
+
+KASAN + lockdep kernels:
+
+| kernel | replace (canceled) | scrub (errors) |
+|---|---|---|
+| v7.3.3 | 10/10 | 5/10 |
+| v7.3.3 + patch | 0/30 | 0/30 |
+| kdave misc-next base 83cd81353093 | 10/10 | 6/10 |
+| misc-next lane + patch | 0/30 | 0/30 |
+| 7.3 lane | - | 6/10 |
+| 7.3 lane + patch | 0/30 | - |
+| 6.18 lane (v6.18.62 + topics) | 10/10 | 6/10 |
+| 6.18 lane + patch | 0/30 (+0/20 at 16K) | 0/30 |
+
+Controls (unpatched): nodiscard 0/10, discard=async 0/10 (the async delay
+outlasts the scrub of a block group). At the default 16K nodesize the hit
+rate is lower (scrub 3/30, replace 0/10 unpatched). A bpftrace probe on
+`btrfs_discard_extent` placed every reported bad tree block inside a range
+discarded during the replace, about a second before the read (4/5 hits
+traced). replace-discard-test.sh (11 cases) with the patch: misc-next and
+7.3 lane 11/11 PASS.
+
+## Promotion gate (pc1111, 2026-11-11)
+
+Topic `<lane>/topics/scrub-commit-pause` = one commit, the last testing
+parent on every lane: misc-next e74d5a2d0a4c (base 83cd81353093), 7.3
+69bee2df2a6f (v7.3.3), 6.18 dff6f2a21e5f (v6.18.62; `[zygo: 6.18
+backport: ...]` note: 6.18 has no raid56 parity pause point). The
+testing merge conflicts in scrub.c next to raid56-scrub-replace's
+scrub_raid56_copy_parity_rows() (and on 6.18 replace-fixes'
+BTRFS_FS_ERROR() stop), resolved as the zb64 + patch tree rd1110
+tested: every new zb64 tree is byte-identical to rd1110's candidate,
+and the testing delta is exactly the patch's lines.
+
+KASAN + lockdep kernels of the promoted zb64 trees:
+
+| lane / kernel | rig | test | result |
+|---|---|---|---|
+| 6.18 zb64 491cbce70bd4 #11 | ahive | replace-discard-test.sh, 11 cases | 11/11 PASS (dsync-raid1 incl.), klog_bad 0 |
+| 6.18 #11 | ahive | scrub-stale-extent 64K replace | 0/10 |
+| 6.18 #11 | ahive | scrub-stale-extent 64K scrub | 0/10 |
+| misc-next zb64 a6ceb4e01937 #76 | dhive | scrub-stale-extent 64K replace / scrub | 0/5 / 0/5 |
+| 7.3 zb64 #10 | ehive | scrub-stale-extent 64K replace / scrub | 0/5 / 0/5 |
+
+Every run: btrfs check clean (6.18: only the baselined pre-existing
+"Space key" line), ro scrub clean, every acked file verified, other klog
+lines 0, taint 0, debug_locks 1, no unwritten-on-end or NORESERVE lines.
+Per-commit buildcheck (fs/btrfs at the topic commit + full vmlinux link,
+the lane zb64 .config, btrfs DEBUG/ASSERT on; the topic adds no Kconfig
+symbol): 6.18 and misc-next 0 failures, 0 new warnings, link rc 0.
+6.18 #11 is the rd1110 6.18 zb64+fix build: its tree equals the
+promoted zb64's, so kbuild had nothing to rebuild.
+
+Found by rd1110 (2026-11-10; forensics `raid56-wh-harness/forensics/rd1110/`)
+chasing a one-off replace-discard-test.sh dsync-raid1 cancel from rh1108;
+promoted by pc1111 (forensics `raid56-wh-harness/forensics/pc1111/`).