| | |
|---|---|
-| 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` `3b6557663e94` (octopus of all 20 topics) |
-| lane head | `zygo-misc-next-zb64` `03fd98a3ff17`; its own commits on top of `testing` (kernel configs, `covers/`) are not exported |
+| base of every series | `99bc6552614f` ("btrfs: === misc-next on b-for-next ==="): btrfs/for-next `0713fa6a4356` plus a marker commit, the misc-next lane base (`misc-next/testing^1`, rebased 2026-10-25) |
+| integration branch | `misc-next/testing` `e8519e93c9a2` (octopus of all 20 topics) |
+| lane head | `zygo-misc-next-zb64` `315863b5a610`; 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
| directory | patches | branch tip | authors | cover letter | notes |
|---|---|---|---|---|---|
-| `logical-ino-costs` | 3 | `fe67a58f7f48` | Zygo, Kai Krakow | from misc-next `covers/`, updated: 0/3 and a paragraph on patch 3 | patch 3 is Kai's, already posted by him |
-| `balance-resume` | 3 | `4f577b679051` | Zygo | from misc-next `covers/`, current | patch 3 optional, offered for rejection |
-| `compress-fixes` | 5 | `babe6f1c006d` | Zygo | from misc-next `covers/`, current | |
-| `deadlock-fixes` | 3 | `68c1f77b3885` | Zygo | new | |
-| `dedupe-fixes` | 1 | `13e8d4c620f7` | Zygo | new, 0/1 (drafted 2026-10-18) | |
-| `delalloc-fixes` | 1 | `7c23eb7ad5c9` | Zygo | from misc-next `covers/`, rewritten 2026-10-19 for 0/1 | patch 1 (delalloc leak) dropped 2026-10-19: fixed upstream by 095be159f3eb; 6.18 keeps it |
-| `dev-extent-defrag` | 1 | `40c2fffa8348` | Zygo | new, 0/1 (drafted 2026-10-18) | |
-| `prealloc-size` | 1 | `93d225865ab2` | Zygo | new, 0/1 (drafted 2026-10-18) | |
-| `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` | 116 | `a23064467620` | 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` | 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 |
-| `read-policies` | 9 | `18680c6045be` | Kai Krakow | new | Kai's series; his postings are authoritative |
-| `replace-fixes` | 7 | `43c8a1e60a5a` | Zygo | new | patch 7 has a btrfs-progs counterpart (`topics/replace-abort-uncorrectable`) |
-| `dev-stats` | 1 | `55ade1cf195c` | Zygo | new, 0/1 (2026-10-21) | behaviour change, offered for rejection; independent of every other series |
-| `resize-missing` | 1 | `8763f9e2126d` | Qu Wenruo, rewritten by Zygo | new, 0/1 (2026-10-21) | Qu's 2019 patch reworked: grow checks now return, absolute sizes checked; Zygo's Signed-off-by to be added before sending |
-| `read-repair-fixes` | 4 | `035bd2f8c1e3` | Zygo | new 2026-10-22; 0/4 | read repair and scrub after an abort: NULL end_io (v6.3+), same csum root, no repair writes after abort; Cc stable on 1-2 only (the abort-write rule is under revision upstream); raid56 left as upstream |
+| `logical-ino-costs` | 3 | `f792976ba697` | Zygo, Kai Krakow | from misc-next `covers/`, updated: 0/3 and a paragraph on patch 3 | patch 3 is Kai's, already posted by him |
+| `balance-resume` | 3 | `6094381703cd` | Zygo | from misc-next `covers/`, current | patch 3 optional, offered for rejection |
+| `compress-fixes` | 5 | `9cf6495173d4` | Zygo | from misc-next `covers/`, current | |
+| `deadlock-fixes` | 3 | `78c0c9e6a02b` | Zygo | new | |
+| `dedupe-fixes` | 1 | `8e47d471e8a3` | Zygo | new, 0/1 (drafted 2026-10-18) | |
+| `delalloc-fixes` | 1 | `a49a18e6a3c7` | Zygo | from misc-next `covers/`, rewritten 2026-10-19 for 0/1 | patch 1 (delalloc leak) dropped 2026-10-19: fixed upstream by 095be159f3eb; 6.18 keeps it |
+| `dev-extent-defrag` | 1 | `34a8e85757bb` | Zygo | new, 0/1 (drafted 2026-10-18) | |
+| `prealloc-size` | 1 | `a69ecf626add` | Zygo | new, 0/1 (drafted 2026-10-18) | |
+| `raid56-fixes` | 12 | `796097dafc94` | 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` | 12 | `b7b4005cacc4` | Zygo | new; 0/12 since 2026-10-25 | Filipe's -EIO fix (`ec0795c045c3`) is in the base now and was dropped from the series |
+| `stripe-alloc` | 116 | `bc8cd9cac405` | 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` | 3 | `087669d83341` | 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 | `dcacae4b4bd8` | Ivan Kozik | new, 0/1 (drafted 2026-10-18) | Ivan's patch |
+| `dm-stripfault` | 2 | `0d13e1572fe7` | Zygo | new | **test fixtures, NOT for merge** (no `To:`) |
+| `allocator-hints` | 12 | `6944c7760536` | Kai Krakow, KeinNiemand, Zygo | new | Kai's series plus follow-ups; the authors' postings are authoritative |
+| `read-policies` | 9 | `ccf8a6c6d49b` | Kai Krakow | new | Kai's series; his postings are authoritative |
+| `replace-fixes` | 7 | `1c2676130104` | Zygo | new | patch 7 has a btrfs-progs counterpart (`topics/replace-abort-uncorrectable`) |
+| `dev-stats` | 1 | `a5160f442538` | Zygo | new, 0/1 (2026-10-21) | behaviour change, offered for rejection; independent of every other series |
+| `resize-missing` | 1 | `2d41f2a9495d` | Qu Wenruo, rewritten by Zygo | new, 0/1 (2026-10-21) | Qu's 2019 patch reworked: grow checks now return, absolute sizes checked; Zygo's Signed-off-by to be added before sending |
+| `read-repair-fixes` | 4 | `df4629dcf9ad` | Zygo | new 2026-10-22; 0/4 | read repair and scrub after an abort: NULL end_io (v6.3+), same csum root, no repair writes after abort; Cc stable on 1-2 only (the abort-write rule is under revision upstream); raid56 left as upstream |
## Applying one series
```sh
cd ~/share/linux # any clone that has the base commit
-git checkout -b up/raid56-scrub-replace 0c48d26d46bd
+git checkout -b up/raid56-scrub-replace 99bc6552614f
git am $(ls ~/share/linux-upstream/topics/raid56-scrub-replace/*.patch | grep -v 0000-cover-letter)
```
On a base that already contains a patch of the series, `git am` stops
at that patch; `git am --skip` drops it. Expected cases:
-- `raid56-scrub-replace` patch 1 (Filipe's -EIO fix), once btrfs/for-next
- is in the base;
- `logical-ino-costs` patch 3 and the `allocator-hints` /
`read-policies` patches, if Kai's postings are merged first.
```sh
cd ~/share/linux
P=~/share/linux-upstream
-B=0c48d26d46bd
+B=99bc6552614f
ORDER="logical-ino-costs balance-resume compress-fixes deadlock-fixes dedupe-fixes
delalloc-fixes dev-extent-defrag prealloc-size raid56-fixes raid56-scrub-replace
stripe-alloc low-space dedupe-mtime dm-stripfault allocator-hints read-policies
branches is the supported way.
Verified on the export: the patches of every directory, applied in order
-to `0c48d26d46bd`, give that branch's tree exactly. Merging all 20 in
+to `99bc6552614f`, give that branch's tree exactly. Merging all 20 in
the order above with `-X ours` and applying `fixups/post-merge.patch`
gives the tree of `misc-next/testing` exactly. The verification used
git 2.47.
- `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` `3b6557663e94`.
+ directories reflect the lane at `misc-next/testing` `e8519e93c9a2`.
Commit the result with the misc-next SHAs that the script prints.
bool "Btrfs experimental features"
depends on BTRFS_FS
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 59f668359df7b6ccbb85dd632eee6858250a2993..e0862c13efafaed76b7c5aa606dd94179ac80500 100644
+index 681fd72ab9277ea30b95cb93999bb720f5e21230..f031f0329814ac9b13bdfae893275548f0e64ff1 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3511,6 +3511,8 @@ void btrfs_retire_open_stripes(struct btrfs_fs_info *fs_info,
}
unit = max(unit, bg->full_stripe_len);
}
-@@ -4826,6 +4834,13 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -4828,6 +4836,13 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
*/
if (sinfo_used - trapped + num_bytes <= sinfo->total_bytes)
ret = 0;
/*
* The stripe_alloc gate admitted writers against whole
-@@ -7198,7 +7213,15 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
+@@ -7201,7 +7216,15 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
mutex_unlock(&fs_info->ro_block_group_mutex);
btrfs_end_transaction(trans);
btrfs_bg_unblock_nocow(cache);
return ret;
}
-@@ -7226,6 +7249,7 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
+@@ -7229,6 +7252,7 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
sinfo->bytes_readonly -= btrfs_block_group_available_space(cache);
list_del_init(&cache->ro_list);
became_rw = true;
}
spin_unlock(&cache->lock);
spin_unlock(&sinfo->lock);
-@@ -8833,6 +8857,30 @@ static bool reloc_reserve_wanted(struct btrfs_fs_info *fs_info,
+@@ -8836,6 +8860,30 @@ static bool reloc_reserve_wanted(struct btrfs_fs_info *fs_info,
return READ_ONCE(sinfo->reloc_reserve);
}
ret = find_free_extent(root, ins, &ffe_ctl);
if (!ret && !is_data) {
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index bcf8dbc7fdf8dc3455b08855149f351046850b1c..c10f75587c2310196a13faf797c868d294cc276d 100644
+index 7cd95d273947a8d3b909ee5b12e1cb3fe5e57fa0..1aa93286f75b929e2a15ea07618778289f670c6f 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -991,13 +991,15 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
+@@ -995,13 +995,15 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
{
struct btrfs_stripe_hash_table *table;
const unsigned int limit = rbio_cache_limit(rbio->bioc->fs_info);
table = rbio->bioc->fs_info->stripe_hash_table;
spin_lock(&table->cache_lock);
-@@ -1020,18 +1022,8 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
+@@ -1024,18 +1026,8 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
spin_unlock(&rbio->bio_list_lock);
spin_unlock(&table->cache_lock);
}
-@@ -4032,6 +4024,258 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -4049,6 +4041,258 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
return false;
}
+ const int stripe_nr = i / rbio->stripe_nsectors;
+ const int sectornr = i % rbio->stripe_nsectors;
+ const u64 logical = rbio->bioc->full_stripe_logical +
-+ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)stripe_nr * rbio->bioc->stripe_len +
+ (u64)sectornr * fs_info->sectorsize;
+ const phys_addr_t *paddrs = from_bio ? rbio->bio_paddrs
+ : rbio->stripe_paddrs;
+ const int stripe_nr = i / rbio->stripe_nsectors;
+ const int sectornr = i % rbio->stripe_nsectors;
+ const u64 logical = rbio->bioc->full_stripe_logical +
-+ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)stripe_nr * rbio->bioc->stripe_len +
+ (u64)sectornr * fs_info->sectorsize;
+ u64 refs;
+ u64 egen;
* Return true if the rebuild of data sector @sector_nr of @stripe_nr can be
* trusted enough to write it back. It can when the sector has a csum: the
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index d71c5c5f4b2ed8f930cb1c2991f98fbafba35261..cfcd9bce4652f861774763844076ef755cc70475 100644
+index 28241c31faa28bb6e68b1fe309e0901c280b986d..a00ef6881ce51e57c4305d5154583ddc580678f3 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -334,5 +334,11 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
+@@ -329,5 +329,11 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_set_rbio_cache_size(struct btrfs_fs_info *info, unsigned int size);
#endif
void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len);
#endif
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 34998749fc548fc6f3a730a1064d60fa1b4cf931..82ab5fbf983e2e58e2e8cd43924d5614a0a857cf 100644
+index 5801b68037a08e36a68939353ccd01d5767de4ed..4cd4f5a58dd3a71bc241410e67d111597e863400 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
-@@ -1289,7 +1289,8 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
+@@ -1297,7 +1297,8 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
bitmap_andnot(&repaired, &errors.init_error_bitmap, &error,
stripe->nr_sectors);
if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors) &&
btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
} else {
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 72c6b4c4c2772ec75bf3e0645aed5d8546da4576..08ecac160dfc0e4e9734c1fc72528ecc3e08d854 100644
+index c0273a10a97035d85e5cb1d3de4823787aead125..9f1809b9a598fbd15405e4b1e177d3c9af30b4cd 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -696,6 +696,7 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
+@@ -694,6 +694,7 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
*/
if (reloc)
used -= min(used, space_info->bytes_stripe_reserve);
return check_can_overcommit(space_info, used, bytes, flush);
}
-@@ -774,6 +775,12 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
+@@ -772,6 +773,12 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
} else {
/* ...and that group is out of reach for everyone else */
supply -= min(supply, dedicated);
/*
* An allocation that opens a run claims
* round_up(bytes, unit). A delalloc write's margin
-@@ -824,6 +831,7 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
+@@ -822,6 +829,7 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
tused = used;
if (ticket->reloc)
tused -= min(tused, space_info->bytes_stripe_reserve);
/* Check and see if our ticket can be satisfied now. */
if ((tused + ticket->bytes <= space_info->total_bytes ||
-@@ -2143,7 +2151,6 @@ static int __reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2141,7 +2149,6 @@ static int __reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
space_info->reclaim_size += ticket.bytes;
init_waitqueue_head(&ticket.wait);
spin_lock_init(&ticket.lock);
ticket.reloc = reloc;
ticket.mount_cleanup =
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 0ee5b52a8296bea97ab82afd153dbd9cd69777d0..af2eb0c3f9a17207fbb20a0a9b83cd3106f5d297 100644
+index 63dd1dc79bef527c3daa470b29b84f535f96c0ca..88141644027aa0f87e08512f64b88cd328a14e97 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -382,7 +382,7 @@ static inline u64 btrfs_space_info_used(const struct btrfs_space_info *s_info,
s_info->bytes_stripe_margin +
s_info->bytes_stripe_reserve +
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9aaa51a6734bb814620155960de1be76019ed7a8..161ee904e12c2dc442438ccea295332c3baa2bad 100644
+index 6c16cc96ff1fea35fe02dffbb0186ce574635744..5edefae1dd1c850306250226c6d4bcfe395f9a80 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -616,6 +616,8 @@ BTRFS_ATTR(debug_mount, stripe_rmw_audit_stats,
SPACE_INFO_ATTR(disk_used);
SPACE_INFO_ATTR(disk_total);
SPACE_INFO_ATTR(reclaim_count);
-@@ -2650,6 +2653,61 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2651,6 +2654,61 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
BTRFS_ATTR_RW(devid, type, btrfs_devinfo_type_show, btrfs_devinfo_type_store);
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
* Information about one device.
*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index b538d4790ef64047e214132263cd4d37eb910a85..816f5522baf27fa701127da27b5e7a5b53c5119e 100644
+index babe6ad81716978f45a6f8f3b65fc745ee18dfe7..a966de1270bcb32580d5365bca1b3887a16207b9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6924,7 +6924,293 @@ bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical)
+@@ -6937,7 +6937,293 @@ bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical)
return ret;
}
-From 43c53b3f02db3c3bcc55714bfe5b06eb56276353 Mon Sep 17 00:00:00 2001
+From 6944c77605368854e644f8c961ad38ffb741d873 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 22:46:13 -0400
+Date: Sun, 25 Oct 2026 03:13:46 -0400
Subject: [PATCH 00/12] btrfs: allocator hints (Kai Krakow's series, as carried on misc-next)
To: linux-btrfs@vger.kernel.org
8 files changed, 490 insertions(+), 20 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 8f3082a7ebefed571d0f36d0194073feaff58660 Mon Sep 17 00:00:00 2001
+From 047b7c947d423dd8f3246d42d2aa48862b1a9ab8 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Fri, 10 Jul 2026 23:49:05 +0200
Subject: [PATCH 01/12] btrfs: add new Kconfig option for btrfs allocator hints
-From 8e7507febeb58ab020164fbdcf7e1d06b8da0621 Mon Sep 17 00:00:00 2001
+From 3a82701b991baee17492c8fdb1911cef9d9a5344 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:51:17 +0200
Subject: [PATCH 02/12] btrfs: add flags to give a hint to the chunk allocator
-From 96eca7bce271925186716b49248f5ac700d2d459 Mon Sep 17 00:00:00 2001
+From 894ba25b5c1bb9bcbafd5ed149503d86f04da31b Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:22:50 +0200
Subject: [PATCH 03/12] btrfs: export dev_item.type in
1 file changed, 15 insertions(+)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..697238beadd0c 100644
+index 89b0a4ef4063e..6a68149318d84 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -1983,6 +1983,18 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
+@@ -1984,6 +1984,18 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
}
BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
/*
* Information about one device.
*
-@@ -1996,6 +2008,9 @@ static struct attribute *devid_attrs[] = {
+@@ -1997,6 +2009,9 @@ static struct attribute *devid_attrs[] = {
BTRFS_ATTR_PTR(devid, replace_target),
BTRFS_ATTR_PTR(devid, scrub_speed_max),
BTRFS_ATTR_PTR(devid, writeable),
-From d7878068817b71bf6ed1dab1e4a17b853d139b9e Mon Sep 17 00:00:00 2001
+From 5c78cc5b6dfa6fca8616e11d75c9c71df39c7ba3 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:25:21 +0200
Subject: [PATCH 04/12] btrfs: change the DEV_ITEM 'type' field via sysfs
1 file changed, 79 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 697238beadd0c..ef03b81215d58 100644
+index 6a68149318d84..a3ccfe3dbcafc 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -1984,6 +1984,22 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
+@@ -1985,6 +1985,22 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
#ifdef CONFIG_BTRFS_ALLOCATOR_HINTS
static ssize_t btrfs_devinfo_type_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf)
{
-@@ -1992,7 +2008,69 @@ static ssize_t btrfs_devinfo_type_show(struct kobject *kobj,
+@@ -1993,7 +2009,69 @@ static ssize_t btrfs_devinfo_type_show(struct kobject *kobj,
return scnprintf(buf, PAGE_SIZE, "0x%016llx\n", device->type);
}
-From b35e5a63150a6c0dce37745f655ad149043a5ef7 Mon Sep 17 00:00:00 2001
+From 957cad32902b12696afc0b263d70050cd204aa83 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:18:02 +0200
Subject: [PATCH 05/12] btrfs: add allocator_hint mode
instead of relying on df only.
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d3e6a9b429dd9..fdeb073b5c275 100644
+index ce78a9441c64f..7af7af717c9ba 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -185,6 +185,21 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
const char *btrfs_bg_type_to_raid_name(u64 flags)
{
const int index = btrfs_bg_flags_to_raid_index(flags);
-@@ -5571,13 +5586,20 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
+@@ -5576,13 +5591,20 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
}
/*
if (di_a->max_avail > di_b->max_avail)
return -1;
if (di_a->max_avail < di_b->max_avail)
-@@ -5947,16 +5969,97 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -5953,16 +5975,97 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
devices_info[ndevs].max_avail = max_avail;
devices_info[ndevs].total_avail = total_avail;
devices_info[ndevs].dev = device;
}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 6eddda2392215..3c64aa598971c 100644
+index 75b1179776c80..3cd7d94554151 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -602,6 +602,9 @@ struct btrfs_device_info {
+@@ -603,6 +603,9 @@ struct btrfs_device_info {
u64 dev_offset;
u64 max_avail;
u64 total_avail;
-From 93213d412a41300db32e3fd57fb090bbbbe73fc4 Mon Sep 17 00:00:00 2001
+From d7add7cf6edfa308343ea12cb95ccabaf7305e2b Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:09:55 +0200
Subject: [PATCH 06/12] btrfs: add allocator_hint for no allocation preferred
If unsure, say N.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index ef03b81215d58..0a787e96bc147 100644
+index a3ccfe3dbcafc..931fd4b5a6559 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -1994,6 +1994,7 @@ static bool btrfs_dev_allocation_hint_valid(u64 type)
+@@ -1995,6 +1995,7 @@ static bool btrfs_dev_allocation_hint_valid(u64 type)
case BTRFS_DEV_ALLOCATION_PREFERRED_METADATA:
case BTRFS_DEV_ALLOCATION_METADATA_ONLY:
case BTRFS_DEV_ALLOCATION_DATA_ONLY:
default:
return false;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index fdeb073b5c275..44acb1b301981 100644
+index 7af7af717c9ba..c1fc62270289d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -196,6 +196,7 @@ static const int alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
/* the other values are set to 0 */
};
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
-@@ -6006,7 +6007,10 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6012,7 +6013,10 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
* sort also by hint (metadata hint
* higher priority)
*/
-From 0c7225f7aabe7a207e0f4d0abf5fad55d7f33daf Mon Sep 17 00:00:00 2001
+From b54d25e97ca7ae0cdd1706c872ee9035e430a6f2 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Fri, 10 Jul 2026 23:51:46 +0200
Subject: [PATCH 07/12] btrfs: add allocator_hint to disable allocation
If unsure, say N.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 0a787e96bc147..19102dafcd4c1 100644
+index 931fd4b5a6559..16912c8f4f9e6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -1995,6 +1995,7 @@ static bool btrfs_dev_allocation_hint_valid(u64 type)
+@@ -1996,6 +1996,7 @@ static bool btrfs_dev_allocation_hint_valid(u64 type)
case BTRFS_DEV_ALLOCATION_METADATA_ONLY:
case BTRFS_DEV_ALLOCATION_DATA_ONLY:
case BTRFS_DEV_ALLOCATION_PREFERRED_NONE:
default:
return false;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 44acb1b301981..862a296bd0453 100644
+index c1fc62270289d..00ecf2b1b30f4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -192,6 +192,7 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
[BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
-@@ -5988,6 +5989,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -5994,6 +5995,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
*/
if (BTRFS_DEV_ALLOCATION_METADATA_ONLY == hint)
continue;
/*
* if a data chunk must be allocated,
* sort also by hint (data disk
-@@ -6002,6 +6008,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6008,6 +6014,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
*/
if (BTRFS_DEV_ALLOCATION_DATA_ONLY == hint)
continue;
-From 0cd6b6146d3a4273b9c79f22b5a5d46c2e7dfeda Mon Sep 17 00:00:00 2001
+From 2763c25f8752709a108b4d07a5a8f734c5596ca8 Mon Sep 17 00:00:00 2001
From: KeinNiemand <18308201+KeinNiemand@users.noreply.github.com>
Date: Sun, 30 Aug 2026 14:50:54 +0200
Subject: [PATCH 08/12] btrfs: honor allocator hints for fixed-width mirrors
1 file changed, 13 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 862a296bd0453..a1ea8450109e3 100644
+index 00ecf2b1b30f4..eba473441b55a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6058,6 +6058,19 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6064,6 +6064,19 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
break;
}
-From 486e2ee2648429c8d668073de4ac1598d1a4cf77 Mon Sep 17 00:00:00 2001
+From 1920847e6f57ae71dc0b18ab63fa9bbf147512bd Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 00:44:02 -0400
Subject: [PATCH 09/12] btrfs: allocator hints: move the hint values out of the
2 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 3c64aa598971c..60b941876da64 100644
+index 3cd7d94554151..ae48bcec15a94 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -597,6 +597,27 @@ struct btrfs_io_context {
+@@ -598,6 +598,27 @@ struct btrfs_io_context {
struct btrfs_io_stripe stripes[];
};
-From c6e048eb9c855be6d381b2a3c5aa6273d684c02e Mon Sep 17 00:00:00 2001
+From 51fc372ce6d49e87326aaa266d695d8b5b9db0aa Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 00:44:58 -0400
Subject: [PATCH 10/12] btrfs: allocator hints: keep the hint across device
memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp));
memcpy(tgt_device->uuid, src_device->uuid, sizeof(tgt_device->uuid));
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 19102dafcd4c1..9dcbc02ff1204 100644
+index 16912c8f4f9e6..6457b74d67f93 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -19,6 +19,7 @@
#include "space-info.h"
#include "block-group.h"
#include "qgroup.h"
-@@ -2020,6 +2021,7 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2021,6 +2022,7 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
struct btrfs_device *device;
int ret;
struct btrfs_trans_handle *trans;
u64 type, prev_type;
-@@ -2048,6 +2050,21 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2049,6 +2051,21 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
if (!btrfs_dev_allocation_hint_valid(type))
return -EINVAL;
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans))
return PTR_ERR(trans);
-@@ -2057,6 +2074,17 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2058,6 +2075,17 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
ret = btrfs_update_device(trans, device);
-From ed65ad6368ce76486e756248deafd5ec748f8f76 Mon Sep 17 00:00:00 2001
+From de1ee879d7873f5224ea97fa5066a8392cc30b9a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 10:55:00 -0400
Subject: [PATCH 11/12] btrfs: allocator hints: don't run a transaction from
memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp));
memcpy(tgt_device->uuid, src_device->uuid, sizeof(tgt_device->uuid));
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9dcbc02ff1204..edb0ca4fb9d2b 100644
+index 6457b74d67f93..8a48b6895a9ae 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -19,7 +19,6 @@
#include "space-info.h"
#include "block-group.h"
#include "qgroup.h"
-@@ -2017,31 +2016,22 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2018,31 +2017,22 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
const char *buf, size_t len)
{
struct btrfs_fs_info *fs_info;
ret = kstrtou64(buf, 0, &type);
if (ret < 0)
return -EINVAL;
-@@ -2050,55 +2040,39 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2051,55 +2041,39 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
if (!btrfs_dev_allocation_hint_valid(type))
return -EINVAL;
BTRFS_ATTR_RW(devid, type, btrfs_devinfo_type_show, btrfs_devinfo_type_store);
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 7431a06f168da..5c41eb54545e4 100644
+index d265fac023e58..39d2718256019 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -2301,6 +2301,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2285,6 +2285,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
goto lockdep_trans_commit_start_release;
}
if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index a1ea8450109e3..f9753dd1b3714 100644
+index eba473441b55a..ebc7be7858aa2 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -8676,6 +8676,61 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
+@@ -8730,6 +8730,61 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
return ret;
}
{
btrfs_dev_stat_inc(dev, index);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 60b941876da64..c16508aca0cd0 100644
+index ae48bcec15a94..f4dd7fd5e4d97 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -110,6 +110,8 @@ static_assert(BTRFS_RAID_RAID1C4 == 8);
/* Special value encoding failure to write primary super block. */
#define BTRFS_SUPER_PRIMARY_WRITE_ERROR (INT_MAX / 2)
-@@ -816,6 +818,11 @@ int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
+@@ -820,6 +822,11 @@ int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
int btrfs_init_writeback_bio_size(struct btrfs_fs_info *fs_info);
int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
-From 43c53b3f02db3c3bcc55714bfe5b06eb56276353 Mon Sep 17 00:00:00 2001
+From 6944c77605368854e644f8c961ad38ffb741d873 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 18 Oct 2026 15:50:43 -0400
Subject: [PATCH 12/12] btrfs: allocator hints: make the available space
5 files changed, 181 insertions(+), 91 deletions(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 82d4ac418a2de..5d0d0917b00ef 100644
+index d5a84fa97462c..4165ace1cedd3 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -464,7 +464,8 @@ static u64 calc_available_free_space(const struct btrfs_space_info *space_info,
+@@ -461,7 +461,8 @@ static u64 calc_available_free_space(const struct btrfs_space_info *space_info,
else
profile = btrfs_metadata_alloc_profile(fs_info);
avail = atomic64_read(&fs_info->free_chunk_space);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index acb704b20c2be..ed5c7a1e29a95 100644
+index b424cc836bd4a..74d2468914d31 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
-@@ -1642,6 +1642,10 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
+@@ -1644,6 +1644,10 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
if (i >= nr_devices)
break;
/* align with stripe_len */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index edb0ca4fb9d2b..2e2d0c7ed4ba4 100644
+index 8a48b6895a9ae..f744ebea1a8c4 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -2066,6 +2066,8 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
+@@ -2067,6 +2067,8 @@ static ssize_t btrfs_devinfo_type_store(struct kobject *kobj,
}
WRITE_ONCE(device->type, type);
set_bit(BTRFS_DEV_STATE_TYPE_DIRTY, &device->dev_state);
/* We don't want to do full transaction commit from inside sysfs */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index f9753dd1b3714..a2dc5754e9b88 100644
+index ebc7be7858aa2..1c2981104646e 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -200,7 +200,101 @@ static const int alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
const char *btrfs_bg_type_to_raid_name(u64 flags)
{
-@@ -5629,7 +5723,7 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
+@@ -5634,7 +5728,7 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
*/
static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
struct btrfs_device_info *devices_info,
u64 *allocated)
{
const struct btrfs_raid_attr *raid_attr = &btrfs_raid_array[type];
-@@ -5649,6 +5743,13 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
+@@ -5654,6 +5748,13 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
continue;
if (device->total_bytes > device->bytes_used +
device->per_profile_allocated)
avail = device->total_bytes - device->bytes_used -
-@@ -5683,6 +5784,16 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
+@@ -5688,6 +5789,16 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
}
sort(devices_info, ndevs, sizeof(struct btrfs_device_info),
btrfs_cmp_device_info, NULL);
ndevs = rounddown(ndevs, raid_attr->devs_increment);
if (ndevs < raid_attr->devs_min)
return -ENOSPC;
-@@ -5705,7 +5816,7 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
+@@ -5710,7 +5821,7 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
}
static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
u64 *result_ret)
{
struct btrfs_device_info *devices_info = NULL;
-@@ -5733,7 +5844,8 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
+@@ -5738,7 +5849,8 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list)
device->per_profile_allocated = 0;
result += allocated;
out:
-@@ -5744,10 +5856,19 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
+@@ -5749,10 +5861,19 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
return 0;
}
int ret;
/*
-@@ -5757,21 +5878,33 @@ void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info)
+@@ -5762,21 +5883,33 @@ void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info)
if (btrfs_is_zoned(fs_info))
goto error;
spin_unlock(&fs_info->fs_devices->per_profile_lock);
}
-@@ -5973,56 +6106,9 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -5979,56 +6112,9 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
devices_info[ndevs].dev = device;
#ifdef CONFIG_BTRFS_ALLOCATOR_HINTS
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
++ndevs;
-@@ -6048,28 +6134,8 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6054,28 +6140,8 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
* select the minimum set of disks grouped by hint that
* can host the chunk
*/
BUG_ON(ndevs > ctl->ndevs);
ctl->ndevs = ndevs;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index c16508aca0cd0..5d7127b406a22 100644
+index f4dd7fd5e4d97..3fd0200e8ec73 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -337,6 +337,13 @@ enum btrfs_read_policy {
spinlock_t per_profile_lock;
};
-@@ -944,18 +953,26 @@ const char *btrfs_bg_type_to_raid_name(u64 flags);
+@@ -948,18 +957,26 @@ const char *btrfs_bg_type_to_raid_name(u64 flags);
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
bool btrfs_verify_dev_items(const struct btrfs_fs_info *fs_info);
void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info);
-From 4f577b67905133549460b60640c9c61ab0b9e85a Mon Sep 17 00:00:00 2001
+From 6094381703cd582ed0a4c84e2d28954696b2c616 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:14 -0400
+Date: Sun, 25 Oct 2026 03:13:33 -0400
Subject: [PATCH 0/3] btrfs: balance resume selects what the original request selected
To: linux-btrfs@vger.kernel.org
2 files changed, 85 insertions(+), 13 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 936c55b685b4b8c3c868c3b0583263d2eeda1999 Mon Sep 17 00:00:00 2001
+From a9847e16418f7b9b1a8f3c91d629fc6426a12132 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 13 Oct 2026 01:05:21 -0400
Subject: [PATCH 1/3] btrfs: free queued remap chunks when balance bails out
1 file changed, 8 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d3e6a9b429dd9..d22c41bbb1056 100644
+index ce78a9441c64f..2ed57bc7a9905 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -4739,6 +4739,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
+@@ -4744,6 +4744,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
}
}
error:
-From ed06b587874e04ced16aebde918ebbdc08cbe874 Mon Sep 17 00:00:00 2001
+From fb89bec9e7b30c381f7d85b4ced60e5d5a21912e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 16 Sep 2026 02:29:10 -0400
Subject: [PATCH 2/3] btrfs: replace the usage=90 balance resume heuristic with
/* Cancellation requests for chunk relocation */
atomic_t reloc_cancel_req;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d22c41bbb1056..17cbbaca44373 100644
+index 2ed57bc7a9905..1996ebaeadc76 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2035,7 +2035,7 @@ static u64 find_next_chunk(struct btrfs_fs_info *fs_info)
}
static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
-@@ -4047,10 +4047,7 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
+@@ -4052,10 +4052,7 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
return ret;
}
static void update_balance_args(struct btrfs_balance_control *bctl)
{
/*
-@@ -4062,34 +4059,58 @@ static void update_balance_args(struct btrfs_balance_control *bctl)
+@@ -4067,34 +4064,58 @@ static void update_balance_args(struct btrfs_balance_control *bctl)
bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
/*
* Clear the balance status in fs_info and delete the balance item from disk.
*/
-@@ -4106,6 +4127,7 @@ static void reset_balance_state(struct btrfs_fs_info *fs_info)
+@@ -4111,6 +4132,7 @@ static void reset_balance_state(struct btrfs_fs_info *fs_info)
kfree(bctl);
ret = del_balance_item(fs_info);
if (ret)
btrfs_handle_fs_error(fs_info, ret, NULL);
}
-@@ -5071,6 +5093,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
+@@ -5076,6 +5098,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
btrfs_bg_type_to_raid_name(data_target));
}
ret = insert_balance_item(fs_info, bctl);
if (ret && ret != -EEXIST)
goto out;
-@@ -5081,6 +5106,8 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
+@@ -5086,6 +5111,8 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
spin_lock(&fs_info->balance_lock);
fs_info->balance_ctl = bctl;
spin_unlock(&fs_info->balance_lock);
} else {
BUG_ON(ret != -EEXIST);
spin_lock(&fs_info->balance_lock);
-@@ -5238,6 +5265,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
+@@ -5243,6 +5270,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
btrfs_balance_sys(leaf, item, &disk_bargs);
btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs);
-From 4f577b67905133549460b60640c9c61ab0b9e85a Mon Sep 17 00:00:00 2001
+From 6094381703cd582ed0a4c84e2d28954696b2c616 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 13 Oct 2026 14:24:01 -0400
Subject: [PATCH 3/3] btrfs: keep the usage=90 resume heuristic for balance
1 file changed, 29 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 17cbbaca44373..2023f1bd85398 100644
+index 1996ebaeadc76..09fcc5d981d8a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -4059,6 +4059,35 @@ static void update_balance_args(struct btrfs_balance_control *bctl)
+@@ -4064,6 +4064,35 @@ static void update_balance_args(struct btrfs_balance_control *bctl)
bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
-From babe6f1c006d470c162d26f1a981bbd0ae08dac6 Mon Sep 17 00:00:00 2001
+From 9cf6495173d43a69008af6544c73cde1b59feb4d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 21:21:16 -0400
+Date: Sun, 25 Oct 2026 03:13:34 -0400
Subject: [PATCH 0/5] btrfs: fix and simplify inode flag vs compression interactions
To: linux-btrfs@vger.kernel.org
5 files changed, 184 insertions(+), 28 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 910b4110dddb076fafefa4eb930142a12d0cbccd Mon Sep 17 00:00:00 2001
+From cb00a6bf8255738f737545f961f141e9257e6fe9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 16 Aug 2025 22:20:01 -0400
Subject: [PATCH 1/5] btrfs: fix nodatacow vs compression inode flag conflict
1 file changed, 45 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index dec015e6bd29a..61c3da2722d3e 100644
+index ac070c745b0eb..55762f77006e0 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -216,9 +216,9 @@ void btrfs_sync_inode_flags_to_i_flags(struct btrfs_inode *inode)
-From eb4a602a2afad08530f538a6f24351c96eb9cb10 Mon Sep 17 00:00:00 2001
+From a7879c4a2fe1ee8092e0f2613915c1ca9d64e2a1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 18 Oct 2026 15:44:15 -0400
Subject: [PATCH 2/5] btrfs: do not leave COMPRESS on an inode that gets
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..812ebd78e6562 100644
+index b071ed59a583f..ea4a2fb26e4d1 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -6553,6 +6553,8 @@ static void btrfs_inherit_iflags(struct btrfs_inode *inode, struct btrfs_inode *
+@@ -6551,6 +6551,8 @@ static void btrfs_inherit_iflags(struct btrfs_inode *inode, struct btrfs_inode *
inode->flags |= BTRFS_INODE_NODATACOW;
if (S_ISREG(inode->vfs_inode.i_mode))
inode->flags |= BTRFS_INODE_NODATASUM;
}
btrfs_sync_inode_flags_to_i_flags(inode);
-@@ -6658,9 +6660,12 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
+@@ -6656,9 +6658,12 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
if (S_ISREG(inode->i_mode)) {
if (btrfs_test_opt(fs_info, NODATASUM))
BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
-From af12234a0e957931c4af7723abf662701fead684 Mon Sep 17 00:00:00 2001
+From d1eafd0809350d1ee9c00b3f9e2097dcc74a2046 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 17 Aug 2025 16:57:07 -0400
Subject: [PATCH 3/5] btrfs: allow NODATACOW | NOCOMPRESS
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index 61c3da2722d3e..26c54ccf42f5f 100644
+index 55762f77006e0..0de6a06e3c3e8 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -366,9 +366,9 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
-From a5683abc6a30bcb28effbbed88f2498e727c67dd Mon Sep 17 00:00:00 2001
+From b009cddd89352180eb1b7b44222fdbea25960cfb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 6 Aug 2026 21:39:01 -0400
Subject: [PATCH 4/5] btrfs: props: add per-inode compression level support
* Force compression on the file using the defrag ioctl, could be
* different from prop_compress and takes precedence if set.
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 812ebd78e6562..165e4556ed067 100644
+index ea4a2fb26e4d1..9cac6f5866a1f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -945,6 +945,8 @@ static void compress_file_range(struct btrfs_work *work)
/*
* We need to pass blocksize and not i_size, otherwise we can't
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index 26c54ccf42f5f..8c1411297feb8 100644
+index 0de6a06e3c3e8..bb1c989c53dcb 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -280,6 +280,7 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
-From babe6f1c006d470c162d26f1a981bbd0ae08dac6 Mon Sep 17 00:00:00 2001
+From 9cf6495173d43a69008af6544c73cde1b59feb4d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 19 Jul 2026 14:33:53 -0400
Subject: [PATCH 5/5] btrfs: props: validate compression property values
-From 68c1f77b3885b37222f141302379bc4eb43b0fd6 Mon Sep 17 00:00:00 2001
+From 78c0c9e6a02b2aa9c27f19ecb73e0dc952d9caf9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:14 -0400
+Date: Sun, 25 Oct 2026 03:13:35 -0400
Subject: [PATCH 0/3] btrfs: deadlocks between reflink, relocation and space reservation
To: linux-btrfs@vger.kernel.org
2 files changed, 218 insertions(+), 118 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 2ca7cbd636565d7bc56e522f1b7a9147f2b1867a Mon Sep 17 00:00:00 2001
+From f61edbb1fa430fdb64311a5fd1c808414280329e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 15 Aug 2026 22:21:10 -0400
Subject: [PATCH 1/3] btrfs: fix flushoncommit deadlock when cloning an inline
-From 2fd67b564a0aaae379014138030a2582b52c337f Mon Sep 17 00:00:00 2001
+From 97724c6881f7b5b79ac8bbb159a85e29aad5e3eb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 16 Aug 2026 03:31:14 -0400
Subject: [PATCH 2/3] btrfs: reflink: never block on space reservations while
-From 68c1f77b3885b37222f141302379bc4eb43b0fd6 Mon Sep 17 00:00:00 2001
+From 78c0c9e6a02b2aa9c27f19ecb73e0dc952d9caf9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 16 Aug 2026 16:26:54 -0400
Subject: [PATCH 3/3] btrfs: relocation: reserve all of a folio's slices before
-From 13e8d4c620f7d2544fc84dfc415787285687b533 Mon Sep 17 00:00:00 2001
+From 8e47d471e8a3a403a2cf9aebd061fc8ca404ae5c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 04:20:31 -0400
+Date: Sun, 25 Oct 2026 03:13:35 -0400
Subject: [PATCH 0/1] btrfs: one dedupe request, one extent reference
To: linux-btrfs@vger.kernel.org
1 file changed, 2 insertions(+), 19 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 13e8d4c620f7d2544fc84dfc415787285687b533 Mon Sep 17 00:00:00 2001
+From 8e47d471e8a3a403a2cf9aebd061fc8ca404ae5c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 11 Nov 2024 20:32:54 -0500
Subject: [PATCH 1/1] btrfs: get rid of maximum dedupe length
-From 288d851bbbc26377ebe77e3816d65061ad323c65 Mon Sep 17 00:00:00 2001
+From dcacae4b4bd8f6257ab9d7656a0c3e176b360f07 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 04:20:31 -0400
+Date: Sun, 25 Oct 2026 03:13:45 -0400
Subject: [PATCH 0/1] btrfs: keep mtime and ctime when a dedupe ends in a hole
To: linux-btrfs@vger.kernel.org
5 files changed, 13 insertions(+), 13 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 288d851bbbc26377ebe77e3816d65061ad323c65 Mon Sep 17 00:00:00 2001
+From dcacae4b4bd8f6257ab9d7656a0c3e176b360f07 Mon Sep 17 00:00:00 2001
From: Ivan Kozik <ivan@ludios.org>
Date: Wed, 30 Sep 2026 06:27:48 +0000
Subject: [PATCH 1/1] btrfs: don't update mtime and ctime when deduping a range
struct btrfs_trans_handle **trans_out);
int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..8a9975aed0202 100644
+index b071ed59a583f..ee7543aef34e0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -9137,7 +9137,6 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
+@@ -9135,7 +9135,6 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
extent_info.file_offset = file_offset;
extent_info.extent_buf = (char *)&stack_fi;
extent_info.is_new_extent = true;
extent_info.qgroup_reserved = qgroup_released;
extent_info.insertions = 0;
-@@ -9148,7 +9147,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
+@@ -9146,7 +9145,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
}
ret = btrfs_replace_file_extents(inode, path, file_offset,
-From 7c23eb7ad5c98b24bb04e21ebba206bcd00b48ef Mon Sep 17 00:00:00 2001
+From a49a18e6a3c7818f1de0871feb20199b5a6ef5e4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 21:21:17 -0400
+Date: Sun, 25 Oct 2026 03:13:36 -0400
Subject: [PATCH 0/1] btrfs: drain pending NOCOW writes before a block group goes read-only
To: linux-btrfs@vger.kernel.org
5 files changed, 102 insertions(+), 5 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 7c23eb7ad5c98b24bb04e21ebba206bcd00b48ef Mon Sep 17 00:00:00 2001
+From a49a18e6a3c7818f1de0871feb20199b5a6ef5e4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 12 Sep 2026 02:16:28 -0400
Subject: [PATCH 1/1] btrfs: drain pending NOCOW writes before making a block
5 files changed, 102 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index b23a543bb3823..4174d632e1a21 100644
+index 027830a53f7dc..bfa3f494332de 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -3114,6 +3114,53 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
+@@ -3117,6 +3117,53 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
* ensure we still have some free space after marking this
* block group RO.
*/
int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
bool do_chunk_alloc)
{
-@@ -3143,6 +3190,14 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
+@@ -3146,6 +3193,14 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
return ret;
}
do {
trans = btrfs_join_transaction(root);
if (IS_ERR(trans))
-@@ -3230,6 +3285,8 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
+@@ -3233,6 +3288,8 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
mutex_unlock(&fs_info->ro_block_group_mutex);
btrfs_end_transaction(trans);
return ret;
}
-@@ -3242,6 +3299,7 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
+@@ -3245,6 +3302,7 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
spin_lock(&sinfo->lock);
spin_lock(&cache->lock);
if (!--cache->ro) {
/* This protects tree_mod_log and tree_mod_seq_list */
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..1b10f5b10616b 100644
+index b071ed59a583f..aaf8b04623bd1 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -7372,10 +7372,20 @@ static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
+@@ -7370,10 +7370,20 @@ static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
bool readonly = false;
block_group = btrfs_lookup_block_group(fs_info, bytenr);
-From 40c2fffa8348196148b5b8ca9805ac407d142242 Mon Sep 17 00:00:00 2001
+From 34a8e85757bbf8650972770b14d8682f4844a1f4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 04:20:31 -0400
+Date: Sun, 25 Oct 2026 03:13:37 -0400
Subject: [PATCH 0/1] btrfs: allow setting the system chunk size through sysfs
To: linux-btrfs@vger.kernel.org
1 file changed, 13 insertions(+), 9 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 40c2fffa8348196148b5b8ca9805ac407d142242 Mon Sep 17 00:00:00 2001
+From 34a8e85757bbf8650972770b14d8682f4844a1f4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 30 Sep 2023 02:47:08 -0400
Subject: [PATCH 1/1] btrfs: allow changing system dev_extent size via sysfs
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..19b8c61cd34de 100644
+index 89b0a4ef4063e..108534dbc4577 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -647,8 +647,8 @@ static ssize_t btrfs_chunk_size_show(struct kobject *kobj,
-From 55ade1cf195c58e80606d630120f5434f66b3a36 Mon Sep 17 00:00:00 2001
+From a5160f442538f1967dd37da26efe20d1b22e2622 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Wed, 21 Oct 2026 00:59:50 -0400
+Date: Sun, 25 Oct 2026 03:13:48 -0400
Subject: [PATCH 0/1] btrfs: persist device stats counted without a transaction
To: linux-btrfs@vger.kernel.org
6 files changed, 82 insertions(+), 13 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 55ade1cf195c58e80606d630120f5434f66b3a36 Mon Sep 17 00:00:00 2001
+From a5160f442538f1967dd37da26efe20d1b22e2622 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 22:15:41 -0400
Subject: [PATCH 1/1] btrfs: write dirty device stats when no transaction is
6 files changed, 82 insertions(+), 13 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index c45cda4290d5a..2bd33cbcb8b0e 100644
+index c628c5081d923..0955228f81201 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1559,6 +1559,12 @@ static int transaction_kthread(void *arg)
goto sleep;
}
-@@ -4250,6 +4256,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
+@@ -4270,6 +4276,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
int btrfs_commit_super(struct btrfs_fs_info *fs_info)
{
mutex_lock(&fs_info->cleaner_mutex);
btrfs_run_delayed_iputs(fs_info);
mutex_unlock(&fs_info->cleaner_mutex);
-@@ -4259,7 +4267,11 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)
+@@ -4279,7 +4287,11 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)
down_write(&fs_info->cleanup_work_sem);
up_write(&fs_info->cleanup_work_sem);
static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index acb704b20c2be..a21a88935cbb3 100644
+index b424cc836bd4a..587eee55d10fd 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1364,6 +1364,15 @@ static int btrfs_remount_ro(struct btrfs_fs_info *fs_info)
* We've set the superblock to RO mode, so we might have made the
* cleaner task sleep without running all pending delayed iputs. Go
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 7431a06f168da..e48d014a0ad80 100644
+index d265fac023e58..0f5c5a9e1e36c 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -2095,6 +2095,41 @@ int btrfs_commit_current_transaction(struct btrfs_root *root)
+@@ -2079,6 +2079,41 @@ int btrfs_commit_current_transaction(struct btrfs_root *root)
return btrfs_commit_transaction(trans);
}
bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans);
void btrfs_throttle(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d3e6a9b429dd9..e8a511e814833 100644
+index ce78a9441c64f..e69f444a46622 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -8474,6 +8474,28 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
+@@ -8528,6 +8528,28 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
return ret;
}
/*
* called from commit_transaction. Writes all changed device stats to disk.
*/
-@@ -8484,7 +8506,6 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
+@@ -8538,7 +8560,6 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
struct btrfs_device *device;
int stats_cnt;
int ret = 0;
/*
* Do an initial pass using RCU to see if we need to update any dev
-@@ -8502,17 +8523,7 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
+@@ -8556,17 +8577,7 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
* transaction commit, no one can be concurrently adding or removing a
* device.
*/
mutex_lock(&fs_devices->device_list_mutex);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 6eddda2392215..00f5d54ae9742 100644
+index 75b1179776c80..969826cc4fe1b 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -791,6 +791,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
+@@ -795,6 +795,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
int btrfs_init_writeback_bio_size(struct btrfs_fs_info *fs_info);
-From 9ab63d7ab0fa67d43583f20d672cbc28f0da9383 Mon Sep 17 00:00:00 2001
+From 0d13e1572fe71fd33e5cdb4d0eaa1111bbe9d179 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:18 -0400
+Date: Sun, 25 Oct 2026 03:13:46 -0400
Subject: [PATCH 0/2] test fixtures: dm-stripfault target and a forced filesystem error (NOT for merge)
Test fixtures carried on the lane for the raid56 tests; NOT for
create mode 100644 drivers/md/dm-stripfault.c
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 94444f914d77923c79eef989db4f323396441610 Mon Sep 17 00:00:00 2001
+From 25e8c47ff024baacc813cf2981a3ebc1a8718762 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 2 Oct 2026 01:08:32 -0400
Subject: [PATCH 1/2] dm: add the stripfault target, a raid56 read-modify-write
-From 9ab63d7ab0fa67d43583f20d672cbc28f0da9383 Mon Sep 17 00:00:00 2001
+From 0d13e1572fe71fd33e5cdb4d0eaa1111bbe9d179 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 24 Sep 2026 17:27:53 -0400
Subject: [PATCH 2/2] DO-NOT-UPSTREAM: btrfs: sysfs force_fs_error, to raise a
1 file changed, 61 insertions(+)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..a50aedf117f6d 100644
+index 89b0a4ef4063e..bae3351f9559e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1124,6 +1124,64 @@ static ssize_t quota_override_store(struct kobject *kobj,
-From fe67a58f7f48c0c26db3aac1bac44966e7ac7828 Mon Sep 17 00:00:00 2001
+From f792976ba69796c4dc0c890bf9c2c72faa500c38 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:13 -0400
+Date: Sun, 25 Oct 2026 03:13:32 -0400
Subject: [PATCH 0/3] btrfs: reducing LOGICAL_INO costs
To: linux-btrfs@vger.kernel.org
4 files changed, 127 insertions(+), 21 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From b82b5eec72387346fec67957cfc5f091efd62dd7 Mon Sep 17 00:00:00 2001
+From f39e3249acc05e0ae076b074fbf46db3ca1699d9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 17 Jul 2026 23:13:26 -0400
Subject: [PATCH 1/3] btrfs: backref: detect tree mod log rewind cycles in
* We are searching for normal backref but bytenr of this leaf
* matches shared data backref, OR
diff --git a/fs/btrfs/fiemap.c b/fs/btrfs/fiemap.c
-index 7a2a971800993..31f3d56631101 100644
+index 817171028413c..02fb813ffb98f 100644
--- a/fs/btrfs/fiemap.c
+++ b/fs/btrfs/fiemap.c
-@@ -428,6 +428,31 @@ static int fiemap_search_slot(struct btrfs_inode *inode, struct btrfs_path *path
+@@ -429,6 +429,31 @@ static int fiemap_search_slot(struct btrfs_inode *inode, struct btrfs_path *path
return 0;
}
/*
* Process a range which is a hole or a prealloc extent in the inode's subvolume
* btree. If @disk_bytenr is 0, we are dealing with a hole, otherwise a prealloc
-@@ -483,10 +508,10 @@ static int fiemap_process_hole(struct btrfs_inode *inode,
+@@ -484,10 +509,10 @@ static int fiemap_process_hole(struct btrfs_inode *inode,
if (prealloc_len > 0) {
if (!checked_extent_shared && fieinfo->fi_extents_max) {
if (ret < 0)
return ret;
else if (ret > 0)
-@@ -532,10 +557,10 @@ static int fiemap_process_hole(struct btrfs_inode *inode,
+@@ -533,10 +558,10 @@ static int fiemap_process_hole(struct btrfs_inode *inode,
}
if (!checked_extent_shared && fieinfo->fi_extents_max) {
if (ret < 0)
return ret;
else if (ret > 0)
-@@ -768,10 +793,10 @@ static int extent_fiemap(struct btrfs_inode *inode,
+@@ -769,10 +794,10 @@ static int extent_fiemap(struct btrfs_inode *inode,
} else {
/* We have a regular extent. */
if (fieinfo->fi_extents_max) {
goto out_unlock;
else if (ret > 0)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..10aa34d4db85a 100644
+index b071ed59a583f..2886e24a20514 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -10436,7 +10436,20 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
+@@ -10434,7 +10434,20 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
ret = btrfs_is_data_extent_shared(BTRFS_I(inode), disk_bytenr,
extent_gen, backref_ctx);
-From cef86d336e3834e393827965e7ae4d096835e168 Mon Sep 17 00:00:00 2001
+From fc805e8fbd3f23a8a358b28f9d5a695d5cf14e2b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 12:36:42 -0400
Subject: [PATCH 2/3] btrfs: resume the delayed-ref merge walk instead of
The restart has had this shape since commit 0e0adbcfdc90 ("btrfs: track
refs in a rb_tree instead of a list") in v4.15.
-Assisted-by: Claude:claude-opus-5[1m]
+Assisted-by: Claude:claude-opus-5
---
fs/btrfs/delayed-ref.c | 49 ++++++++++++++++++++++++++++++++++++------
1 file changed, 42 insertions(+), 7 deletions(-)
-From fe67a58f7f48c0c26db3aac1bac44966e7ac7828 Mon Sep 17 00:00:00 2001
+From f792976ba69796c4dc0c890bf9c2c72faa500c38 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Mon, 23 Jun 2025 13:56:36 +0200
Subject: [PATCH 3/3] btrfs: avoid RCU stall during backref list construction
-From 4f26c7c448962f551ae85038d4ca3971d109ec9b Mon Sep 17 00:00:00 2001
+From 087669d83341b0e044a253146b2f633bc4f63534 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 22 Oct 2026 05:12:25 -0400
+Date: Sun, 25 Oct 2026 03:13:45 -0400
Subject: [PATCH 0/3] btrfs: keep room to relocate on a full filesystem
To: linux-btrfs@vger.kernel.org
12 files changed, 614 insertions(+), 10 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From bd9f6c46fa79374ba55701eec56a461cc663e23a Mon Sep 17 00:00:00 2001
+From ff1a34bdfe8c76ac3624306f3882321c90fc0e5e 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/3] btrfs: print the error when reclaim fails to relocate a
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index b23a543bb3823..17d4f23de1e66 100644
+index 027830a53f7dc..b0adf7aded255 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -2062,8 +2062,8 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -2064,8 +2064,8 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
}
if (ret) {
btrfs_dec_block_group_ro(bg);
-From 57034df182f0238f0420d4b958e4f3d0b06f7959 Mon Sep 17 00:00:00 2001
+From 8ddf0ef4313d7d243c2323d679e443184c8c4510 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/3] btrfs: hold block groups free for relocation
12 files changed, 602 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 17d4f23de1e66..882215de55683 100644
+index b0adf7aded255..f9c506b8c80d0 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -1422,6 +1422,18 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -1424,6 +1424,18 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
goto out;
}
num_bytes = btrfs_block_group_available_space(cache);
/*
-@@ -1439,6 +1451,13 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -1441,6 +1453,13 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
*/
if (sinfo_used + num_bytes <= sinfo->total_bytes)
ret = 0;
} else {
/*
* We overcommit metadata, so we need to do the
-@@ -1448,6 +1467,8 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -1450,6 +1469,8 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
*/
if (btrfs_can_overcommit(sinfo, num_bytes, BTRFS_RESERVE_NO_FLUSH))
ret = 0;
}
if (!ret) {
-@@ -1462,6 +1483,8 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -1464,6 +1485,8 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
list_add_tail(&cache->ro_list, &sinfo->ro_bgs);
}
out:
spin_unlock(&cache->lock);
spin_unlock(&sinfo->lock);
if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) {
-@@ -1649,7 +1672,9 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
+@@ -1651,7 +1674,9 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
((block_group->flags & BTRFS_BLOCK_GROUP_SYSTEM) &&
space_info->total_bytes - block_group->length <
system_space_target(space_info)) ||
/*
* We want to bail if we made new allocations or have
* outstanding allocations in this block group. We do
-@@ -3253,6 +3278,7 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
+@@ -3256,6 +3281,7 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
}
sinfo->bytes_readonly -= btrfs_block_group_available_space(cache);
list_del_init(&cache->ro_list);
}
spin_unlock(&cache->lock);
spin_unlock(&sinfo->lock);
-@@ -3669,6 +3695,7 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache,
+@@ -3672,6 +3698,7 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache,
}
cache->reserved += num_bytes;
if (delalloc)
cache->delalloc_bytes += num_bytes;
-@@ -3717,6 +3744,8 @@ void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes,
+@@ -3720,6 +3747,8 @@ void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes,
spin_lock(&cache->lock);
bg_ro = cache->ro;
cache->reserved -= num_bytes;
btrfs_maybe_reset_size_class(cache);
if (is_delalloc)
cache->delalloc_bytes -= num_bytes;
-@@ -4681,3 +4710,334 @@ int btrfs_populate_fully_remapped_bgs_list(struct btrfs_fs_info *fs_info)
+@@ -4684,3 +4713,334 @@ int btrfs_populate_fully_remapped_bgs_list(struct btrfs_fs_info *fs_info)
return 0;
}
void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limit);
void btrfs_reclaim_bgs_work(struct work_struct *work);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index c45cda4290d5a..3d105a2973a3f 100644
+index c628c5081d923..c8254d91f9e91 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1519,6 +1519,9 @@ static int cleaner_kthread(void *arg)
/*
* Reclaim block groups in the reclaim_bgs list after we deleted
* all unused block_groups. This possibly gives us some more free
-@@ -3132,6 +3135,9 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
+@@ -3152,6 +3155,9 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
}
up_read(&fs_info->cleanup_work_sem);
out_put_rc:
put_reloc_control(rc);
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 82d4ac418a2de..eb4a89ab68262 100644
+index d5a84fa97462c..18dedf106ae53 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -186,11 +186,25 @@ struct reserve_ticket {
space_info->clamp = 1;
btrfs_update_space_info_chunk_size(space_info, calc_chunk_size(info, flags));
space_info->subgroup_id = BTRFS_SUB_GROUP_PRIMARY;
-@@ -401,6 +420,13 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
+@@ -400,6 +419,13 @@ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group)
btrfs_space_info_update_bytes_zone_unusable(space_info, block_group->zone_unusable);
if (block_group->length > 0)
space_info->full = false;
btrfs_try_granting_tickets(space_info);
spin_unlock(&space_info->lock);
-@@ -550,7 +576,9 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
+@@ -547,7 +573,9 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
if (space_info->flags & BTRFS_BLOCK_GROUP_DATA)
return false;
return check_can_overcommit(space_info, used, bytes, flush);
}
-@@ -600,13 +628,15 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
+@@ -597,13 +625,15 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
while (!list_empty(head)) {
struct reserve_ticket *ticket;
u64 used_after;
btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes);
remove_ticket(space_info, ticket, 0);
space_info->tickets_id++;
-@@ -1795,6 +1825,7 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1792,6 +1822,7 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
u64 used;
int ret = -ENOSPC;
bool pending_tickets;
ASSERT(orig_bytes, "orig_bytes=%llu", orig_bytes);
/*
-@@ -1816,7 +1847,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1813,7 +1844,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
async_work = &fs_info->async_reclaim_work;
spin_lock(&space_info->lock);
/*
* We don't want NO_FLUSH allocations to jump everybody, they can
-@@ -1866,6 +1898,7 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1863,6 +1895,7 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
space_info->reclaim_size += ticket.bytes;
init_waitqueue_head(&ticket.wait);
spin_lock_init(&ticket.lock);
ticket.steal = can_steal(flush);
if (trace_btrfs_reserve_ticket_enabled())
start_ns = ktime_get_ns();
-@@ -1997,6 +2030,32 @@ __cold void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info)
+@@ -1994,6 +2027,32 @@ __cold void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info)
dump_global_block_rsv(fs_info);
}
* Account the unused space of all the readonly block group in the space_info.
* takes mirrors into account.
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index d0130c8ba3dda..759547d4938f7 100644
+index 0456b0d2d1b4a..08ee1111085de 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -148,6 +148,8 @@ struct btrfs_space_info {
(may_use_included ? s_info->bytes_may_use : 0);
}
-@@ -308,6 +324,7 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
+@@ -307,6 +323,7 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
u64 orig_bytes,
enum btrfs_reserve_flush_enum flush);
void btrfs_try_granting_tickets(struct btrfs_space_info *space_info);
enum btrfs_reserve_flush_enum flush);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index acb704b20c2be..79b370625d757 100644
+index b424cc836bd4a..829cd78d04dfd 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
-@@ -1727,6 +1727,8 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
+@@ -1729,6 +1729,8 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
total_free_data += found->disk_total - found->disk_used;
total_free_data -=
btrfs_account_ro_block_groups_free_space(found);
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
if (!list_empty(&found->block_groups[i]))
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..8a3816019ba98 100644
+index 89b0a4ef4063e..4a94ab172a27a 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -788,6 +788,7 @@ SPACE_INFO_ATTR(bytes_reserved);
BTRFS_ATTR_PTR(space_info, chunk_size),
BTRFS_ATTR_PTR(space_info, size_classes),
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d3e6a9b429dd9..b46e3d94eae63 100644
+index ce78a9441c64f..f78f83bfe9f47 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -3718,8 +3718,16 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
+@@ -3723,8 +3723,16 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
bg->start);
}
ret = PTR_ERR(trans);
btrfs_handle_fs_error(root->fs_info, ret, NULL);
return ret;
-@@ -3728,6 +3736,10 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
+@@ -3733,6 +3741,10 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
/* Step two, delete the device extents and the chunk tree entries. */
ret = btrfs_remove_chunk(trans, bg->start);
btrfs_end_transaction(trans);
return ret;
}
-@@ -4322,6 +4334,25 @@ static int should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *
+@@ -4327,6 +4339,25 @@ static int should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *
return false;
}
-From 4f26c7c448962f551ae85038d4ca3971d109ec9b Mon Sep 17 00:00:00 2001
+From 087669d83341b0e044a253146b2f633bc4f63534 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
-From 93d225865ab25105a48bf80f6c29a800b806a85b Mon Sep 17 00:00:00 2001
+From a69ecf626addcaa2c0d02bb8fefb6d964ead28a6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 04:20:31 -0400
+Date: Sun, 25 Oct 2026 03:13:37 -0400
Subject: [PATCH 0/1] btrfs: limit preallocated extents to 128 MiB
To: linux-btrfs@vger.kernel.org
1 file changed, 1 insertion(+), 1 deletion(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 93d225865ab25105a48bf80f6c29a800b806a85b Mon Sep 17 00:00:00 2001
+From a69ecf626addcaa2c0d02bb8fefb6d964ead28a6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 21 Dec 2024 10:48:03 -0500
Subject: [PATCH 1/1] btrfs: use BTRFS_MAX_EXTENT_SIZE in prealloc
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..ed46720d7c944 100644
+index b071ed59a583f..0202108393361 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -9187,7 +9187,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9185,7 +9185,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
u64 end = start + num_bytes - 1;
while (num_bytes > 0) {
-From f7e693d10be20b7f83d5ba52569425bc68c36807 Mon Sep 17 00:00:00 2001
+From 796097dafc9486af8ee93c8e073d5ca1de5cfc14 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 22 Oct 2026 21:41:29 -0400
+Date: Sun, 25 Oct 2026 03:13:37 -0400
Subject: [PATCH 00/12] btrfs: raid56: rbio lifetime and cache fixes, error reporting
To: linux-btrfs@vger.kernel.org
8 files changed, 677 insertions(+), 43 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 06db5c045ee4d05f55678163dc984793966b09af Mon Sep 17 00:00:00 2001
+From 2390ec646753c7827a2398c9b50da8a5c5813beb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 5 Jul 2024 23:08:46 -0400
Subject: [PATCH 01/12] btrfs: log a message when dropping an extent due to IO
1 file changed, 16 insertions(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..ad1528fce5f94 100644
+index b071ed59a583f..8b95be6893f0e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -3391,6 +3391,22 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
+@@ -3389,6 +3389,22 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
clear_reserved_extent &&
!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
!test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
-From dec088fcc6e6b83401e437af76e1beac9f403bd1 Mon Sep 17 00:00:00 2001
+From 5605ea80dd3424b27a98a7621722b76866c62f64 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 25 Jul 2026 16:06:34 -0400
Subject: [PATCH 02/12] btrfs: raid56: fix use-after-free of rbio in bio end_io
2 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5ec31299f1c30..04e998e99599e 100644
+index 59aad807f98ab..a0a1bae60c1ae 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -1095,7 +1095,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
+@@ -1101,7 +1101,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
}
bio_list_init(&rbio->bio_list);
INIT_LIST_HEAD(&rbio->plug_list);
spin_lock_init(&rbio->bio_list_lock);
INIT_LIST_HEAD(&rbio->stripe_cache);
-@@ -1676,6 +1676,40 @@ static void verify_bio_data_sectors(struct btrfs_raid_bio *rbio,
+@@ -1689,6 +1689,40 @@ static void verify_bio_data_sectors(struct btrfs_raid_bio *rbio,
}
}
static void raid_wait_read_end_io(struct bio *bio)
{
struct btrfs_raid_bio *rbio = bio->bi_private;
-@@ -1688,8 +1722,7 @@ static void raid_wait_read_end_io(struct bio *bio)
+@@ -1701,8 +1735,7 @@ static void raid_wait_read_end_io(struct bio *bio)
}
bio_put(bio);
}
static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
-@@ -1697,7 +1730,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
+@@ -1710,7 +1743,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
{
struct bio *bio;
while ((bio = bio_list_pop(bio_list))) {
bio->bi_end_io = raid_wait_read_end_io;
-@@ -1710,7 +1743,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
+@@ -1723,7 +1756,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
submit_bio(bio);
}
}
static int alloc_rbio_data_pages(struct btrfs_raid_bio *rbio)
-@@ -2399,8 +2432,7 @@ static void raid_wait_write_end_io(struct bio *bio)
+@@ -2416,8 +2449,7 @@ static void raid_wait_write_end_io(struct bio *bio)
if (bio->bi_status)
rbio_update_error_bitmap(rbio, bio);
bio_put(bio);
}
static void submit_write_bios(struct btrfs_raid_bio *rbio,
-@@ -2408,7 +2440,7 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2425,7 +2457,7 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
{
struct bio *bio;
while ((bio = bio_list_pop(bio_list))) {
bio->bi_end_io = raid_wait_write_end_io;
-@@ -2514,7 +2546,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2531,7 +2563,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
/* We should have at least one bio assembled. */
ASSERT(bio_list_size(&bio_list));
submit_write_bios(rbio, &bio_list);
/* We may have more errors than our tolerance during the read. */
for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
-@@ -2974,7 +3006,9 @@ static void scrub_rbio(struct btrfs_raid_bio *rbio)
+@@ -2984,7 +3016,9 @@ static void scrub_rbio(struct btrfs_raid_bio *rbio)
* and writeback the good content.
*/
ret = finish_parity_scrub(rbio);
int found_errors;
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 8542648199f1a..47f8e85db2949 100644
+index 8700910b8dc99..b56f9b958d713 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
@@ -13,6 +13,7 @@
#include "volumes.h"
struct page;
-@@ -178,9 +179,16 @@ struct btrfs_raid_bio {
+@@ -173,9 +174,16 @@ struct btrfs_raid_bio {
refcount_t refs;
-From c4ca7d88372eb775e03b9fb0ae3e080d171256c1 Mon Sep 17 00:00:00 2001
+From 9ea7e7a0b451d6f1a49a9aa4c4f43519dd98dcd7 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 1 Aug 2026 01:31:24 -0400
Subject: [PATCH 03/12] btrfs: propagate a split bio's error when the failing
-From c05f4a996dc3d9f233e27e191e3bc8d1f92492bb Mon Sep 17 00:00:00 2001
+From 8b657c64c5b9b11a1552b998c6589de8ff02ea74 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 3 Aug 2026 03:24:38 -0400
Subject: [PATCH 04/12] btrfs: raid56: drop cached rbios when their stripes'
total_unpinned += len;
space_info = cache->space_info;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 04e998e99599e..8c57b1f4318e0 100644
+index a0a1bae60c1ae..69ce17bc7f0af 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -535,6 +535,43 @@ static void remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
+@@ -539,6 +539,43 @@ static void remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
spin_unlock(&table->cache_lock);
}
+ spin_lock(&table->cache_lock);
+ list_for_each_entry_safe(rbio, tmp, &table->stripe_cache, stripe_cache) {
+ const u64 rbio_start = rbio->bioc->full_stripe_logical;
-+ const u64 rbio_len = (u64)rbio->nr_data << BTRFS_STRIPE_LEN_SHIFT;
++ const u64 rbio_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
+
+ if (rbio_start < start + len && start < rbio_start + rbio_len)
+ __remove_rbio_from_cache(rbio);
* remove everything in the cache
*/
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 47f8e85db2949..c7c4b0db61f4c 100644
+index b56f9b958d713..be507cceb465d 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -295,5 +295,6 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+@@ -290,5 +290,6 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
-From 0fe89be282ee3d71b69555adab49dd43729aad45 Mon Sep 17 00:00:00 2001
+From 92f5a085fe10893c3980e9d17734341d85d4efb9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 5 Aug 2026 02:59:50 -0400
Subject: [PATCH 05/12] btrfs: raid56: verify reconstructed tree blocks
1 file changed, 174 insertions(+)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 8c57b1f4318e0..d3c9bd7a7a718 100644
+index 69ce17bc7f0af..13e5a0244fdb3 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -1954,6 +1954,176 @@ static void calculate_block_csum_paddrs(struct btrfs_fs_info *fs_info,
+@@ -1971,6 +1971,176 @@ static void calculate_block_csum_paddrs(struct btrfs_fs_info *fs_info,
btrfs_csum_final(&csum, dest);
}
+ * wait until every sector of the block has been recovered, which is why this
+ * runs after the vertical recovery loop rather than inside it.
+ *
-+ * A tree block never straddles a column. nodesize and BTRFS_STRIPE_LEN are
-+ * both powers of two with nodesize <= BTRFS_STRIPE_LEN, and a full stripe is
++ * A tree block never straddles a column. nodesize and the stripe length are
++ * both powers of two with nodesize <= the stripe length, and a full stripe is
+ * stripe-length aligned, so each column begins on a nodesize boundary and
+ * tree blocks tile it exactly.
+ *
+ const u32 sectors_per_tree = fs_info->nodesize >> fs_info->sectorsize_bits;
+ const u32 step = min(sectorsize, PAGE_SIZE);
+ const u64 logical = rbio->bioc->full_stripe_logical +
-+ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)stripe_nr * rbio->bioc->stripe_len +
+ (u64)sector_nr * sectorsize;
+ u8 on_disk_csum[BTRFS_CSUM_SIZE];
+ u8 calculated_csum[BTRFS_CSUM_SIZE];
static int verify_one_sector(struct btrfs_raid_bio *rbio,
int stripe_nr, int sector_nr)
{
-@@ -2189,6 +2359,10 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
+@@ -2206,6 +2376,10 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
break;
}
-From b2c793a1845e5928abc500c6719aebf14e543c05 Mon Sep 17 00:00:00 2001
+From 4d6253c5eec47d8b006c6952cad73ea354d2d577 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 4 Sep 2026 22:14:19 -0400
Subject: [PATCH 06/12] btrfs: raid56: keep a reference on a stolen cached rbio
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index d3c9bd7a7a718..40ab59b1f0e2a 100644
+index 13e5a0244fdb3..cb4d6d7afe396 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -826,8 +826,14 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+@@ -831,8 +831,14 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
list_empty(&cur->plug_list) &&
test_bit(RBIO_CACHE_BIT, &cur->flags) &&
!test_bit(RBIO_RMW_LOCKED_BIT, &cur->flags)) {
steal_rbio(cur, rbio);
cache_drop = cur;
-@@ -875,8 +881,10 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+@@ -880,8 +886,10 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
list_add(&rbio->hash_list, &h->hash_list);
out:
spin_unlock(&h->lock);
-From 3a80dae0c04b17fa72ef154d058a763334da4438 Mon Sep 17 00:00:00 2001
+From 91863d542ab16d679351dde0560bb5e987459f3d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 12 Sep 2026 07:17:54 -0400
Subject: [PATCH 07/12] btrfs: raid56: do not unhash a cached rbio that has
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 40ab59b1f0e2a..1cec4589be7ba 100644
+index cb4d6d7afe396..6ff4eeca37fbc 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -502,11 +502,21 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
+@@ -506,11 +506,21 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
* the rbio from the hash_table, and drop
* the corresponding ref
*/
if (!list_empty(&rbio->hash_list)) {
list_del_init(&rbio->hash_list);
refcount_dec(&rbio->refs);
-- BUG_ON(!list_empty(&rbio->plug_list));
+- ASSERT(list_empty(&rbio->plug_list));
}
}
}
-From 773140d8d8973b91099623dedb025073a34b0974 Mon Sep 17 00:00:00 2001
+From 68a1dc1bf316ba1a62c82b8d4656ccfb932623d8 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 01:19:22 -0400
Subject: [PATCH 08/12] btrfs: raid56: do not let a failed write leave its
1 file changed, 12 insertions(+)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 1cec4589be7ba..616beef40d8c0 100644
+index 6ff4eeca37fbc..1d9917330e912 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -1013,6 +1013,18 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
+@@ -1018,6 +1018,18 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
*/
bitmap_clear(&rbio->dbitmap, 0, rbio->stripe_nsectors);
-From d507eefdb5832348bc728b963f3d7c8898ffb0a4 Mon Sep 17 00:00:00 2001
+From f55474d2c5c8a84ee73003e6ea52ada8fd0152be Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:04:12 -0400
Subject: [PATCH 09/12] btrfs: raid56: rebuild from Q when a sector rebuilt
1 file changed, 95 insertions(+), 20 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 616beef40d8c0..c4bea99e0b411 100644
+index 1d9917330e912..0a84eab7db224 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2300,6 +2300,94 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio,
+@@ -2317,6 +2317,94 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio,
kunmap_local(unmap_array[stripe_nr]);
}
/*
* Recover a vertical stripe specified by @sector_nr.
* @*pointers are the pre-allocated pointers by the caller, so we don't
-@@ -2311,7 +2399,7 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
+@@ -2328,7 +2416,7 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
int found_errors;
int faila;
int failb;
/*
* Now we just use bitmap to mark the horizontal stripes in
-@@ -2333,25 +2421,12 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
+@@ -2350,25 +2438,12 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
if (unlikely(found_errors > rbio->bioc->max_errors))
return -EIO;
-From 6dfdbfdffe7d7f18f1112740a6e3a9baa06dbb93 Mon Sep 17 00:00:00 2001
+From 200a23a21458376d5d670e46e7a2c8a3a4b34201 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:43:10 -0400
Subject: [PATCH 10/12] btrfs: raid56: count I/O errors in the device stats
int btrfs_repair_bbio_failure(struct btrfs_bio *bbio, const struct bvec_iter *orig_iter,
u32 length, int mirror_num);
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index c4bea99e0b411..232cc91584ea2 100644
+index 0a84eab7db224..673c579147b15 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -1777,11 +1777,29 @@ static void rbio_wait_io(struct btrfs_raid_bio *rbio)
+@@ -1790,11 +1790,29 @@ static void rbio_wait_io(struct btrfs_raid_bio *rbio)
wait_for_completion(&rbio->io_done);
}
rbio_update_error_bitmap(rbio, bio);
} else {
set_bio_pages_uptodate(rbio, bio);
-@@ -2745,8 +2763,10 @@ static void raid_wait_write_end_io(struct bio *bio)
+@@ -2762,8 +2780,10 @@ static void raid_wait_write_end_io(struct bio *bio)
{
struct btrfs_raid_bio *rbio = bio->bi_private;
-From 95d142c556b58d28b69c8c9aa579470eddce6d19 Mon Sep 17 00:00:00 2001
+From 4f9f89c3d420ce96b9e541f22aebbeaa469a2ceb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 15:52:51 -0400
Subject: [PATCH 11/12] btrfs: raid56: write back the sectors a sub-stripe
1 file changed, 152 insertions(+)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 232cc91584ea2..5732c2d8ea359 100644
+index 673c579147b15..0b10204b70a50 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2813,10 +2813,153 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -2830,10 +2830,153 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
return false;
}
int ret = 0;
/*
-@@ -2845,6 +2988,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2862,6 +3005,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
ret = rmw_read_wait_recover(rbio);
if (ret < 0)
goto out;
}
/*
-@@ -2878,11 +3022,18 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2895,11 +3039,18 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
ret = rmw_assemble_write_bios(rbio, &bio_list);
if (ret < 0)
goto out;
/* We may have more errors than our tolerance during the read. */
for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
-@@ -2895,6 +3046,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2912,6 +3063,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
}
}
out:
-From f7e693d10be20b7f83d5ba52569425bc68c36807 Mon Sep 17 00:00:00 2001
+From 796097dafc9486af8ee93c8e073d5ca1de5cfc14 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 03:54:55 -0400
Subject: [PATCH 12/12] DO-NOT-UPSTREAM: btrfs: raid56: debug knob for the rbio
/*
* This protects the ordered operations list only while we are
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5732c2d8ea359..c44e447b7c4a5 100644
+index 0b10204b70a50..5ea3efebfa6c8 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -198,6 +198,9 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
if (info->stripe_hash_table)
return 0;
-@@ -601,6 +604,23 @@ static void btrfs_clear_rbio_cache(struct btrfs_fs_info *info)
+@@ -605,6 +608,23 @@ static void btrfs_clear_rbio_cache(struct btrfs_fs_info *info)
spin_unlock(&table->cache_lock);
}
/*
* remove all cached entries and free the hash table
* used by unmount
-@@ -625,12 +645,25 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
+@@ -629,12 +649,25 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
* If the size of the rbio cache is too big, we
* prune an item.
*/
table = rbio->bioc->fs_info->stripe_hash_table;
-@@ -650,15 +683,17 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
+@@ -654,15 +687,17 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
spin_unlock(&rbio->bio_list_lock);
spin_unlock(&table->cache_lock);
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index c7c4b0db61f4c..8d28e2a77c62b 100644
+index be507cceb465d..0a25e41a00132 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -295,6 +295,9 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+@@ -290,6 +290,9 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
#endif
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..78688c36f8b02 100644
+index 89b0a4ef4063e..c208300634ebc 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -25,6 +25,7 @@
-From 9970d7e44abf0e5a7c67c93228908af5a0303f86 Mon Sep 17 00:00:00 2001
+From b7b4005cacc44b50375cbb55d550f35eed1662f6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Wed, 21 Oct 2026 07:09:39 -0400
-Subject: [PATCH 00/13] btrfs: raid56 scrub and device replace with unrepairable data
+Date: Sun, 25 Oct 2026 03:13:39 -0400
+Subject: [PATCH 00/12] btrfs: raid56 scrub and device replace with unrepairable data
To: linux-btrfs@vger.kernel.org
RAID5/6 scrub and device replace handle uncorrectable data differently
the scrub or replace moves on, and the rows of a full stripe that can
still be verified are verified and copied.
-Patch 1 is Filipe Manana's "btrfs: scrub: fix lost error return value
-when scrubbing raid56 parity stripe" (in for-next), included unchanged
-so the series applies; it drops out when the base contains it.
+The series applies on top of Filipe Manana's "btrfs: scrub: fix lost
+error return value when scrubbing raid56 parity stripe" (ec0795c045c3
+in for-next), which this base contains.
-Patch 2 checks P/Q per row. When a data stripe has unrepaired sectors,
+Patch 1 checks P/Q per row. When a data stripe has unrepaired sectors,
scrub_raid56_parity_stripe() skipped the parity check for the whole full
stripe, so P/Q of the other rows was never verified, and on dev-replace
the replaced device's P/Q strip was never written to the target. Now
only the rows with unrepaired sectors are left out. A full stripe with
unrepaired data still fails the scrub with -EIO at this point.
-Patch 3 copies the original P/Q of the unrepairable rows to the replace
+Patch 2 copies the original P/Q of the unrepairable rows to the replace
target, so a transient read failure during the replace does not make
those rows unrecoverable from the new device.
-Patch 4 copies the unrepaired data sectors to the target verbatim. On
+Patch 3 copies the unrepaired data sectors to the target verbatim. On
raid56 the replaced strip is an input to every later rebuild of its row,
so leaving it unwritten damages other devices' sectors too.
-Patch 5 copies every sector of the raid56 data stripes to the target,
+Patch 4 copies every sector of the raid56 data stripes to the target,
including sectors that hold no extent (deleted data, never-written
space) in full stripes that have live data, and data stripes with no
extent at all in such full stripes. Replace copied only extents, so
replacing any raid56 device, healthy or not, lost blocks that were
recoverable before (667-1599 per replace in the test below).
-Patch 6 makes "replace -r" avoid only the source device's own stripes.
+Patch 5 makes "replace -r" avoid only the source device's own stripes.
The avoid mode was applied to every stripe read, including the other
devices' data stripes read by the parity scrub, which were then rebuilt
from P and used, unverified, to recompute parity.
-Patch 7 reads the no-extent sectors from the source when -r is given
+Patch 6 reads the no-extent sectors from the source when -r is given
and the source is present. Their rebuild cannot be verified (no csum)
and carries the damage of any other bad strip in the row; with patches
5-6 alone, -r replaces lost 682-878 blocks. It is separate so it can
be dropped if reading the source here is not wanted.
-Patch 8 stops raid56 scrub from failing on the first full stripe with
+Patch 7 stops raid56 scrub from failing on the first full stripe with
an uncorrectable sector. -EIO there ended the scrub of every device
holding P or Q for that stripe, and since parity rotates, a few bad
stripes stopped most of the array's scrub, leaving later errors
uncounted and correctable ones unrepaired. It comes last so there is
no point in the series where replace carries on past a bad row without
-patches 2-3 writing its parity.
+patches 1-2 writing its parity.
-Patch 9 makes a read-only scrub (-r) of raid56 parity write nothing.
+Patch 8 makes a read-only scrub (-r) of raid56 parity write nothing.
finish_parity_scrub() never checked sctx->readonly, so a read-only
scrub rewrote P/Q that disagreed with the data, on a read-only mount
too. The mismatches are still verified and counted. It comes before
-patch 10 so that no point in the series rebuilds data in a read-only
+patch 9 so that no point in the series rebuilds data in a read-only
scrub. Fixes: 5a6ac9eacb49.
-Patch 10 lets raid56 parity scrub repair a raid6 data strip that has
+Patch 9 lets raid56 parity scrub repair a raid6 data strip that has
no csum. When the scrubbed P and Q both disagree with the data in a
way that locates a single data strip (dQ = g^z dP for every differing
byte), scrub rebuilds that strip from P and Q and writes it back
of Q does not repeat it. RAID5 has no such redundancy and keeps
today's behaviour. Fixes: 5a6ac9eacb49.
-Patch 11 counts parity mismatches found by raid56 parity scrub as
-corruption errors: in the device stats of the data member patch 10
+Patch 10 counts parity mismatches found by raid56 parity scrub as
+corruption errors: in the device stats of the data member patch 9
rebuilt, otherwise of the scrubbed parity member, and in the scrub's
corrected count. They were rewritten silently before. On RAID5, and
-on a RAID6 row patch 10 cannot locate, a mismatch may equally be
+on a RAID6 row patch 9 cannot locate, a mismatch may equally be
undetectable corruption in a data strip without csums; it is charged to
the parity member because there is no better information.
-Patch 12 names the right device in raid56 scrub error messages. The
+Patch 11 names the right device in raid56 scrub error messages. The
"fixed up error / checksum error ... on dev X" lines mapped the sector
with a non-READ op, which on raid56 returns the full-stripe write map,
so they named the device of the full stripe's first data strip: damage
on one device was reported on most of them. Fixes: 0096580713ff.
-Patch 13 counts the data repairs a raid56 parity scrub makes. The
+Patch 12 counts the data repairs a raid56 parity scrub makes. The
parity scrub of the P/Q holder reads and repairs the full stripe's data
strips without reporting them, so a damaged sector it reached before
the data device's own scrub was repaired and counted nowhere: a raid6
target, and no data lands at the wrong place, on misc-next and 6.18,
under KASAN.
-Filipe Manana (1):
- btrfs: scrub: fix lost error return value when scrubbing raid56 parity
- stripe
-
Zygo Blaxell (12):
btrfs: scrub: check raid56 parity of the rows without unrepaired data
btrfs: scrub: copy raid56 parity of unrepairable rows to the replace
fs/btrfs/raid56.c | 234 +++++++++++++++++++++++--
fs/btrfs/raid56.h | 9 +-
- fs/btrfs/scrub.c | 433 +++++++++++++++++++++++++++++++++++++++++-----
- 3 files changed, 617 insertions(+), 59 deletions(-)
+ fs/btrfs/scrub.c | 434 +++++++++++++++++++++++++++++++++++++++++-----
+ 3 files changed, 618 insertions(+), 59 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
--- /dev/null
+From 3a63fbd085fcf4b7844e7c4bb8f6c12bfabc35cc Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Fri, 16 Oct 2026 02:32:16 -0400
+Subject: [PATCH 01/12] btrfs: scrub: check raid56 parity of the rows without
+ unrepaired data
+To: linux-btrfs@vger.kernel.org
+
+When a data stripe of a full stripe has unrepaired sectors,
+scrub_raid56_parity_stripe() skips the P/Q check for the whole full
+stripe. Parity is per row (the same sector of every strip), so only the
+rows that contain an unrepaired data sector need to be left alone.
+Skipping the whole full stripe has two costs:
+
+ - on scrub, P/Q of the other rows is never verified or repaired;
+
+ - on dev-replace, the parity scrub is the only path that writes the
+ replaced device's P/Q strip to the target (finish_parity_scrub()
+ duplicates its writes when the strip being scrubbed is on the replace
+ source). Skipping it leaves that strip unwritten on the target, so
+ the good data strips of the full stripe can no longer be rebuilt from
+ the new device.
+
+Collect the rows with unrepaired data sectors from all data stripes,
+leave them out of the bitmap passed to the parity scrub, and check and
+regenerate P/Q for the remaining rows. The bad rows keep their existing
+P/Q on scrub, and on dev-replace nothing is written to the target for
+them. That is the rule the other profiles already follow when they copy
+a data stripe with uncorrectable sectors to the replace target
+(flush_scrub_stripes() writes only the good sectors).
+
+A full stripe with unrepaired data sectors still fails the scrub of the
+device with -EIO, now after its good rows have been checked. Whether
+the scrub should fail at all is left to a later change.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 33 ++++++++++++++++++++++++++-------
+ 1 file changed, 26 insertions(+), 7 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 98362c91bce43..73d200304271d 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2156,6 +2156,8 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ const u32 stripe_len = map->stripe_len;
+ const int data_stripes = nr_data_stripes(map);
+ unsigned long extent_bitmap = 0;
++ unsigned long bad_rows = 0;
++ const u32 nr_sectors = map->stripe_len >> fs_info->sectorsize_bits;
+ int ret;
+
+ ASSERT(sctx->raid56_data_stripes);
+@@ -2243,9 +2245,9 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ ASSERT(!btrfs_is_zoned(sctx->fs_info));
+
+ /*
+- * Now all data stripes are properly verified. Check if we have any
+- * unrepaired, if so abort immediately or we could further corrupt the
+- * P/Q stripes.
++ * Now all data stripes are properly verified. Collect the rows that
++ * still have unrepaired sectors: P/Q computed from them would be wrong,
++ * so those rows are left out of the P/Q check below.
+ *
+ * During the loop, also populate extent_bitmap.
+ */
+@@ -2268,15 +2270,32 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ "scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl",
+ full_stripe_start, i, stripe->nr_sectors,
+ &error);
+- return -EIO;
++ bitmap_or(&bad_rows, &bad_rows, &error,
++ stripe->nr_sectors);
+ }
+ bitmap_or(&extent_bitmap, &extent_bitmap, &has_extent,
+ stripe->nr_sectors);
+ }
+
+- /* Now we can check and regenerate the P/Q stripe. */
+- return scrub_raid56_cached_parity(sctx, scrub_dev, map, full_stripe_start,
+- &extent_bitmap);
++ /*
++ * Parity is per row. Leave the existing P/Q of the bad rows alone
++ * (and, during dev-replace, write nothing for them to the target, as
++ * for the bad sectors of the other profiles), but check and regenerate
++ * the rest.
++ */
++ bitmap_andnot(&extent_bitmap, &extent_bitmap, &bad_rows, nr_sectors);
++ if (!bitmap_empty(&extent_bitmap, nr_sectors)) {
++ /* Now we can check and regenerate the P/Q stripe. */
++ ret = scrub_raid56_cached_parity(sctx, scrub_dev, map,
++ full_stripe_start, &extent_bitmap);
++ if (ret)
++ return ret;
++ }
++
++ /* The unrepaired data sectors still fail the scrub. */
++ if (!bitmap_empty(&bad_rows, nr_sectors))
++ return -EIO;
++ return 0;
+ }
+
+ /*
+--
+2.47.3
+
+++ /dev/null
-From 84fa71315be6366bf0d836536c7c7f50560aa1f5 Mon Sep 17 00:00:00 2001
-From: Filipe Manana <fdmanana@suse.com>
-Date: Thu, 15 Oct 2026 18:45:45 +0100
-Subject: [PATCH 01/13] btrfs: scrub: fix lost error return value when
- scrubbing raid56 parity stripe
-To: linux-btrfs@vger.kernel.org
-
-If we find errors we are returning the value of 'ret', which has a value
-of 0 from some previous function call that succeeded, instead of returning
-an -EIO error. Fix this by returning -EIO instead of 'ret'.
-
-Fixes: fab0c0f03cfd ("btrfs: introduce BTRFS_PATH_AUTO_RELEASE() helper")
-Reviewed-by: Qu Wenruo <wqu@suse.com>
-Signed-off-by: Filipe Manana <fdmanana@suse.com>
-Signed-off-by: David Sterba <dsterba@suse.com>
----
- fs/btrfs/scrub.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 479c0e037015a..ba2e27cc53519 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2250,7 +2250,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- "scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl",
- full_stripe_start, i, stripe->nr_sectors,
- &error);
-- return ret;
-+ return -EIO;
- }
- bitmap_or(&extent_bitmap, &extent_bitmap, &has_extent,
- stripe->nr_sectors);
---
-2.47.3
-
+++ /dev/null
-From fdce5181605d8fc3d78a4852e5a04d310c35a521 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 16 Oct 2026 02:32:16 -0400
-Subject: [PATCH 02/13] btrfs: scrub: check raid56 parity of the rows without
- unrepaired data
-To: linux-btrfs@vger.kernel.org
-
-When a data stripe of a full stripe has unrepaired sectors,
-scrub_raid56_parity_stripe() skips the P/Q check for the whole full
-stripe. Parity is per row (the same sector of every strip), so only the
-rows that contain an unrepaired data sector need to be left alone.
-Skipping the whole full stripe has two costs:
-
- - on scrub, P/Q of the other rows is never verified or repaired;
-
- - on dev-replace, the parity scrub is the only path that writes the
- replaced device's P/Q strip to the target (finish_parity_scrub()
- duplicates its writes when the strip being scrubbed is on the replace
- source). Skipping it leaves that strip unwritten on the target, so
- the good data strips of the full stripe can no longer be rebuilt from
- the new device.
-
-Collect the rows with unrepaired data sectors from all data stripes,
-leave them out of the bitmap passed to the parity scrub, and check and
-regenerate P/Q for the remaining rows. The bad rows keep their existing
-P/Q on scrub, and on dev-replace nothing is written to the target for
-them. That is the rule the other profiles already follow when they copy
-a data stripe with uncorrectable sectors to the replace target
-(flush_scrub_stripes() writes only the good sectors).
-
-A full stripe with unrepaired data sectors still fails the scrub of the
-device with -EIO, now after its good rows have been checked. Whether
-the scrub should fail at all is left to a later change.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 33 ++++++++++++++++++++++++++-------
- 1 file changed, 26 insertions(+), 7 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index ba2e27cc53519..8083ad640b2c1 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2139,6 +2139,8 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- bool all_empty = true;
- const int data_stripes = nr_data_stripes(map);
- unsigned long extent_bitmap = 0;
-+ unsigned long bad_rows = 0;
-+ const u32 nr_sectors = BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits;
- int ret;
-
- ASSERT(sctx->raid56_data_stripes);
-@@ -2225,9 +2227,9 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- ASSERT(!btrfs_is_zoned(sctx->fs_info));
-
- /*
-- * Now all data stripes are properly verified. Check if we have any
-- * unrepaired, if so abort immediately or we could further corrupt the
-- * P/Q stripes.
-+ * Now all data stripes are properly verified. Collect the rows that
-+ * still have unrepaired sectors: P/Q computed from them would be wrong,
-+ * so those rows are left out of the P/Q check below.
- *
- * During the loop, also populate extent_bitmap.
- */
-@@ -2250,15 +2252,32 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- "scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl",
- full_stripe_start, i, stripe->nr_sectors,
- &error);
-- return -EIO;
-+ bitmap_or(&bad_rows, &bad_rows, &error,
-+ stripe->nr_sectors);
- }
- bitmap_or(&extent_bitmap, &extent_bitmap, &has_extent,
- stripe->nr_sectors);
- }
-
-- /* Now we can check and regenerate the P/Q stripe. */
-- return scrub_raid56_cached_parity(sctx, scrub_dev, map, full_stripe_start,
-- &extent_bitmap);
-+ /*
-+ * Parity is per row. Leave the existing P/Q of the bad rows alone
-+ * (and, during dev-replace, write nothing for them to the target, as
-+ * for the bad sectors of the other profiles), but check and regenerate
-+ * the rest.
-+ */
-+ bitmap_andnot(&extent_bitmap, &extent_bitmap, &bad_rows, nr_sectors);
-+ if (!bitmap_empty(&extent_bitmap, nr_sectors)) {
-+ /* Now we can check and regenerate the P/Q stripe. */
-+ ret = scrub_raid56_cached_parity(sctx, scrub_dev, map,
-+ full_stripe_start, &extent_bitmap);
-+ if (ret)
-+ return ret;
-+ }
-+
-+ /* The unrepaired data sectors still fail the scrub. */
-+ if (!bitmap_empty(&bad_rows, nr_sectors))
-+ return -EIO;
-+ return 0;
- }
-
- /*
---
-2.47.3
-
--- /dev/null
+From dbd38ff999b5f6be70fee9c3b537c4f16219e03a Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Fri, 16 Oct 2026 02:32:16 -0400
+Subject: [PATCH 02/12] btrfs: scrub: copy raid56 parity of unrepairable rows
+ to the replace target
+To: linux-btrfs@vger.kernel.org
+
+"btrfs: scrub: check raid56 parity of the rows without unrepaired data"
+leaves the rows of a full stripe that contain unrepaired data out of the
+parity scrub, so during dev-replace the target gets nothing for those
+rows of the replaced device's P/Q strip.
+
+A row is unrepairable when more of its strips failed than P/Q can
+rebuild, but the failure is not always permanent: a read error during
+the replace can be transient. On the source, such a row is still
+covered by its original P/Q, so if the data turns out to be readable
+later the row can be recovered. On the target, with nothing written for
+those P/Q sectors, that hope is gone.
+
+When replacing, copy the original P/Q sectors of those rows from the
+source device to the target, so the target's P/Q for those rows matches
+the source's and the rows stay as recoverable from the new device as
+they were from the old one. The copy is best effort: if the source
+sectors cannot be read or the target write fails, log it and carry on,
+leaving those rows unwritten as before.
+
+The commit above does not depend on this one, but a scrub that does not
+fail on unrepaired data does: a replace that carries on past such a row
+would otherwise leave its P/Q unwritten on the target.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 68 +++++++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 65 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 73d200304271d..8e4febe466dbc 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2142,6 +2142,65 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
+ return ret;
+ }
+
++/*
++ * Dev-replace: copy the original P/Q sectors of the rows that the parity scrub
++ * leaves out (@bad_rows: rows with unrepaired data) from the source device to
++ * the replace target, so the target's P/Q for those rows matches the source's.
++ * Best effort: a failed copy is logged and the replace goes on.
++ */
++static void scrub_raid56_copy_parity_rows(struct scrub_ctx *sctx,
++ struct btrfs_device *scrub_dev,
++ struct btrfs_block_group *bg,
++ struct btrfs_chunk_map *map,
++ u64 full_stripe_start,
++ unsigned long bad_rows)
++{
++ struct btrfs_fs_info *fs_info = sctx->fs_info;
++ struct btrfs_device *tgtdev = sctx->wr_tgtdev;
++ const u32 nr_sectors = map->stripe_len >> fs_info->sectorsize_bits;
++ const int data_stripes = nr_data_stripes(map);
++ unsigned int start, end;
++ u64 physical;
++ int rot;
++ int i;
++ void *buf;
++
++ if (!tgtdev || !tgtdev->bdev || !scrub_dev->bdev)
++ return;
++ for (i = 0; i < map->num_stripes; i++)
++ if (map->stripes[i].dev == scrub_dev)
++ break;
++ if (WARN_ON_ONCE(i == map->num_stripes))
++ return;
++ rot = div_u64(full_stripe_start - bg->start, data_stripes) >>
++ map->stripe_shift;
++ physical = map->stripes[i].physical +
++ btrfs_stripe_nr_to_offset(rot, map->stripe_len);
++
++ buf = kmalloc(BTRFS_STRIPE_LEN, GFP_NOFS);
++ if (!buf)
++ return;
++ btrfs_bio_counter_inc_blocked(fs_info);
++ for_each_set_bitrange(start, end, &bad_rows, nr_sectors) {
++ const u64 pos = physical +
++ ((u64)start << fs_info->sectorsize_bits);
++ const u32 len = (end - start) << fs_info->sectorsize_bits;
++ int ret;
++
++ ret = bdev_rw_virt(scrub_dev->bdev, pos >> SECTOR_SHIFT, buf,
++ len, REQ_OP_READ);
++ if (!ret)
++ ret = bdev_rw_virt(tgtdev->bdev, pos >> SECTOR_SHIFT,
++ buf, len, REQ_OP_WRITE);
++ if (ret)
++ btrfs_warn_rl(fs_info,
++"scrub: failed to copy parity of full stripe %llu sectors %u-%u to the replace target: %d",
++ full_stripe_start, start, end - 1, ret);
++ }
++ btrfs_bio_counter_dec(fs_info);
++ kfree(buf);
++}
++
+ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ struct btrfs_device *scrub_dev,
+ struct btrfs_block_group *bg,
+@@ -2277,11 +2336,14 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ stripe->nr_sectors);
+ }
+
++ if (sctx->is_dev_replace && !bitmap_empty(&bad_rows, nr_sectors))
++ scrub_raid56_copy_parity_rows(sctx, scrub_dev, bg, map,
++ full_stripe_start, bad_rows);
++
+ /*
+ * Parity is per row. Leave the existing P/Q of the bad rows alone
+- * (and, during dev-replace, write nothing for them to the target, as
+- * for the bad sectors of the other profiles), but check and regenerate
+- * the rest.
++ * (during dev-replace it is copied to the target as it is, above), but
++ * check and regenerate the rest.
+ */
+ bitmap_andnot(&extent_bitmap, &extent_bitmap, &bad_rows, nr_sectors);
+ if (!bitmap_empty(&extent_bitmap, nr_sectors)) {
+--
+2.47.3
+
+++ /dev/null
-From e47bef121de9dabf61d7044fb5adf5b0aabad031 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 16 Oct 2026 02:32:16 -0400
-Subject: [PATCH 03/13] btrfs: scrub: copy raid56 parity of unrepairable rows
- to the replace target
-To: linux-btrfs@vger.kernel.org
-
-"btrfs: scrub: check raid56 parity of the rows without unrepaired data"
-leaves the rows of a full stripe that contain unrepaired data out of the
-parity scrub, so during dev-replace the target gets nothing for those
-rows of the replaced device's P/Q strip.
-
-A row is unrepairable when more of its strips failed than P/Q can
-rebuild, but the failure is not always permanent: a read error during
-the replace can be transient. On the source, such a row is still
-covered by its original P/Q, so if the data turns out to be readable
-later the row can be recovered. On the target, with nothing written for
-those P/Q sectors, that hope is gone.
-
-When replacing, copy the original P/Q sectors of those rows from the
-source device to the target, so the target's P/Q for those rows matches
-the source's and the rows stay as recoverable from the new device as
-they were from the old one. The copy is best effort: if the source
-sectors cannot be read or the target write fails, log it and carry on,
-leaving those rows unwritten as before.
-
-The commit above does not depend on this one, but a scrub that does not
-fail on unrepaired data does: a replace that carries on past such a row
-would otherwise leave its P/Q unwritten on the target.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 67 +++++++++++++++++++++++++++++++++++++++++++++---
- 1 file changed, 64 insertions(+), 3 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 8083ad640b2c1..9cfa426b40ff9 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2126,6 +2126,64 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
- return ret;
- }
-
-+/*
-+ * Dev-replace: copy the original P/Q sectors of the rows that the parity scrub
-+ * leaves out (@bad_rows: rows with unrepaired data) from the source device to
-+ * the replace target, so the target's P/Q for those rows matches the source's.
-+ * Best effort: a failed copy is logged and the replace goes on.
-+ */
-+static void scrub_raid56_copy_parity_rows(struct scrub_ctx *sctx,
-+ struct btrfs_device *scrub_dev,
-+ struct btrfs_block_group *bg,
-+ struct btrfs_chunk_map *map,
-+ u64 full_stripe_start,
-+ unsigned long bad_rows)
-+{
-+ struct btrfs_fs_info *fs_info = sctx->fs_info;
-+ struct btrfs_device *tgtdev = sctx->wr_tgtdev;
-+ const u32 nr_sectors = BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits;
-+ const int data_stripes = nr_data_stripes(map);
-+ unsigned int start, end;
-+ u64 physical;
-+ int rot;
-+ int i;
-+ void *buf;
-+
-+ if (!tgtdev || !tgtdev->bdev || !scrub_dev->bdev)
-+ return;
-+ for (i = 0; i < map->num_stripes; i++)
-+ if (map->stripes[i].dev == scrub_dev)
-+ break;
-+ if (WARN_ON_ONCE(i == map->num_stripes))
-+ return;
-+ rot = div_u64(full_stripe_start - bg->start, data_stripes) >>
-+ BTRFS_STRIPE_LEN_SHIFT;
-+ physical = map->stripes[i].physical + btrfs_stripe_nr_to_offset(rot);
-+
-+ buf = kmalloc(BTRFS_STRIPE_LEN, GFP_NOFS);
-+ if (!buf)
-+ return;
-+ btrfs_bio_counter_inc_blocked(fs_info);
-+ for_each_set_bitrange(start, end, &bad_rows, nr_sectors) {
-+ const u64 pos = physical +
-+ ((u64)start << fs_info->sectorsize_bits);
-+ const u32 len = (end - start) << fs_info->sectorsize_bits;
-+ int ret;
-+
-+ ret = bdev_rw_virt(scrub_dev->bdev, pos >> SECTOR_SHIFT, buf,
-+ len, REQ_OP_READ);
-+ if (!ret)
-+ ret = bdev_rw_virt(tgtdev->bdev, pos >> SECTOR_SHIFT,
-+ buf, len, REQ_OP_WRITE);
-+ if (ret)
-+ btrfs_warn_rl(fs_info,
-+"scrub: failed to copy parity of full stripe %llu sectors %u-%u to the replace target: %d",
-+ full_stripe_start, start, end - 1, ret);
-+ }
-+ btrfs_bio_counter_dec(fs_info);
-+ kfree(buf);
-+}
-+
- static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- struct btrfs_device *scrub_dev,
- struct btrfs_block_group *bg,
-@@ -2259,11 +2317,14 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- stripe->nr_sectors);
- }
-
-+ if (sctx->is_dev_replace && !bitmap_empty(&bad_rows, nr_sectors))
-+ scrub_raid56_copy_parity_rows(sctx, scrub_dev, bg, map,
-+ full_stripe_start, bad_rows);
-+
- /*
- * Parity is per row. Leave the existing P/Q of the bad rows alone
-- * (and, during dev-replace, write nothing for them to the target, as
-- * for the bad sectors of the other profiles), but check and regenerate
-- * the rest.
-+ * (during dev-replace it is copied to the target as it is, above), but
-+ * check and regenerate the rest.
- */
- bitmap_andnot(&extent_bitmap, &extent_bitmap, &bad_rows, nr_sectors);
- if (!bitmap_empty(&extent_bitmap, nr_sectors)) {
---
-2.47.3
-
--- /dev/null
+From e00230459d26e6365c353de0083231d53a82b7da Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Fri, 16 Oct 2026 02:32:17 -0400
+Subject: [PATCH 03/12] btrfs: scrub: copy unrepaired raid56 data sectors to
+ the replace target
+To: linux-btrfs@vger.kernel.org
+
+When dev-replace copies a data stripe, it writes only the sectors that
+were read or repaired successfully (flush_scrub_stripes()); sectors that
+could not be repaired are left unwritten on the target. For mirrored
+profiles that loses nothing: the sector was bad on every copy anyway,
+and the csum keeps reporting it.
+
+RAID56 is different. The replaced device's data strip is an input to
+every later rebuild of the other strips in its rows: when another device
+of the row fails, its sector is reconstructed from P/Q and the remaining
+data strips, including this one. An unwritten target sector turns those
+rebuilds into garbage, where the source's sector, even with a bad csum,
+kept the row as consistent as it was. And as with the parity rows, the
+failure may have been a transient read error, in which case the
+source's bytes are the right data.
+
+For RAID56 block groups only, write the unrepaired data sectors to the
+target verbatim, as they are on the source. The scrub buffer holds the
+last failed reconstruction attempt for them, not the source's bytes, so
+they are read again from the source. The copy is best effort: on a read
+or write error it is logged and the replace carries on. This
+deliberately differs from the good-sectors-only rule of the other
+profiles, for the reason above.
+
+This is an optional improvement: it does not depend on "btrfs: scrub:
+copy raid56 parity of unrepairable rows to the replace target", and
+"btrfs: scrub: check raid56 parity of the rows without unrepaired data"
+does not depend on it.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 50 insertions(+)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 8e4febe466dbc..4e815980c08b5 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -1938,6 +1938,54 @@ static void submit_initial_group_read(struct scrub_ctx *sctx,
+ blk_finish_plug(&plug);
+ }
+
++/*
++ * Dev-replace on RAID56: give the replace target the source's bytes for the
++ * data sectors of @stripe that could not be repaired (@bad), instead of
++ * leaving them unwritten as the other profiles do. A RAID56 data strip is an
++ * input to every rebuild of the other strips in its rows, so an unwritten
++ * target sector would make those rebuilds read garbage. The stripe buffer
++ * holds the last failed reconstruction attempt for these sectors, not the
++ * source's bytes, so read them again. Best effort: a failed copy is logged
++ * and the replace goes on.
++ */
++static void scrub_raid56_copy_bad_sectors(struct scrub_ctx *sctx,
++ struct scrub_stripe *stripe,
++ unsigned long bad)
++{
++ struct btrfs_fs_info *fs_info = sctx->fs_info;
++ struct btrfs_device *tgtdev = sctx->wr_tgtdev;
++ unsigned int start, end;
++ void *buf;
++
++ if (!(stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) ||
++ bitmap_empty(&bad, stripe->nr_sectors))
++ return;
++ if (!tgtdev || !tgtdev->bdev || !stripe->dev->bdev)
++ return;
++ buf = kmalloc(BTRFS_STRIPE_LEN, GFP_NOFS);
++ if (!buf)
++ return;
++ btrfs_bio_counter_inc_blocked(fs_info);
++ for_each_set_bitrange(start, end, &bad, stripe->nr_sectors) {
++ const u64 off = (u64)start << fs_info->sectorsize_bits;
++ const u64 pos = stripe->physical + off;
++ const u32 len = (end - start) << fs_info->sectorsize_bits;
++ int ret;
++
++ ret = bdev_rw_virt(stripe->dev->bdev, pos >> SECTOR_SHIFT, buf,
++ len, REQ_OP_READ);
++ if (!ret)
++ ret = bdev_rw_virt(tgtdev->bdev, pos >> SECTOR_SHIFT,
++ buf, len, REQ_OP_WRITE);
++ if (ret)
++ btrfs_warn_rl(fs_info,
++"scrub: failed to copy unrepaired sectors at logical %llu to the replace target: %d",
++ stripe->logical + off, ret);
++ }
++ btrfs_bio_counter_dec(fs_info);
++ kfree(buf);
++}
++
+ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+ {
+ struct btrfs_fs_info *fs_info = sctx->fs_info;
+@@ -1989,6 +2037,8 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+ error = scrub_bitmap_read_error(stripe);
+ bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
+ scrub_write_sectors(sctx, stripe, good, true);
++ scrub_raid56_copy_bad_sectors(sctx, stripe,
++ error & has_extent);
+ }
+ }
+
+--
+2.47.3
+
--- /dev/null
+From dcef108c87c970b53ef041811305692649deaac6 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Fri, 16 Oct 2026 20:33:38 -0400
+Subject: [PATCH 04/12] btrfs: scrub: copy every sector of raid56 data stripes
+ to the replace target
+To: linux-btrfs@vger.kernel.org
+
+Dev-replace copies a data stripe of the source device by writing the
+sectors that hold an extent (flush_scrub_stripes()), and it only visits
+the data stripes that hold at least one extent: queue_scrub_stripe()
+skips the others. For mirrored profiles that is all that matters.
+
+For RAID56 it is not. P/Q of a row is computed over every data strip of
+the row, whether or not the strip's sector holds an extent (deleted data,
+never written space, zeroed padding), and every later rebuild of another
+data strip in the row reads the replaced device's sector as an input.
+If the target never got that sector, it holds whatever was there before
+the replace, the rebuild produces wrong bytes, the csum check fails and
+the read returns -EIO. So replacing any raid56 device, healthy or not,
+silently turns recoverable damage on another device into lost data, and
+leaves the affected rows without redundancy until a full scrub rewrites
+their parity.
+
+For RAID56 block groups, also write the sectors of the data stripe that
+hold no extent and were read without error, and queue the data stripes
+without any extent when another data stripe of their full stripe holds
+one. The bytes written are the ones the scrub read: the source's
+on-disk bytes, which keep the row as consistent with its P/Q as it was
+on the source even if other strips of the row are bad; or, when the
+source is missing or the user asked to avoid reading it (-r), the
+stripe rebuilt from the other strips. A rebuilt sector is consistent
+with P/Q by construction, but if another strip of the row is bad at the
+time, the rebuild carries that damage and the bad sector can no longer
+be recovered; that is the price of not reading the source. Full
+stripes without any extent are still skipped: a later write to one
+computes P/Q from what is on disk at that time.
+
+Measured with a test that fills a 5-device raid5 (raid1 metadata) with
+partially filled full stripes, corrupts two devices in different rows
+and then replaces one of them, or a healthy device, without reading
+anything first: each replace left 5400-6700 of these sectors unwritten
+on the target, and 1028-1237 blocks that were recoverable before the
+replace returned -EIO after it (667-1302 when some rows were also
+damaged on both devices), on both a misc-next and a 6.18 based tree,
+with and without stripe_alloc. With this change all of those sectors
+are written and only the blocks that were unrecoverable before the
+replace return -EIO.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 85 insertions(+), 2 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 4e815980c08b5..f064acbd7a8ef 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -1325,8 +1325,13 @@ static void scrub_write_sectors(struct scrub_ctx *sctx, struct scrub_stripe *str
+ int sector_nr;
+
+ for_each_set_bit(sector_nr, &write_bitmap, stripe->nr_sectors) {
+- /* We should only writeback sectors covered by an extent. */
+- ASSERT(scrub_bitmap_test_bit_has_extent(stripe, sector_nr));
++ /*
++ * We should only writeback sectors covered by an extent, except
++ * for RAID56 dev-replace, see flush_scrub_stripes().
++ */
++ ASSERT(scrub_bitmap_test_bit_has_extent(stripe, sector_nr) ||
++ (dev_replace &&
++ (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)));
+
+ /* Cannot merge with previous sector, submit the current one. */
+ if (bbio && sector_nr && !test_bit(sector_nr - 1, &write_bitmap)) {
+@@ -1986,6 +1991,30 @@ static void scrub_raid56_copy_bad_sectors(struct scrub_ctx *sctx,
+ kfree(buf);
+ }
+
++/*
++ * Dev-replace on RAID56: the sectors of @stripe without an extent are inputs
++ * to the P/Q of their rows too, and the other data stripes of those rows rely
++ * on that P/Q. The replace target must hold the same bytes, or a later
++ * rebuild of another stripe from the target would be wrong.
++ *
++ * Return those sectors whose content in the stripe buffer can be copied: read
++ * from the source device, or rebuilt from the other stripes if the source is
++ * missing, is to be avoided, or failed to read.
++ */
++static unsigned long scrub_raid56_unused_sectors(struct scrub_stripe *stripe)
++{
++ struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
++ const unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
++ const unsigned long has_extent = scrub_bitmap_read_has_extent(stripe);
++ const unsigned long io_error = scrub_bitmap_read_io_error(stripe);
++ unsigned long unused = 0;
++
++ bitmap_set(&unused, 0, nr_sectors);
++ bitmap_andnot(&unused, &unused, &has_extent, nr_sectors);
++ bitmap_andnot(&unused, &unused, &io_error, nr_sectors);
++ return unused;
++}
++
+ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+ {
+ struct btrfs_fs_info *fs_info = sctx->fs_info;
+@@ -2036,6 +2065,8 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+ has_extent = scrub_bitmap_read_has_extent(stripe);
+ error = scrub_bitmap_read_error(stripe);
+ bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
++ if (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)
++ good |= scrub_raid56_unused_sectors(stripe);
+ scrub_write_sectors(sctx, stripe, good, true);
+ scrub_raid56_copy_bad_sectors(sctx, stripe,
+ error & has_extent);
+@@ -2062,6 +2093,54 @@ static void raid56_scrub_wait_endio(struct bio *bio)
+ complete(bio->bi_private);
+ }
+
++/*
++ * Dev-replace on RAID56: set up @stripe, a data stripe of the source device
++ * that has no extent, to be copied to the target anyway if another data stripe
++ * of its full stripe has one, see scrub_raid56_unused_sectors().
++ *
++ * Return 0 if @stripe is set up, >0 if there is nothing to copy, <0 on error.
++ */
++static int scrub_raid56_fill_unused_stripe(struct scrub_ctx *sctx,
++ struct btrfs_block_group *bg,
++ struct btrfs_device *dev, u64 physical,
++ int mirror_num, u64 logical,
++ u32 length, struct scrub_stripe *stripe)
++{
++ struct btrfs_fs_info *fs_info = bg->fs_info;
++ struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bg->start);
++ BTRFS_PATH_AUTO_RELEASE(path);
++ u64 full_stripe_start;
++ int ret;
++
++ if (!sctx->is_dev_replace ||
++ !(bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK))
++ return 1;
++ /* RAID56 data stripes are queued one whole stripe at a time. */
++ if (WARN_ON_ONCE(!IS_ALIGNED(logical - bg->start, stripe->stripe_len) ||
++ length != stripe->stripe_len))
++ return 1;
++
++ full_stripe_start = bg->start +
++ div_u64(logical - bg->start, bg->full_stripe_len) *
++ bg->full_stripe_len;
++ path.search_commit_root = true;
++ path.skip_locking = true;
++ ret = find_first_extent_item(extent_root, &path, full_stripe_start,
++ bg->full_stripe_len);
++ if (ret)
++ return ret;
++
++ stripe->logical = logical;
++ stripe->physical = physical;
++ stripe->dev = dev;
++ stripe->bg = bg;
++ stripe->mirror_num = mirror_num;
++ /* No extent here, nothing to report. */
++ set_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state);
++ set_bit(SCRUB_STRIPE_FLAG_INITIALIZED, &stripe->state);
++ return 0;
++}
++
+ static int queue_scrub_stripe(struct scrub_ctx *sctx, struct btrfs_block_group *bg,
+ struct btrfs_device *dev, int mirror_num,
+ u64 logical, u32 length, u64 physical,
+@@ -2084,6 +2163,10 @@ static int queue_scrub_stripe(struct scrub_ctx *sctx, struct btrfs_block_group *
+ ret = scrub_find_fill_first_stripe(bg, &sctx->extent_path,
+ &sctx->csum_path, dev, physical,
+ mirror_num, logical, length, stripe);
++ if (ret > 0)
++ ret = scrub_raid56_fill_unused_stripe(sctx, bg, dev, physical,
++ mirror_num, logical,
++ length, stripe);
+ /* Either >0 as no more extents or <0 for error. */
+ if (ret)
+ return ret;
+--
+2.47.3
+
+++ /dev/null
-From a2f3c61ffd00b724c66a9a3e7b28af23bcaee0e4 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 16 Oct 2026 02:32:17 -0400
-Subject: [PATCH 04/13] btrfs: scrub: copy unrepaired raid56 data sectors to
- the replace target
-To: linux-btrfs@vger.kernel.org
-
-When dev-replace copies a data stripe, it writes only the sectors that
-were read or repaired successfully (flush_scrub_stripes()); sectors that
-could not be repaired are left unwritten on the target. For mirrored
-profiles that loses nothing: the sector was bad on every copy anyway,
-and the csum keeps reporting it.
-
-RAID56 is different. The replaced device's data strip is an input to
-every later rebuild of the other strips in its rows: when another device
-of the row fails, its sector is reconstructed from P/Q and the remaining
-data strips, including this one. An unwritten target sector turns those
-rebuilds into garbage, where the source's sector, even with a bad csum,
-kept the row as consistent as it was. And as with the parity rows, the
-failure may have been a transient read error, in which case the
-source's bytes are the right data.
-
-For RAID56 block groups only, write the unrepaired data sectors to the
-target verbatim, as they are on the source. The scrub buffer holds the
-last failed reconstruction attempt for them, not the source's bytes, so
-they are read again from the source. The copy is best effort: on a read
-or write error it is logged and the replace carries on. This
-deliberately differs from the good-sectors-only rule of the other
-profiles, for the reason above.
-
-This is an optional improvement: it does not depend on "btrfs: scrub:
-copy raid56 parity of unrepairable rows to the replace target", and
-"btrfs: scrub: check raid56 parity of the rows without unrepaired data"
-does not depend on it.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
- 1 file changed, 50 insertions(+)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 9cfa426b40ff9..938e9b3d0ebd4 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -1922,6 +1922,54 @@ static void submit_initial_group_read(struct scrub_ctx *sctx,
- blk_finish_plug(&plug);
- }
-
-+/*
-+ * Dev-replace on RAID56: give the replace target the source's bytes for the
-+ * data sectors of @stripe that could not be repaired (@bad), instead of
-+ * leaving them unwritten as the other profiles do. A RAID56 data strip is an
-+ * input to every rebuild of the other strips in its rows, so an unwritten
-+ * target sector would make those rebuilds read garbage. The stripe buffer
-+ * holds the last failed reconstruction attempt for these sectors, not the
-+ * source's bytes, so read them again. Best effort: a failed copy is logged
-+ * and the replace goes on.
-+ */
-+static void scrub_raid56_copy_bad_sectors(struct scrub_ctx *sctx,
-+ struct scrub_stripe *stripe,
-+ unsigned long bad)
-+{
-+ struct btrfs_fs_info *fs_info = sctx->fs_info;
-+ struct btrfs_device *tgtdev = sctx->wr_tgtdev;
-+ unsigned int start, end;
-+ void *buf;
-+
-+ if (!(stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) ||
-+ bitmap_empty(&bad, stripe->nr_sectors))
-+ return;
-+ if (!tgtdev || !tgtdev->bdev || !stripe->dev->bdev)
-+ return;
-+ buf = kmalloc(BTRFS_STRIPE_LEN, GFP_NOFS);
-+ if (!buf)
-+ return;
-+ btrfs_bio_counter_inc_blocked(fs_info);
-+ for_each_set_bitrange(start, end, &bad, stripe->nr_sectors) {
-+ const u64 off = (u64)start << fs_info->sectorsize_bits;
-+ const u64 pos = stripe->physical + off;
-+ const u32 len = (end - start) << fs_info->sectorsize_bits;
-+ int ret;
-+
-+ ret = bdev_rw_virt(stripe->dev->bdev, pos >> SECTOR_SHIFT, buf,
-+ len, REQ_OP_READ);
-+ if (!ret)
-+ ret = bdev_rw_virt(tgtdev->bdev, pos >> SECTOR_SHIFT,
-+ buf, len, REQ_OP_WRITE);
-+ if (ret)
-+ btrfs_warn_rl(fs_info,
-+"scrub: failed to copy unrepaired sectors at logical %llu to the replace target: %d",
-+ stripe->logical + off, ret);
-+ }
-+ btrfs_bio_counter_dec(fs_info);
-+ kfree(buf);
-+}
-+
- static int flush_scrub_stripes(struct scrub_ctx *sctx)
- {
- struct btrfs_fs_info *fs_info = sctx->fs_info;
-@@ -1973,6 +2021,8 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
- error = scrub_bitmap_read_error(stripe);
- bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
- scrub_write_sectors(sctx, stripe, good, true);
-+ scrub_raid56_copy_bad_sectors(sctx, stripe,
-+ error & has_extent);
- }
- }
-
---
-2.47.3
-
+++ /dev/null
-From 8a2a9c58e862444eb6dedaf3198c3241f525e031 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 16 Oct 2026 20:33:38 -0400
-Subject: [PATCH 05/13] btrfs: scrub: copy every sector of raid56 data stripes
- to the replace target
-To: linux-btrfs@vger.kernel.org
-
-Dev-replace copies a data stripe of the source device by writing the
-sectors that hold an extent (flush_scrub_stripes()), and it only visits
-the data stripes that hold at least one extent: queue_scrub_stripe()
-skips the others. For mirrored profiles that is all that matters.
-
-For RAID56 it is not. P/Q of a row is computed over every data strip of
-the row, whether or not the strip's sector holds an extent (deleted data,
-never written space, zeroed padding), and every later rebuild of another
-data strip in the row reads the replaced device's sector as an input.
-If the target never got that sector, it holds whatever was there before
-the replace, the rebuild produces wrong bytes, the csum check fails and
-the read returns -EIO. So replacing any raid56 device, healthy or not,
-silently turns recoverable damage on another device into lost data, and
-leaves the affected rows without redundancy until a full scrub rewrites
-their parity.
-
-For RAID56 block groups, also write the sectors of the data stripe that
-hold no extent and were read without error, and queue the data stripes
-without any extent when another data stripe of their full stripe holds
-one. The bytes written are the ones the scrub read: the source's
-on-disk bytes, which keep the row as consistent with its P/Q as it was
-on the source even if other strips of the row are bad; or, when the
-source is missing or the user asked to avoid reading it (-r), the
-stripe rebuilt from the other strips. A rebuilt sector is consistent
-with P/Q by construction, but if another strip of the row is bad at the
-time, the rebuild carries that damage and the bad sector can no longer
-be recovered; that is the price of not reading the source. Full
-stripes without any extent are still skipped: a later write to one
-computes P/Q from what is on disk at that time.
-
-Measured with a test that fills a 5-device raid5 (raid1 metadata) with
-partially filled full stripes, corrupts two devices in different rows
-and then replaces one of them, or a healthy device, without reading
-anything first: each replace left 5400-6700 of these sectors unwritten
-on the target, and 1028-1237 blocks that were recoverable before the
-replace returned -EIO after it (667-1302 when some rows were also
-damaged on both devices), on both a misc-next and a 6.18 based tree,
-with and without stripe_alloc. With this change all of those sectors
-are written and only the blocks that were unrecoverable before the
-replace return -EIO.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--
- 1 file changed, 85 insertions(+), 2 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 938e9b3d0ebd4..fbef0eec7f41d 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -1317,8 +1317,13 @@ static void scrub_write_sectors(struct scrub_ctx *sctx, struct scrub_stripe *str
- int sector_nr;
-
- for_each_set_bit(sector_nr, &write_bitmap, stripe->nr_sectors) {
-- /* We should only writeback sectors covered by an extent. */
-- ASSERT(scrub_bitmap_test_bit_has_extent(stripe, sector_nr));
-+ /*
-+ * We should only writeback sectors covered by an extent, except
-+ * for RAID56 dev-replace, see flush_scrub_stripes().
-+ */
-+ ASSERT(scrub_bitmap_test_bit_has_extent(stripe, sector_nr) ||
-+ (dev_replace &&
-+ (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)));
-
- /* Cannot merge with previous sector, submit the current one. */
- if (bbio && sector_nr && !test_bit(sector_nr - 1, &write_bitmap)) {
-@@ -1970,6 +1975,30 @@ static void scrub_raid56_copy_bad_sectors(struct scrub_ctx *sctx,
- kfree(buf);
- }
-
-+/*
-+ * Dev-replace on RAID56: the sectors of @stripe without an extent are inputs
-+ * to the P/Q of their rows too, and the other data stripes of those rows rely
-+ * on that P/Q. The replace target must hold the same bytes, or a later
-+ * rebuild of another stripe from the target would be wrong.
-+ *
-+ * Return those sectors whose content in the stripe buffer can be copied: read
-+ * from the source device, or rebuilt from the other stripes if the source is
-+ * missing, is to be avoided, or failed to read.
-+ */
-+static unsigned long scrub_raid56_unused_sectors(struct scrub_stripe *stripe)
-+{
-+ struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
-+ const unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
-+ const unsigned long has_extent = scrub_bitmap_read_has_extent(stripe);
-+ const unsigned long io_error = scrub_bitmap_read_io_error(stripe);
-+ unsigned long unused = 0;
-+
-+ bitmap_set(&unused, 0, nr_sectors);
-+ bitmap_andnot(&unused, &unused, &has_extent, nr_sectors);
-+ bitmap_andnot(&unused, &unused, &io_error, nr_sectors);
-+ return unused;
-+}
-+
- static int flush_scrub_stripes(struct scrub_ctx *sctx)
- {
- struct btrfs_fs_info *fs_info = sctx->fs_info;
-@@ -2020,6 +2049,8 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
- has_extent = scrub_bitmap_read_has_extent(stripe);
- error = scrub_bitmap_read_error(stripe);
- bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
-+ if (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)
-+ good |= scrub_raid56_unused_sectors(stripe);
- scrub_write_sectors(sctx, stripe, good, true);
- scrub_raid56_copy_bad_sectors(sctx, stripe,
- error & has_extent);
-@@ -2046,6 +2077,54 @@ static void raid56_scrub_wait_endio(struct bio *bio)
- complete(bio->bi_private);
- }
-
-+/*
-+ * Dev-replace on RAID56: set up @stripe, a data stripe of the source device
-+ * that has no extent, to be copied to the target anyway if another data stripe
-+ * of its full stripe has one, see scrub_raid56_unused_sectors().
-+ *
-+ * Return 0 if @stripe is set up, >0 if there is nothing to copy, <0 on error.
-+ */
-+static int scrub_raid56_fill_unused_stripe(struct scrub_ctx *sctx,
-+ struct btrfs_block_group *bg,
-+ struct btrfs_device *dev, u64 physical,
-+ int mirror_num, u64 logical,
-+ u32 length, struct scrub_stripe *stripe)
-+{
-+ struct btrfs_fs_info *fs_info = bg->fs_info;
-+ struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bg->start);
-+ BTRFS_PATH_AUTO_RELEASE(path);
-+ u64 full_stripe_start;
-+ int ret;
-+
-+ if (!sctx->is_dev_replace ||
-+ !(bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK))
-+ return 1;
-+ /* RAID56 data stripes are queued one whole stripe at a time. */
-+ if (WARN_ON_ONCE(!IS_ALIGNED(logical - bg->start, BTRFS_STRIPE_LEN) ||
-+ length != BTRFS_STRIPE_LEN))
-+ return 1;
-+
-+ full_stripe_start = bg->start +
-+ div_u64(logical - bg->start, bg->full_stripe_len) *
-+ bg->full_stripe_len;
-+ path.search_commit_root = true;
-+ path.skip_locking = true;
-+ ret = find_first_extent_item(extent_root, &path, full_stripe_start,
-+ bg->full_stripe_len);
-+ if (ret)
-+ return ret;
-+
-+ stripe->logical = logical;
-+ stripe->physical = physical;
-+ stripe->dev = dev;
-+ stripe->bg = bg;
-+ stripe->mirror_num = mirror_num;
-+ /* No extent here, nothing to report. */
-+ set_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state);
-+ set_bit(SCRUB_STRIPE_FLAG_INITIALIZED, &stripe->state);
-+ return 0;
-+}
-+
- static int queue_scrub_stripe(struct scrub_ctx *sctx, struct btrfs_block_group *bg,
- struct btrfs_device *dev, int mirror_num,
- u64 logical, u32 length, u64 physical,
-@@ -2068,6 +2147,10 @@ static int queue_scrub_stripe(struct scrub_ctx *sctx, struct btrfs_block_group *
- ret = scrub_find_fill_first_stripe(bg, &sctx->extent_path,
- &sctx->csum_path, dev, physical,
- mirror_num, logical, length, stripe);
-+ if (ret > 0)
-+ ret = scrub_raid56_fill_unused_stripe(sctx, bg, dev, physical,
-+ mirror_num, logical,
-+ length, stripe);
- /* Either >0 as no more extents or <0 for error. */
- if (ret)
- return ret;
---
-2.47.3
-
--- /dev/null
+From c9a6389239a4e644ea9e2eda4be889f9050196f2 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Fri, 16 Oct 2026 20:33:38 -0400
+Subject: [PATCH 05/12] btrfs: scrub: only avoid the replace source device for
+ its own stripes
+To: linux-btrfs@vger.kernel.org
+
+With cont_reading_from_srcdev_mode AVOID (btrfs replace start -r),
+scrub_submit_initial_read() reads a stripe through the next mirror
+instead of directly. In the data path that is right: the stripes there
+are on the source device. But the RAID56 parity scrub
+(scrub_raid56_parity_stripe(), which runs when the source holds P or Q
+of a full stripe) reads the data stripes of all the other devices
+through the same function, and for RAID56 the next mirror of a data
+stripe is a rebuild of it from P/Q and the other data stripes, which
+reads the source's P, the device the user asked to avoid.
+
+The rebuilt bytes are verified only where the stripe has an extent with
+a csum. Everywhere else the scrub buffer keeps them, and
+scrub_raid56_cached_parity() hands them to the parity rbio as the data,
+so finish_parity_scrub() does not check P/Q against the data on disk:
+
+ - where a sector without an extent was rebuilt from P, the recomputed
+ P equals the on-disk P by construction, so bad P passes the check and
+ is duplicated to the replace target as it is;
+
+ - where another data stripe's sector is bad, the rebuilt sectors carry
+ that damage, the recomputed P (P ^ bad ^ good) differs from the
+ on-disk P and is written to the source and the target, baking the bad
+ data into parity: the bad sector, recoverable before the replace, is
+ lost.
+
+Apply the AVOID mode only to the stripes on the source device. A
+missing device is still read through the next mirror, whichever device
+it is.
+
+The parity scrub has read the other devices' data stripes this way since
+1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q
+scrub"), and has used the scrub buffers as the parity rbio's data since
+94ead93e6375 ("btrfs: scrub: use recovered data stripes as cache to
+avoid unnecessary read").
+
+In the test described in "btrfs: scrub: copy every sector of raid56 data
+stripes to the replace target", replaces with -r recomputed 184-362
+parity sectors over another device's bad data and copied about twice as
+many bad parity sectors verbatim to the target as replaces without -r
+(1453-1600 instead of 623-712). With this change -r recomputes none
+over bad data and copies exactly as much bad parity as a replace
+without -r.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 17 +++++++++++++----
+ 1 file changed, 13 insertions(+), 4 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index f064acbd7a8ef..c547379692ac5 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -1886,12 +1886,21 @@ static void scrub_submit_initial_read(struct scrub_ctx *sctx,
+ atomic_inc(&stripe->pending_io);
+
+ /*
+- * For dev-replace, either user asks to avoid the source dev, or
+- * the device is missing, we try the next mirror instead.
++ * For dev-replace, either user asks to avoid the source dev and this
++ * stripe is on it, or the device is missing, we try the next mirror
++ * instead.
++ *
++ * The RAID56 parity scrub reads the data stripes of the other devices
++ * here too. Those must be read directly: for RAID56 the next mirror
++ * is a rebuild from the parity that is about to be checked, and the
++ * data sectors without an extent are not verified, so a rebuild would
++ * make the check pass on bad parity, or write parity computed from
++ * another stripe's bad data.
+ */
+ if (sctx->is_dev_replace &&
+- (fs_info->dev_replace.cont_reading_from_srcdev_mode ==
+- BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID ||
++ ((fs_info->dev_replace.cont_reading_from_srcdev_mode ==
++ BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID &&
++ stripe->dev == fs_info->dev_replace.srcdev) ||
+ !stripe->dev->bdev)) {
+ int num_copies = btrfs_num_copies(fs_info, stripe->bg->start,
+ stripe->bg->length);
+--
+2.47.3
+
+++ /dev/null
-From 979b9e694a567841b7acdb09358c7e056f0325ac Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 16 Oct 2026 20:33:38 -0400
-Subject: [PATCH 06/13] btrfs: scrub: only avoid the replace source device for
- its own stripes
-To: linux-btrfs@vger.kernel.org
-
-With cont_reading_from_srcdev_mode AVOID (btrfs replace start -r),
-scrub_submit_initial_read() reads a stripe through the next mirror
-instead of directly. In the data path that is right: the stripes there
-are on the source device. But the RAID56 parity scrub
-(scrub_raid56_parity_stripe(), which runs when the source holds P or Q
-of a full stripe) reads the data stripes of all the other devices
-through the same function, and for RAID56 the next mirror of a data
-stripe is a rebuild of it from P/Q and the other data stripes, which
-reads the source's P, the device the user asked to avoid.
-
-The rebuilt bytes are verified only where the stripe has an extent with
-a csum. Everywhere else the scrub buffer keeps them, and
-scrub_raid56_cached_parity() hands them to the parity rbio as the data,
-so finish_parity_scrub() does not check P/Q against the data on disk:
-
- - where a sector without an extent was rebuilt from P, the recomputed
- P equals the on-disk P by construction, so bad P passes the check and
- is duplicated to the replace target as it is;
-
- - where another data stripe's sector is bad, the rebuilt sectors carry
- that damage, the recomputed P (P ^ bad ^ good) differs from the
- on-disk P and is written to the source and the target, baking the bad
- data into parity: the bad sector, recoverable before the replace, is
- lost.
-
-Apply the AVOID mode only to the stripes on the source device. A
-missing device is still read through the next mirror, whichever device
-it is.
-
-The parity scrub has read the other devices' data stripes this way since
-1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q
-scrub"), and has used the scrub buffers as the parity rbio's data since
-94ead93e6375 ("btrfs: scrub: use recovered data stripes as cache to
-avoid unnecessary read").
-
-In the test described in "btrfs: scrub: copy every sector of raid56 data
-stripes to the replace target", replaces with -r recomputed 184-362
-parity sectors over another device's bad data and copied about twice as
-many bad parity sectors verbatim to the target as replaces without -r
-(1453-1600 instead of 623-712). With this change -r recomputes none
-over bad data and copies exactly as much bad parity as a replace
-without -r.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 17 +++++++++++++----
- 1 file changed, 13 insertions(+), 4 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index fbef0eec7f41d..6d6de0c55beb6 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -1871,12 +1871,21 @@ static void scrub_submit_initial_read(struct scrub_ctx *sctx,
- atomic_inc(&stripe->pending_io);
-
- /*
-- * For dev-replace, either user asks to avoid the source dev, or
-- * the device is missing, we try the next mirror instead.
-+ * For dev-replace, either user asks to avoid the source dev and this
-+ * stripe is on it, or the device is missing, we try the next mirror
-+ * instead.
-+ *
-+ * The RAID56 parity scrub reads the data stripes of the other devices
-+ * here too. Those must be read directly: for RAID56 the next mirror
-+ * is a rebuild from the parity that is about to be checked, and the
-+ * data sectors without an extent are not verified, so a rebuild would
-+ * make the check pass on bad parity, or write parity computed from
-+ * another stripe's bad data.
- */
- if (sctx->is_dev_replace &&
-- (fs_info->dev_replace.cont_reading_from_srcdev_mode ==
-- BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID ||
-+ ((fs_info->dev_replace.cont_reading_from_srcdev_mode ==
-+ BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID &&
-+ stripe->dev == fs_info->dev_replace.srcdev) ||
- !stripe->dev->bdev)) {
- int num_copies = btrfs_num_copies(fs_info, stripe->bg->start,
- stripe->bg->length);
---
-2.47.3
-
--- /dev/null
+From 7105ab505bd11a8cd4f75957efee33652ea27cc7 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Fri, 16 Oct 2026 21:06:45 -0400
+Subject: [PATCH 06/12] btrfs: scrub: read raid56 sectors without an extent
+ from the replace source
+To: linux-btrfs@vger.kernel.org
+
+With -r (cont_reading_from_srcdev_mode AVOID), dev-replace reads the
+data stripes of the source device through the next mirror, which for
+RAID56 is a rebuild from the other stripes of the row. Where the stripe
+has an extent, the rebuilt bytes are checked against the csum, and if
+they are wrong the repair reads the source after all. "btrfs: scrub:
+copy every sector of raid56 data stripes to the replace target" also
+copies the sectors without an extent, and nothing checks their rebuild:
+if another stripe of the row is bad at that sector, the rebuild carries
+the damage, the target's sector no longer matches what P/Q was computed
+over, and the other device's bad sector, recoverable before the replace,
+is lost.
+
+Read those sectors from the source when it is present, which keeps every
+row exactly as recoverable as it was on the source, and keep the rebuilt
+bytes only where that read fails or the source is missing. This reads
+the source for sectors that hold no data although the user asked to
+avoid it, but -r is documented as reading the source only when no other
+zero-defect mirror exists, and the rebuild of a sector without a csum
+cannot be shown to be one.
+
+It is a separate change so it can be dropped if reading the source here
+is not wanted; without it, a replace with -r can lose blocks that were
+recoverable before it.
+
+In the test described in "btrfs: scrub: copy every sector of raid56 data
+stripes to the replace target", replaces with -r lost 682-878
+blocks that were recoverable before the replace, and left 1000-1150
+target sectors holding rebuilt bytes that carried another device's
+damage. With this change they lose none, like replaces without -r.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 49 insertions(+), 1 deletion(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index c547379692ac5..9fe5c83c8273a 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2024,6 +2024,49 @@ static unsigned long scrub_raid56_unused_sectors(struct scrub_stripe *stripe)
+ return unused;
+ }
+
++/*
++ * Dev-replace on RAID56 avoiding the source device (-r): the stripe buffer
++ * holds the source's data stripe rebuilt from the other stripes. Where the
++ * stripe has an extent the rebuild is verified and replaced by the source's
++ * bytes if wrong, but nothing can verify it where there is no extent, and if
++ * another stripe of the row is bad there, the rebuild carries that damage:
++ * copied to the target, it would make the bad sector unrecoverable. The
++ * source's bytes keep the row as recoverable as it was, so read the sectors
++ * without an extent from the source after all, and keep the rebuilt bytes
++ * only where that read fails.
++ */
++static void scrub_raid56_read_unused_from_srcdev(struct scrub_stripe *stripe)
++{
++ struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
++ const unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
++ unsigned long unused = 0;
++ unsigned long has_extent = scrub_bitmap_read_has_extent(stripe);
++ unsigned int start, end;
++ void *buf;
++
++ bitmap_set(&unused, 0, nr_sectors);
++ bitmap_andnot(&unused, &unused, &has_extent, nr_sectors);
++ if (bitmap_empty(&unused, nr_sectors))
++ return;
++ buf = kmalloc(BTRFS_STRIPE_LEN, GFP_NOFS);
++ if (!buf)
++ return;
++ btrfs_bio_counter_inc_blocked(fs_info);
++ for_each_set_bitrange(start, end, &unused, nr_sectors) {
++ const u32 off = start << fs_info->sectorsize_bits;
++ const u32 len = (end - start) << fs_info->sectorsize_bits;
++
++ if (bdev_rw_virt(stripe->dev->bdev,
++ (stripe->physical + off) >> SECTOR_SHIFT, buf,
++ len, REQ_OP_READ))
++ continue;
++ memcpy(stripe->buffer + off, buf, len);
++ scrub_bitmap_clear_io_error(stripe, start, end - start);
++ }
++ btrfs_bio_counter_dec(fs_info);
++ kfree(buf);
++}
++
+ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+ {
+ struct btrfs_fs_info *fs_info = sctx->fs_info;
+@@ -2074,8 +2117,13 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+ has_extent = scrub_bitmap_read_has_extent(stripe);
+ error = scrub_bitmap_read_error(stripe);
+ bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
+- if (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)
++ if (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) {
++ if (fs_info->dev_replace.cont_reading_from_srcdev_mode ==
++ BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID &&
++ stripe->dev->bdev)
++ scrub_raid56_read_unused_from_srcdev(stripe);
+ good |= scrub_raid56_unused_sectors(stripe);
++ }
+ scrub_write_sectors(sctx, stripe, good, true);
+ scrub_raid56_copy_bad_sectors(sctx, stripe,
+ error & has_extent);
+--
+2.47.3
+
--- /dev/null
+From 9ed90b2065e4fbdc968ccb96244178ef22c461b8 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 3 Jul 2024 21:00:18 -0400
+Subject: [PATCH 07/12] btrfs: don't abort raid56 data scrub on first
+ uncorrectable sector
+To: linux-btrfs@vger.kernel.org
+
+In commit 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement
+RAID56 P/Q scrub") a new function scrub_raid56_parity_stripe() was
+introduced to recalculate the parity stripe after correcting any
+correctable errors. When it detected unrepaired sectors in a data
+stripe, it returned -EIO, which propagated up the stack through
+scrub_stripe, scrub_chunk, and scrub_enumerate_chunks, where an error
+makes the scrub of that device break out of its loop early and return
+the error to userspace. Every device holding P or Q for an affected
+full stripe stops there, and parity rotates, so a few bad full stripes
+stop the scrub of most of the array.
+
+That was a regression: uncorrectable data blocks are one of the
+expected possible events that occur during a scrub, so scrub should
+continue until it has counted and reported all of the uncorrectable
+stripes in the filesystem. Perhaps more importantly, scrub should fix
+up any correctable errors that might exist in other stripes beyond the
+first uncorrectable stripe. No other profile does this: their scrubs
+count uncorrectable sectors, report them and carry on, returning 0.
+Errors from this function are only appropriate when scrub cannot do its
+job at all: unable to read csums, unable to map an extent's data
+blocks, or out of memory.
+
+Since commit fab0c0f03cfd ("btrfs: introduce BTRFS_PATH_AUTO_RELEASE()
+helper") the bug had changed shape: ret no longer held -EIO at that
+point but the leftover return value of the last
+scrub_find_fill_first_stripe() call, 0 or 1. 1 made scrub_stripe()
+silently stop scrubbing the rest of the block group on that device, and
+0 let the scrub continue only by accident, until "btrfs: scrub: fix lost
+error return value when scrubbing raid56 parity stripe" restored the
+-EIO.
+
+scrub_raid56_parity_stripe() has successfully completed its task once it
+has performed its data correction and verification steps and checked P/Q
+of the rows without unrepaired sectors. Return 0 at that point,
+regardless of the outcome of the verification. P/Q of the rows with
+unrepaired sectors is still not regenerated, so no garbage is written
+back to the devices, and during dev-replace their original P/Q is copied
+to the target ("btrfs: scrub: copy raid56 parity of unrepairable rows to
+the replace target"), so a replace that now carries on past them does
+not lose their redundancy. The unrepaired sectors are logged, and
+counted in the scrub statistics (and, since v6.16, the device stats)
+when their own data device is scrubbed; they are not reported through
+the return code of the scrub ioctl.
+
+Fixes: 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
+Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+---
+ fs/btrfs/scrub.c | 16 +++++-----------
+ 1 file changed, 5 insertions(+), 11 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 9fe5c83c8273a..89067b08106d2 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2536,18 +2536,12 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ * check and regenerate the rest.
+ */
+ bitmap_andnot(&extent_bitmap, &extent_bitmap, &bad_rows, nr_sectors);
+- if (!bitmap_empty(&extent_bitmap, nr_sectors)) {
+- /* Now we can check and regenerate the P/Q stripe. */
+- ret = scrub_raid56_cached_parity(sctx, scrub_dev, map,
+- full_stripe_start, &extent_bitmap);
+- if (ret)
+- return ret;
+- }
++ if (bitmap_empty(&extent_bitmap, nr_sectors))
++ return 0;
+
+- /* The unrepaired data sectors still fail the scrub. */
+- if (!bitmap_empty(&bad_rows, nr_sectors))
+- return -EIO;
+- return 0;
++ /* Now we can check and regenerate the P/Q stripe. */
++ return scrub_raid56_cached_parity(sctx, scrub_dev, map, full_stripe_start,
++ &extent_bitmap);
+ }
+
+ /*
+--
+2.47.3
+
+++ /dev/null
-From 31a9785c46bf8c3c7c66b1c0dc40b42511ce5923 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 16 Oct 2026 21:06:45 -0400
-Subject: [PATCH 07/13] btrfs: scrub: read raid56 sectors without an extent
- from the replace source
-To: linux-btrfs@vger.kernel.org
-
-With -r (cont_reading_from_srcdev_mode AVOID), dev-replace reads the
-data stripes of the source device through the next mirror, which for
-RAID56 is a rebuild from the other stripes of the row. Where the stripe
-has an extent, the rebuilt bytes are checked against the csum, and if
-they are wrong the repair reads the source after all. "btrfs: scrub:
-copy every sector of raid56 data stripes to the replace target" also
-copies the sectors without an extent, and nothing checks their rebuild:
-if another stripe of the row is bad at that sector, the rebuild carries
-the damage, the target's sector no longer matches what P/Q was computed
-over, and the other device's bad sector, recoverable before the replace,
-is lost.
-
-Read those sectors from the source when it is present, which keeps every
-row exactly as recoverable as it was on the source, and keep the rebuilt
-bytes only where that read fails or the source is missing. This reads
-the source for sectors that hold no data although the user asked to
-avoid it, but -r is documented as reading the source only when no other
-zero-defect mirror exists, and the rebuild of a sector without a csum
-cannot be shown to be one.
-
-It is a separate change so it can be dropped if reading the source here
-is not wanted; without it, a replace with -r can lose blocks that were
-recoverable before it.
-
-In the test described in "btrfs: scrub: copy every sector of raid56 data
-stripes to the replace target", replaces with -r lost 682-878
-blocks that were recoverable before the replace, and left 1000-1150
-target sectors holding rebuilt bytes that carried another device's
-damage. With this change they lose none, like replaces without -r.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
- 1 file changed, 49 insertions(+), 1 deletion(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 6d6de0c55beb6..200fc471748df 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2008,6 +2008,49 @@ static unsigned long scrub_raid56_unused_sectors(struct scrub_stripe *stripe)
- return unused;
- }
-
-+/*
-+ * Dev-replace on RAID56 avoiding the source device (-r): the stripe buffer
-+ * holds the source's data stripe rebuilt from the other stripes. Where the
-+ * stripe has an extent the rebuild is verified and replaced by the source's
-+ * bytes if wrong, but nothing can verify it where there is no extent, and if
-+ * another stripe of the row is bad there, the rebuild carries that damage:
-+ * copied to the target, it would make the bad sector unrecoverable. The
-+ * source's bytes keep the row as recoverable as it was, so read the sectors
-+ * without an extent from the source after all, and keep the rebuilt bytes
-+ * only where that read fails.
-+ */
-+static void scrub_raid56_read_unused_from_srcdev(struct scrub_stripe *stripe)
-+{
-+ struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
-+ const unsigned int nr_sectors = stripe_length(stripe) >> fs_info->sectorsize_bits;
-+ unsigned long unused = 0;
-+ unsigned long has_extent = scrub_bitmap_read_has_extent(stripe);
-+ unsigned int start, end;
-+ void *buf;
-+
-+ bitmap_set(&unused, 0, nr_sectors);
-+ bitmap_andnot(&unused, &unused, &has_extent, nr_sectors);
-+ if (bitmap_empty(&unused, nr_sectors))
-+ return;
-+ buf = kmalloc(BTRFS_STRIPE_LEN, GFP_NOFS);
-+ if (!buf)
-+ return;
-+ btrfs_bio_counter_inc_blocked(fs_info);
-+ for_each_set_bitrange(start, end, &unused, nr_sectors) {
-+ const u32 off = start << fs_info->sectorsize_bits;
-+ const u32 len = (end - start) << fs_info->sectorsize_bits;
-+
-+ if (bdev_rw_virt(stripe->dev->bdev,
-+ (stripe->physical + off) >> SECTOR_SHIFT, buf,
-+ len, REQ_OP_READ))
-+ continue;
-+ memcpy(stripe->buffer + off, buf, len);
-+ scrub_bitmap_clear_io_error(stripe, start, end - start);
-+ }
-+ btrfs_bio_counter_dec(fs_info);
-+ kfree(buf);
-+}
-+
- static int flush_scrub_stripes(struct scrub_ctx *sctx)
- {
- struct btrfs_fs_info *fs_info = sctx->fs_info;
-@@ -2058,8 +2101,13 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
- has_extent = scrub_bitmap_read_has_extent(stripe);
- error = scrub_bitmap_read_error(stripe);
- bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
-- if (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)
-+ if (stripe->bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) {
-+ if (fs_info->dev_replace.cont_reading_from_srcdev_mode ==
-+ BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID &&
-+ stripe->dev->bdev)
-+ scrub_raid56_read_unused_from_srcdev(stripe);
- good |= scrub_raid56_unused_sectors(stripe);
-+ }
- scrub_write_sectors(sctx, stripe, good, true);
- scrub_raid56_copy_bad_sectors(sctx, stripe,
- error & has_extent);
---
-2.47.3
-
+++ /dev/null
-From 336c48ef59723ac8e1d01abf1e9076a369d685ef Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Wed, 3 Jul 2024 21:00:18 -0400
-Subject: [PATCH 08/13] btrfs: don't abort raid56 data scrub on first
- uncorrectable sector
-To: linux-btrfs@vger.kernel.org
-
-In commit 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement
-RAID56 P/Q scrub") a new function scrub_raid56_parity_stripe() was
-introduced to recalculate the parity stripe after correcting any
-correctable errors. When it detected unrepaired sectors in a data
-stripe, it returned -EIO, which propagated up the stack through
-scrub_stripe, scrub_chunk, and scrub_enumerate_chunks, where an error
-makes the scrub of that device break out of its loop early and return
-the error to userspace. Every device holding P or Q for an affected
-full stripe stops there, and parity rotates, so a few bad full stripes
-stop the scrub of most of the array.
-
-That was a regression: uncorrectable data blocks are one of the
-expected possible events that occur during a scrub, so scrub should
-continue until it has counted and reported all of the uncorrectable
-stripes in the filesystem. Perhaps more importantly, scrub should fix
-up any correctable errors that might exist in other stripes beyond the
-first uncorrectable stripe. No other profile does this: their scrubs
-count uncorrectable sectors, report them and carry on, returning 0.
-Errors from this function are only appropriate when scrub cannot do its
-job at all: unable to read csums, unable to map an extent's data
-blocks, or out of memory.
-
-Since commit fab0c0f03cfd ("btrfs: introduce BTRFS_PATH_AUTO_RELEASE()
-helper") the bug had changed shape: ret no longer held -EIO at that
-point but the leftover return value of the last
-scrub_find_fill_first_stripe() call, 0 or 1. 1 made scrub_stripe()
-silently stop scrubbing the rest of the block group on that device, and
-0 let the scrub continue only by accident, until "btrfs: scrub: fix lost
-error return value when scrubbing raid56 parity stripe" restored the
--EIO.
-
-scrub_raid56_parity_stripe() has successfully completed its task once it
-has performed its data correction and verification steps and checked P/Q
-of the rows without unrepaired sectors. Return 0 at that point,
-regardless of the outcome of the verification. P/Q of the rows with
-unrepaired sectors is still not regenerated, so no garbage is written
-back to the devices, and during dev-replace their original P/Q is copied
-to the target ("btrfs: scrub: copy raid56 parity of unrepairable rows to
-the replace target"), so a replace that now carries on past them does
-not lose their redundancy. The unrepaired sectors are logged, and
-counted in the scrub statistics (and, since v6.16, the device stats)
-when their own data device is scrubbed; they are not reported through
-the return code of the scrub ioctl.
-
-Fixes: 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
----
- fs/btrfs/scrub.c | 16 +++++-----------
- 1 file changed, 5 insertions(+), 11 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 200fc471748df..02c015d9f09e4 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2517,18 +2517,12 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- * check and regenerate the rest.
- */
- bitmap_andnot(&extent_bitmap, &extent_bitmap, &bad_rows, nr_sectors);
-- if (!bitmap_empty(&extent_bitmap, nr_sectors)) {
-- /* Now we can check and regenerate the P/Q stripe. */
-- ret = scrub_raid56_cached_parity(sctx, scrub_dev, map,
-- full_stripe_start, &extent_bitmap);
-- if (ret)
-- return ret;
-- }
-+ if (bitmap_empty(&extent_bitmap, nr_sectors))
-+ return 0;
-
-- /* The unrepaired data sectors still fail the scrub. */
-- if (!bitmap_empty(&bad_rows, nr_sectors))
-- return -EIO;
-- return 0;
-+ /* Now we can check and regenerate the P/Q stripe. */
-+ return scrub_raid56_cached_parity(sctx, scrub_dev, map, full_stripe_start,
-+ &extent_bitmap);
- }
-
- /*
---
-2.47.3
-
--- /dev/null
+From 86ab0366dc0e9d21fe74fde137cd51d87ddc0e4a Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 21 Oct 2026 03:59:11 -0400
+Subject: [PATCH 08/12] btrfs: scrub: do not write raid56 parity in a read-only
+ scrub
+To: linux-btrfs@vger.kernel.org
+
+A read-only scrub (btrfs scrub start -r) must not write to the devices.
+The data stripes honour that: their repairs are only written back when
+the scrub is not read-only. The raid56 parity scrub never looks at it:
+finish_parity_scrub() rewrites every P or Q sector that does not match
+the data, whatever the scrub's mode. So a read-only scrub of a raid56
+filesystem with stale or damaged parity rewrites it.
+
+Tell the parity scrub rbio whether the scrub is read-only, and in that
+case stop after the check, before any write is built.
+
+Test (raid56-wh-harness scrub-blame-test.sh SB_RO=1: read-only mount,
+scrub -r): with 8 damaged data sectors (every order) or 8 damaged parity
+sectors on one raid5/raid6 member, every member image is byte-identical
+after the scrub, and the damage is still counted. Before: with damaged
+parity, the scrub rewrote it, and a member image changed.
+
+Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/raid56.c | 8 +++++++-
+ fs/btrfs/raid56.h | 6 +++++-
+ fs/btrfs/scrub.c | 3 ++-
+ 3 files changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 59aad807f98ab..58f4e05561e6f 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2574,7 +2574,8 @@ static void rmw_rbio_work_locked(struct work_struct *work)
+ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+ struct btrfs_io_context *bioc,
+ struct btrfs_device *scrub_dev,
+- unsigned long *dbitmap, int stripe_nsectors)
++ unsigned long *dbitmap, int stripe_nsectors,
++ bool readonly)
+ {
+ struct btrfs_fs_info *fs_info = bioc->fs_info;
+ struct btrfs_raid_bio *rbio;
+@@ -2605,6 +2606,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+ ASSERT_RBIO_STRIPE(i < rbio->real_stripes, rbio, i);
+
+ bitmap_copy(&rbio->dbitmap, dbitmap, stripe_nsectors);
++ rbio->scrub_readonly = readonly;
+ return rbio;
+ }
+
+@@ -2780,6 +2782,10 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ q_paddr = INVALID_PADDR;
+ }
+
++ /* A read-only scrub only checks: submit no write. */
++ if (rbio->scrub_readonly)
++ goto submit_write;
++
+ /*
+ * time to start writing. Make bios for everything from the
+ * higher layers (the bio_list in our rbio) and our p/q. Ignore
+diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
+index 8700910b8dc99..d213ddcb102dc 100644
+--- a/fs/btrfs/raid56.h
++++ b/fs/btrfs/raid56.h
+@@ -165,6 +165,9 @@ struct btrfs_raid_bio {
+ /* Stripe number that we're scrubbing */
+ u8 scrubp;
+
++ /* Parity scrub of a read-only scrub: check, but write nothing. */
++ bool scrub_readonly;
++
+ /*
+ * Size of all the bios in the bio_list. This helps us decide if the
+ * rbio maps to a full stripe or not.
+@@ -274,7 +277,8 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc);
+ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+ struct btrfs_io_context *bioc,
+ struct btrfs_device *scrub_dev,
+- unsigned long *dbitmap, int stripe_nsectors);
++ unsigned long *dbitmap, int stripe_nsectors,
++ bool readonly);
+ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
+
+ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 89067b08106d2..e1544cf597957 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2310,7 +2310,8 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
+ /* For RAID56 write there must be an @bioc allocated. */
+ ASSERT(bioc);
+ rbio = raid56_parity_alloc_scrub_rbio(&bio, bioc, scrub_dev, extent_bitmap,
+- map->stripe_len >> fs_info->sectorsize_bits);
++ map->stripe_len >> fs_info->sectorsize_bits,
++ sctx->readonly);
+ btrfs_put_bioc(bioc);
+ if (!rbio) {
+ ret = -ENOMEM;
+--
+2.47.3
+
+++ /dev/null
-From d67280810713477185cf1dae7e72d5fe91300be1 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Wed, 21 Oct 2026 03:59:11 -0400
-Subject: [PATCH 09/13] btrfs: scrub: do not write raid56 parity in a read-only
- scrub
-To: linux-btrfs@vger.kernel.org
-
-A read-only scrub (btrfs scrub start -r) must not write to the devices.
-The data stripes honour that: their repairs are only written back when
-the scrub is not read-only. The raid56 parity scrub never looks at it:
-finish_parity_scrub() rewrites every P or Q sector that does not match
-the data, whatever the scrub's mode. So a read-only scrub of a raid56
-filesystem with stale or damaged parity rewrites it.
-
-Tell the parity scrub rbio whether the scrub is read-only, and in that
-case stop after the check, before any write is built.
-
-Test (raid56-wh-harness scrub-blame-test.sh SB_RO=1: read-only mount,
-scrub -r): with 8 damaged data sectors (every order) or 8 damaged parity
-sectors on one raid5/raid6 member, every member image is byte-identical
-after the scrub, and the damage is still counted. Before: with damaged
-parity, the scrub rewrote it, and a member image changed.
-
-Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/raid56.c | 8 +++++++-
- fs/btrfs/raid56.h | 6 +++++-
- fs/btrfs/scrub.c | 3 ++-
- 3 files changed, 14 insertions(+), 3 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5ec31299f1c30..637be11a1ab4a 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -2557,7 +2557,8 @@ static void rmw_rbio_work_locked(struct work_struct *work)
- struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
- struct btrfs_io_context *bioc,
- struct btrfs_device *scrub_dev,
-- unsigned long *dbitmap, int stripe_nsectors)
-+ unsigned long *dbitmap, int stripe_nsectors,
-+ bool readonly)
- {
- struct btrfs_fs_info *fs_info = bioc->fs_info;
- struct btrfs_raid_bio *rbio;
-@@ -2588,6 +2589,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
- ASSERT_RBIO_STRIPE(i < rbio->real_stripes, rbio, i);
-
- bitmap_copy(&rbio->dbitmap, dbitmap, stripe_nsectors);
-+ rbio->scrub_readonly = readonly;
- return rbio;
- }
-
-@@ -2770,6 +2772,10 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
- q_paddr = INVALID_PADDR;
- }
-
-+ /* A read-only scrub only checks: submit no write. */
-+ if (rbio->scrub_readonly)
-+ goto submit_write;
-+
- /*
- * time to start writing. Make bios for everything from the
- * higher layers (the bio_list in our rbio) and our p/q. Ignore
-diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 8542648199f1a..1f68218598072 100644
---- a/fs/btrfs/raid56.h
-+++ b/fs/btrfs/raid56.h
-@@ -170,6 +170,9 @@ struct btrfs_raid_bio {
- /* Stripe number that we're scrubbing */
- u8 scrubp;
-
-+ /* Parity scrub of a read-only scrub: check, but write nothing. */
-+ bool scrub_readonly;
-+
- /*
- * Size of all the bios in the bio_list. This helps us decide if the
- * rbio maps to a full stripe or not.
-@@ -279,7 +282,8 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc);
- struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
- struct btrfs_io_context *bioc,
- struct btrfs_device *scrub_dev,
-- unsigned long *dbitmap, int stripe_nsectors);
-+ unsigned long *dbitmap, int stripe_nsectors,
-+ bool readonly);
- void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
-
- void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 02c015d9f09e4..690c8c9d76b5d 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2294,7 +2294,8 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
- /* For RAID56 write there must be an @bioc allocated. */
- ASSERT(bioc);
- rbio = raid56_parity_alloc_scrub_rbio(&bio, bioc, scrub_dev, extent_bitmap,
-- BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits);
-+ BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits,
-+ sctx->readonly);
- btrfs_put_bioc(bioc);
- if (!rbio) {
- ret = -ENOMEM;
---
-2.47.3
-
--- /dev/null
+From dc2880d0871aa4c790df4a326b0cd904dd039168 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 20 Oct 2026 13:43:04 -0400
+Subject: [PATCH 09/12] btrfs: scrub: rebuild a raid6 data stripe that both P
+ and Q disagree with
+To: linux-btrfs@vger.kernel.org
+
+Scrub checks raid56 parity against the data stripes as they read. Data
+without checksums (nodatasum and nodatacow files) cannot be verified, so
+it is taken as it reads, and when the parity being scrubbed differs,
+finish_parity_scrub() rewrites it from that data.
+
+That is wrong when the data is what is stale. A write that fails on one
+device but succeeds within the profile's tolerance is acked and leaves
+that device's strip with its old contents, while P and Q were written
+from the new data. With the device missing, the new data still rebuilds
+from parity. Scrub then rewrites P and Q from the stale strip, and from
+then on the acked data is gone: with that device missing it rebuilds to
+the old contents.
+
+On RAID6, P and Q together locate one bad stripe without a checksum: if
+data stripe z is off by e, P is off by e and Q by g^z * e, in every
+byte. When both differ from the data in that pattern, rebuild data
+stripe z and write it back instead of rewriting the parity. Two parity
+strips that are stale independently do not fit that pattern by chance
+over a whole sector. Any other difference (P or Q alone, or no single
+z) keeps the parity rewrite. The P and Q devices are scrubbed in
+parallel, each from its own read of the data, so only the scrub of P
+rebuilds; the scrub of Q leaves such a row alone (Q is right). A torn
+write that reached one data stripe but neither P nor Q fits the pattern
+too; the rebuild returns that stripe to its old contents, as valid for
+an unacked write as the new ones. Rows with a read error were rebuilt
+by recover_scrub_rbio() from the parity that is not being scrubbed, and
+are left alone. In a read-only scrub nothing is written (previous
+patch).
+
+RAID5 has a single parity, so it cannot tell a stale data strip from
+stale parity, and is unchanged.
+
+Test (raid56-wh-harness nodatasum-scrub-repair-test.sh): nodatasum files
+on a 5-device raid6, each file written with one member failing writes
+during its writeback (each member in turn; within tolerance, so acked),
+then scrub, then every file read with no member, each member and each
+pair missing. Before: scrub kept the 6 stale data strips and rewrote P
+and Q from them; 64 of 80 reads were wrong afterwards, 20 of them correct
+before the scrub. After: the stale strips are rebuilt, P and Q match the
+data, and 80 of 80 reads are correct, with and without stripe_alloc. Two
+stale strips per row (two members failing) cannot be located and still
+get their parity rewritten, as before.
+
+Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/raid56.c | 195 +++++++++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 177 insertions(+), 18 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 58f4e05561e6f..730fbd5225c1e 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -9,6 +9,7 @@
+ #include <linux/slab.h>
+ #include <linux/blkdev.h>
+ #include <linux/raid/pq.h>
++#include <linux/raid/pq_tables.h>
+ #include <linux/hash.h>
+ #include <linux/list_sort.h>
+ #include <linux/raid/xor.h>
+@@ -2653,16 +2654,13 @@ static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio)
+ return 0;
+ }
+
+-/* Return true if the content of the step matches the calculated one. */
+-static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
+- void *pointers[], unsigned int sector_nr,
+- unsigned int step_nr)
++/* Calculate P (and Q) of one step into the temporary pages in @pointers. */
++static void gen_one_parity_step(struct btrfs_raid_bio *rbio, void *pointers[],
++ unsigned int sector_nr, unsigned int step_nr)
+ {
+ const unsigned int nr_data = rbio->nr_data;
+ const bool has_qstripe = (rbio->real_stripes - rbio->nr_data == 2);
+ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
+- void *parity;
+- bool ret = false;
+
+ ASSERT(step_nr < rbio->sector_nsteps);
+
+@@ -2682,36 +2680,159 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
+ xor_gen(pointers[nr_data], pointers + 1, nr_data - 1, step);
+ }
+
++ for (int stripe = nr_data - 1; stripe >= 0; stripe--)
++ kunmap_local(pointers[stripe]);
++}
++
++/*
++ * Return true if the content of the step matches the calculated one. If not
++ * and @repair is set, replace it with the calculated one.
++ */
++static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
++ void *pointers[], unsigned int sector_nr,
++ unsigned int step_nr, bool repair)
++{
++ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
++ void *parity;
++ bool ret = false;
++
++ gen_one_parity_step(rbio, pointers, sector_nr, step_nr);
++
+ /* Check scrubbing parity and repair it. */
+ parity = kmap_local_paddr(rbio_stripe_paddr(rbio, rbio->scrubp, sector_nr, step_nr));
+- if (memcmp(parity, pointers[rbio->scrubp], step) != 0)
+- memcpy(parity, pointers[rbio->scrubp], step);
+- else
++ if (memcmp(parity, pointers[rbio->scrubp], step) != 0) {
++ if (repair)
++ memcpy(parity, pointers[rbio->scrubp], step);
++ } else {
+ ret = true;
++ }
+ kunmap_local(parity);
+-
+- for (int stripe = nr_data - 1; stripe >= 0; stripe--)
+- kunmap_local(pointers[stripe]);
+ return ret;
+ }
+
++/*
++ * RAID6: find the one data stripe that explains why P and Q of @sector_nr
++ * both differ from the ones calculated from the data.
++ *
++ * If data stripe z is off by e, P is off by e and Q by g^z * e, in every
++ * byte. Return z if every differing byte of the sector shows that pattern
++ * with the same z, or -1 if it does not (P or Q alone is off, or more than
++ * one stripe is).
++ */
++static int raid6_locate_bad_data(struct btrfs_raid_bio *rbio, void *pointers[],
++ unsigned int sector_nr)
++{
++ const int nr_data = rbio->nr_data;
++ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
++ const u8 *p_calc = pointers[nr_data];
++ const u8 *q_calc = pointers[rbio->real_stripes - 1];
++ int bad = -1;
++
++ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++) {
++ const u8 *p;
++ const u8 *q;
++
++ gen_one_parity_step(rbio, pointers, sector_nr, step_nr);
++ p = kmap_local_paddr(rbio_pstripe_paddr(rbio, sector_nr, step_nr));
++ q = kmap_local_paddr(rbio_qstripe_paddr(rbio, sector_nr, step_nr));
++ for (u32 i = 0; i < step; i++) {
++ const u8 dp = p[i] ^ p_calc[i];
++ const u8 dq = q[i] ^ q_calc[i];
++ int z;
++
++ if (!dp && !dq)
++ continue;
++ if (!dp || !dq) {
++ bad = -2;
++ break;
++ }
++ z = (raid6_gflog[dq] + 255 - raid6_gflog[dp]) % 255;
++ if (z >= nr_data || (bad >= 0 && z != bad)) {
++ bad = -2;
++ break;
++ }
++ bad = z;
++ }
++ kunmap_local(q);
++ kunmap_local(p);
++ if (bad == -2)
++ break;
++ }
++ return bad < 0 ? -1 : bad;
++}
++
++/* Rebuild data stripe @stripe of @sector_nr: it is off by P ^ calculated P. */
++static void raid6_rebuild_data_sector(struct btrfs_raid_bio *rbio, void *pointers[],
++ unsigned int sector_nr, int stripe)
++{
++ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
++
++ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++) {
++ void *srcs[2];
++ void *data;
++
++ gen_one_parity_step(rbio, pointers, sector_nr, step_nr);
++ data = kmap_local_paddr(rbio_stripe_paddr(rbio, stripe, sector_nr, step_nr));
++ srcs[0] = kmap_local_paddr(rbio_pstripe_paddr(rbio, sector_nr, step_nr));
++ srcs[1] = pointers[rbio->nr_data];
++ xor_gen(data, srcs, 2, step);
++ kunmap_local(srcs[0]);
++ kunmap_local(data);
++ }
++}
++
+ /*
+ * The @pointers array should have the P/Q parity already mapped.
++ *
++ * Return the data stripe that was rebuilt instead of rewriting the parity,
++ * or -1.
+ */
+-static void verify_one_parity_sector(struct btrfs_raid_bio *rbio,
+- void *pointers[], unsigned int sector_nr)
++static int verify_one_parity_sector(struct btrfs_raid_bio *rbio,
++ void *pointers[], unsigned int sector_nr,
++ bool can_locate)
+ {
++ const bool has_qstripe = (rbio->real_stripes - rbio->nr_data == 2);
+ bool found_error = false;
+
+ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++) {
+ bool match;
+
+- match = verify_one_parity_step(rbio, pointers, sector_nr, step_nr);
++ match = verify_one_parity_step(rbio, pointers, sector_nr, step_nr, false);
+ if (!match)
+ found_error = true;
+ }
+- if (!found_error)
++ if (!found_error) {
+ bitmap_clear(&rbio->dbitmap, sector_nr, 1);
++ return -1;
++ }
++
++ /*
++ * Data without a checksum is taken as it was read, so parity
++ * calculated from it is not necessarily right: one data stripe may be
++ * stale, e.g. after a write that failed on its device but succeeded on
++ * the others. On RAID6, P and Q together tell which one, so rebuild
++ * that data stripe instead of rewriting the parity from it.
++ */
++ if (has_qstripe && can_locate) {
++ const int bad = raid6_locate_bad_data(rbio, pointers, sector_nr);
++
++ if (bad >= 0) {
++ /*
++ * P and Q are scrubbed in parallel, each with its own
++ * read of the data: leave the rebuild to the scrub of P,
++ * so it is done and counted once. Q is right.
++ */
++ bitmap_clear(&rbio->dbitmap, sector_nr, 1);
++ if (rbio->scrubp != rbio->nr_data)
++ return -1;
++ raid6_rebuild_data_sector(rbio, pointers, sector_nr, bad);
++ return bad;
++ }
++ }
++
++ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++)
++ verify_one_parity_step(rbio, pointers, sector_nr, step_nr, true);
++ return -1;
+ }
+
+ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2727,6 +2848,9 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ phys_addr_t q_paddr = INVALID_PADDR;
+ struct bio_list bio_list;
+ bool is_replace = false;
++ unsigned long read_errors = 0;
++ unsigned long rebuilt = 0;
++ u8 rebuilt_stripe[BITS_PER_LONG];
+ int ret;
+
+ bio_list_init(&bio_list);
+@@ -2767,12 +2891,27 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ pointers[rbio->real_stripes - 1] = kmap_local_paddr(q_paddr);
+ }
+
++ /*
++ * Rows with a read error were rebuilt by recover_scrub_rbio(): do not
++ * look for a bad data stripe there.
++ */
++ for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors)
++ if (get_rbio_vertical_errors(rbio, sectornr, NULL, NULL))
++ __set_bit(sectornr, &read_errors);
++
+ bitmap_clear(rbio->error_bitmap, 0, rbio->nr_sectors);
+
+ /* Map the parity stripe just once */
+
+- for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors)
+- verify_one_parity_sector(rbio, pointers, sectornr);
++ for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors) {
++ const int stripe = verify_one_parity_sector(rbio, pointers, sectornr,
++ !test_bit(sectornr, &read_errors));
++
++ if (stripe >= 0) {
++ __set_bit(sectornr, &rebuilt);
++ rebuilt_stripe[sectornr] = stripe;
++ }
++ }
+
+ kunmap_local(pointers[nr_data]);
+ __free_page(phys_to_page(p_paddr));
+@@ -2786,6 +2925,26 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ if (rbio->scrub_readonly)
+ goto submit_write;
+
++ /* Write the data sectors rebuilt from P and Q. */
++ for_each_set_bit(sectornr, &rebuilt, rbio->stripe_nsectors) {
++ const int stripe = rebuilt_stripe[sectornr];
++ const struct btrfs_io_stripe *io_stripe = &bioc->stripes[stripe];
++
++ btrfs_warn_rl(bioc->fs_info,
++"scrub: raid6 data at logical %llu on devid %llu physical %llu did not match P and Q, rebuilt it",
++ bioc->full_stripe_logical +
++ btrfs_stripe_nr_to_offset(stripe, bioc->stripe_len) +
++ ((u64)sectornr << bioc->fs_info->sectorsize_bits),
++ io_stripe->dev->devid,
++ io_stripe->physical +
++ ((u64)sectornr << bioc->fs_info->sectorsize_bits));
++ ret = rbio_add_io_paddrs(rbio, &bio_list,
++ rbio_stripe_paddrs(rbio, stripe, sectornr),
++ stripe, sectornr, REQ_OP_WRITE);
++ if (ret)
++ goto cleanup;
++ }
++
+ /*
+ * time to start writing. Make bios for everything from the
+ * higher layers (the bio_list in our rbio) and our p/q. Ignore
+--
+2.47.3
+
--- /dev/null
+From 0c60a08b66859c207b4c5bca366910ef8334e3bb Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 20 Oct 2026 16:15:58 -0400
+Subject: [PATCH 10/12] btrfs: scrub: count raid56 parity mismatches as
+ corruption errors
+To: linux-btrfs@vger.kernel.org
+
+When scrub finds raid56 parity that does not match the data, it rewrites
+the parity (or, on RAID6, rebuilds the data stripe that P and Q locate),
+but counts nothing: the device stats do not change, and the scrub
+progress, and so `btrfs scrub status`, says "no errors found". A
+corrupted parity strip, a stale data strip, or a write hole is repaired
+or papered over without a trace.
+
+Count every sector that did not match as a corruption error
+(BTRFS_DEV_STAT_CORRUPTION_ERRS) of the device that held the bad copy,
+and add it to the scrub's corrected_errors:
+
+- a data stripe that P and Q located and that was rebuilt: its device;
+- otherwise the parity being scrubbed: its device.
+
+The second case is not always right. Without a checksum on the data and
+without a second parity to locate the error (RAID5, or a RAID6 row that
+the decode cannot place), a mismatch may as well be a corrupt or stale
+data sector that nothing can detect; scrub rewrites the parity from that
+data, and the parity device is charged. Rows whose stripes had a read
+error are not counted again: the read error was.
+
+The device is the one in the scrub rbio's io context at the stripe that
+held the bad copy. During dev-replace the scrubbed parity is the
+source's (the target is only written), so the source is charged.
+
+Test (raid56-wh-harness raid56-devstats-test.sh, arm P): 4 sectors of a
+P strip (on raid6 also 4 of a Q strip, other rows) overwritten, then
+scrub. Before: no counter moved and scrub said "no errors found".
+After: corruption_errs +4 on exactly the corrupted member(s), Corrected
+4 (raid6 8), and a second scrub finds nothing.
+nodatasum-scrub-repair-test.sh, raid6 with one stale member per row:
+every stale sector is charged once, to the member that held it.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/raid56.c | 33 ++++++++++++++++++++++++++++++++-
+ fs/btrfs/raid56.h | 5 ++++-
+ fs/btrfs/scrub.c | 8 +++++++-
+ 3 files changed, 43 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 730fbd5225c1e..37a077b64f99b 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2576,7 +2576,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+ struct btrfs_io_context *bioc,
+ struct btrfs_device *scrub_dev,
+ unsigned long *dbitmap, int stripe_nsectors,
+- bool readonly)
++ bool readonly, u32 *corrected)
+ {
+ struct btrfs_fs_info *fs_info = bioc->fs_info;
+ struct btrfs_raid_bio *rbio;
+@@ -2608,6 +2608,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+
+ bitmap_copy(&rbio->dbitmap, dbitmap, stripe_nsectors);
+ rbio->scrub_readonly = readonly;
++ rbio->scrub_corrected = corrected;
+ return rbio;
+ }
+
+@@ -2835,6 +2836,35 @@ static int verify_one_parity_sector(struct btrfs_raid_bio *rbio,
+ return -1;
+ }
+
++/*
++ * Count each sector that did not match as a corruption error of the device
++ * that held it: the data stripe rebuilt from P and Q, or else the scrubbed
++ * parity, which is rewritten from the data. Without a checksum and without
++ * a decode (RAID5, or a RAID6 row the decode cannot place), the mismatch may
++ * as well be corrupt data that nothing can find; the parity is charged.
++ * Rows with a read error are not counted here: the read error was.
++ */
++static void count_parity_scrub_errors(struct btrfs_raid_bio *rbio,
++ unsigned long read_errors,
++ unsigned long rebuilt,
++ const u8 *rebuilt_stripe)
++{
++ struct btrfs_io_context *bioc = rbio->bioc;
++ unsigned long parity_bad;
++ unsigned int sectornr;
++
++ bitmap_andnot(&parity_bad, &rbio->dbitmap, &read_errors, rbio->stripe_nsectors);
++ for_each_set_bit(sectornr, &rebuilt, rbio->stripe_nsectors)
++ btrfs_dev_stat_inc_and_print(bioc->stripes[rebuilt_stripe[sectornr]].dev,
++ BTRFS_DEV_STAT_CORRUPTION_ERRS);
++ for_each_set_bit(sectornr, &parity_bad, rbio->stripe_nsectors)
++ btrfs_dev_stat_inc_and_print(bioc->stripes[rbio->scrubp].dev,
++ BTRFS_DEV_STAT_CORRUPTION_ERRS);
++ if (rbio->scrub_corrected)
++ *rbio->scrub_corrected += bitmap_weight(&rebuilt, rbio->stripe_nsectors) +
++ bitmap_weight(&parity_bad, rbio->stripe_nsectors);
++}
++
+ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ {
+ struct btrfs_io_context *bioc = rbio->bioc;
+@@ -2912,6 +2942,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ rebuilt_stripe[sectornr] = stripe;
+ }
+ }
++ count_parity_scrub_errors(rbio, read_errors, rebuilt, rebuilt_stripe);
+
+ kunmap_local(pointers[nr_data]);
+ __free_page(phys_to_page(p_paddr));
+diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
+index d213ddcb102dc..2f5c05d5a00a4 100644
+--- a/fs/btrfs/raid56.h
++++ b/fs/btrfs/raid56.h
+@@ -165,6 +165,9 @@ struct btrfs_raid_bio {
+ /* Stripe number that we're scrubbing */
+ u8 scrubp;
+
++ /* Parity scrub: where to add the number of mismatching sectors. */
++ u32 *scrub_corrected;
++
+ /* Parity scrub of a read-only scrub: check, but write nothing. */
+ bool scrub_readonly;
+
+@@ -278,7 +281,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+ struct btrfs_io_context *bioc,
+ struct btrfs_device *scrub_dev,
+ unsigned long *dbitmap, int stripe_nsectors,
+- bool readonly);
++ bool readonly, u32 *corrected);
+ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
+
+ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index e1544cf597957..799e78a892d10 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -2295,6 +2295,7 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
+ struct bio bio;
+ const int data_stripes = nr_data_stripes(map);
+ u64 length = btrfs_stripe_nr_to_offset(data_stripes, map->stripe_len);
++ u32 corrected = 0;
+ int ret;
+
+ bio_init(&bio, NULL, NULL, 0, REQ_OP_READ);
+@@ -2311,7 +2312,7 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
+ ASSERT(bioc);
+ rbio = raid56_parity_alloc_scrub_rbio(&bio, bioc, scrub_dev, extent_bitmap,
+ map->stripe_len >> fs_info->sectorsize_bits,
+- sctx->readonly);
++ sctx->readonly, &corrected);
+ btrfs_put_bioc(bioc);
+ if (!rbio) {
+ ret = -ENOMEM;
+@@ -2327,6 +2328,11 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
+ raid56_parity_submit_scrub_rbio(rbio);
+ wait_for_completion_io(&io_done);
+ ret = blk_status_to_errno(bio.bi_status);
++ if (corrected) {
++ spin_lock(&sctx->stat_lock);
++ sctx->stat.corrected_errors += corrected;
++ spin_unlock(&sctx->stat_lock);
++ }
+ out:
+ btrfs_bio_counter_dec(fs_info);
+ bio_uninit(&bio);
+--
+2.47.3
+
+++ /dev/null
-From 1395225e695d542703268c68a433194058a322de Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 20 Oct 2026 13:43:04 -0400
-Subject: [PATCH 10/13] btrfs: scrub: rebuild a raid6 data stripe that both P
- and Q disagree with
-To: linux-btrfs@vger.kernel.org
-
-Scrub checks raid56 parity against the data stripes as they read. Data
-without checksums (nodatasum and nodatacow files) cannot be verified, so
-it is taken as it reads, and when the parity being scrubbed differs,
-finish_parity_scrub() rewrites it from that data.
-
-That is wrong when the data is what is stale. A write that fails on one
-device but succeeds within the profile's tolerance is acked and leaves
-that device's strip with its old contents, while P and Q were written
-from the new data. With the device missing, the new data still rebuilds
-from parity. Scrub then rewrites P and Q from the stale strip, and from
-then on the acked data is gone: with that device missing it rebuilds to
-the old contents.
-
-On RAID6, P and Q together locate one bad stripe without a checksum: if
-data stripe z is off by e, P is off by e and Q by g^z * e, in every
-byte. When both differ from the data in that pattern, rebuild data
-stripe z and write it back instead of rewriting the parity. Two parity
-strips that are stale independently do not fit that pattern by chance
-over a whole sector. Any other difference (P or Q alone, or no single
-z) keeps the parity rewrite. The P and Q devices are scrubbed in
-parallel, each from its own read of the data, so only the scrub of P
-rebuilds; the scrub of Q leaves such a row alone (Q is right). A torn
-write that reached one data stripe but neither P nor Q fits the pattern
-too; the rebuild returns that stripe to its old contents, as valid for
-an unacked write as the new ones. Rows with a read error were rebuilt
-by recover_scrub_rbio() from the parity that is not being scrubbed, and
-are left alone. In a read-only scrub nothing is written (previous
-patch).
-
-RAID5 has a single parity, so it cannot tell a stale data strip from
-stale parity, and is unchanged.
-
-Test (raid56-wh-harness nodatasum-scrub-repair-test.sh): nodatasum files
-on a 5-device raid6, each file written with one member failing writes
-during its writeback (each member in turn; within tolerance, so acked),
-then scrub, then every file read with no member, each member and each
-pair missing. Before: scrub kept the 6 stale data strips and rewrote P
-and Q from them; 64 of 80 reads were wrong afterwards, 20 of them correct
-before the scrub. After: the stale strips are rebuilt, P and Q match the
-data, and 80 of 80 reads are correct, with and without stripe_alloc. Two
-stale strips per row (two members failing) cannot be located and still
-get their parity rewritten, as before.
-
-Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/raid56.c | 195 +++++++++++++++++++++++++++++++++++++++++-----
- 1 file changed, 177 insertions(+), 18 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 637be11a1ab4a..b3366434f0d90 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -9,6 +9,7 @@
- #include <linux/slab.h>
- #include <linux/blkdev.h>
- #include <linux/raid/pq.h>
-+#include <linux/raid/pq_tables.h>
- #include <linux/hash.h>
- #include <linux/list_sort.h>
- #include <linux/raid/xor.h>
-@@ -2636,16 +2637,13 @@ static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio)
- return 0;
- }
-
--/* Return true if the content of the step matches the calculated one. */
--static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
-- void *pointers[], unsigned int sector_nr,
-- unsigned int step_nr)
-+/* Calculate P (and Q) of one step into the temporary pages in @pointers. */
-+static void gen_one_parity_step(struct btrfs_raid_bio *rbio, void *pointers[],
-+ unsigned int sector_nr, unsigned int step_nr)
- {
- const unsigned int nr_data = rbio->nr_data;
- const bool has_qstripe = (rbio->real_stripes - rbio->nr_data == 2);
- const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
-- void *parity;
-- bool ret = false;
-
- ASSERT(step_nr < rbio->sector_nsteps);
-
-@@ -2665,36 +2663,159 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
- xor_gen(pointers[nr_data], pointers + 1, nr_data - 1, step);
- }
-
-+ for (int stripe = nr_data - 1; stripe >= 0; stripe--)
-+ kunmap_local(pointers[stripe]);
-+}
-+
-+/*
-+ * Return true if the content of the step matches the calculated one. If not
-+ * and @repair is set, replace it with the calculated one.
-+ */
-+static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
-+ void *pointers[], unsigned int sector_nr,
-+ unsigned int step_nr, bool repair)
-+{
-+ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
-+ void *parity;
-+ bool ret = false;
-+
-+ gen_one_parity_step(rbio, pointers, sector_nr, step_nr);
-+
- /* Check scrubbing parity and repair it. */
- parity = kmap_local_paddr(rbio_stripe_paddr(rbio, rbio->scrubp, sector_nr, step_nr));
-- if (memcmp(parity, pointers[rbio->scrubp], step) != 0)
-- memcpy(parity, pointers[rbio->scrubp], step);
-- else
-+ if (memcmp(parity, pointers[rbio->scrubp], step) != 0) {
-+ if (repair)
-+ memcpy(parity, pointers[rbio->scrubp], step);
-+ } else {
- ret = true;
-+ }
- kunmap_local(parity);
--
-- for (int stripe = nr_data - 1; stripe >= 0; stripe--)
-- kunmap_local(pointers[stripe]);
- return ret;
- }
-
-+/*
-+ * RAID6: find the one data stripe that explains why P and Q of @sector_nr
-+ * both differ from the ones calculated from the data.
-+ *
-+ * If data stripe z is off by e, P is off by e and Q by g^z * e, in every
-+ * byte. Return z if every differing byte of the sector shows that pattern
-+ * with the same z, or -1 if it does not (P or Q alone is off, or more than
-+ * one stripe is).
-+ */
-+static int raid6_locate_bad_data(struct btrfs_raid_bio *rbio, void *pointers[],
-+ unsigned int sector_nr)
-+{
-+ const int nr_data = rbio->nr_data;
-+ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
-+ const u8 *p_calc = pointers[nr_data];
-+ const u8 *q_calc = pointers[rbio->real_stripes - 1];
-+ int bad = -1;
-+
-+ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++) {
-+ const u8 *p;
-+ const u8 *q;
-+
-+ gen_one_parity_step(rbio, pointers, sector_nr, step_nr);
-+ p = kmap_local_paddr(rbio_pstripe_paddr(rbio, sector_nr, step_nr));
-+ q = kmap_local_paddr(rbio_qstripe_paddr(rbio, sector_nr, step_nr));
-+ for (u32 i = 0; i < step; i++) {
-+ const u8 dp = p[i] ^ p_calc[i];
-+ const u8 dq = q[i] ^ q_calc[i];
-+ int z;
-+
-+ if (!dp && !dq)
-+ continue;
-+ if (!dp || !dq) {
-+ bad = -2;
-+ break;
-+ }
-+ z = (raid6_gflog[dq] + 255 - raid6_gflog[dp]) % 255;
-+ if (z >= nr_data || (bad >= 0 && z != bad)) {
-+ bad = -2;
-+ break;
-+ }
-+ bad = z;
-+ }
-+ kunmap_local(q);
-+ kunmap_local(p);
-+ if (bad == -2)
-+ break;
-+ }
-+ return bad < 0 ? -1 : bad;
-+}
-+
-+/* Rebuild data stripe @stripe of @sector_nr: it is off by P ^ calculated P. */
-+static void raid6_rebuild_data_sector(struct btrfs_raid_bio *rbio, void *pointers[],
-+ unsigned int sector_nr, int stripe)
-+{
-+ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
-+
-+ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++) {
-+ void *srcs[2];
-+ void *data;
-+
-+ gen_one_parity_step(rbio, pointers, sector_nr, step_nr);
-+ data = kmap_local_paddr(rbio_stripe_paddr(rbio, stripe, sector_nr, step_nr));
-+ srcs[0] = kmap_local_paddr(rbio_pstripe_paddr(rbio, sector_nr, step_nr));
-+ srcs[1] = pointers[rbio->nr_data];
-+ xor_gen(data, srcs, 2, step);
-+ kunmap_local(srcs[0]);
-+ kunmap_local(data);
-+ }
-+}
-+
- /*
- * The @pointers array should have the P/Q parity already mapped.
-+ *
-+ * Return the data stripe that was rebuilt instead of rewriting the parity,
-+ * or -1.
- */
--static void verify_one_parity_sector(struct btrfs_raid_bio *rbio,
-- void *pointers[], unsigned int sector_nr)
-+static int verify_one_parity_sector(struct btrfs_raid_bio *rbio,
-+ void *pointers[], unsigned int sector_nr,
-+ bool can_locate)
- {
-+ const bool has_qstripe = (rbio->real_stripes - rbio->nr_data == 2);
- bool found_error = false;
-
- for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++) {
- bool match;
-
-- match = verify_one_parity_step(rbio, pointers, sector_nr, step_nr);
-+ match = verify_one_parity_step(rbio, pointers, sector_nr, step_nr, false);
- if (!match)
- found_error = true;
- }
-- if (!found_error)
-+ if (!found_error) {
- bitmap_clear(&rbio->dbitmap, sector_nr, 1);
-+ return -1;
-+ }
-+
-+ /*
-+ * Data without a checksum is taken as it was read, so parity
-+ * calculated from it is not necessarily right: one data stripe may be
-+ * stale, e.g. after a write that failed on its device but succeeded on
-+ * the others. On RAID6, P and Q together tell which one, so rebuild
-+ * that data stripe instead of rewriting the parity from it.
-+ */
-+ if (has_qstripe && can_locate) {
-+ const int bad = raid6_locate_bad_data(rbio, pointers, sector_nr);
-+
-+ if (bad >= 0) {
-+ /*
-+ * P and Q are scrubbed in parallel, each with its own
-+ * read of the data: leave the rebuild to the scrub of P,
-+ * so it is done and counted once. Q is right.
-+ */
-+ bitmap_clear(&rbio->dbitmap, sector_nr, 1);
-+ if (rbio->scrubp != rbio->nr_data)
-+ return -1;
-+ raid6_rebuild_data_sector(rbio, pointers, sector_nr, bad);
-+ return bad;
-+ }
-+ }
-+
-+ for (int step_nr = 0; step_nr < rbio->sector_nsteps; step_nr++)
-+ verify_one_parity_step(rbio, pointers, sector_nr, step_nr, true);
-+ return -1;
- }
-
- static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
-@@ -2710,6 +2831,9 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
- phys_addr_t q_paddr = INVALID_PADDR;
- struct bio_list bio_list;
- bool is_replace = false;
-+ unsigned long read_errors = 0;
-+ unsigned long rebuilt = 0;
-+ u8 rebuilt_stripe[BITS_PER_LONG];
- int ret;
-
- bio_list_init(&bio_list);
-@@ -2757,12 +2881,27 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
- pointers[rbio->real_stripes - 1] = kmap_local_paddr(q_paddr);
- }
-
-+ /*
-+ * Rows with a read error were rebuilt by recover_scrub_rbio(): do not
-+ * look for a bad data stripe there.
-+ */
-+ for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors)
-+ if (get_rbio_vertical_errors(rbio, sectornr, NULL, NULL))
-+ __set_bit(sectornr, &read_errors);
-+
- bitmap_clear(rbio->error_bitmap, 0, rbio->nr_sectors);
-
- /* Map the parity stripe just once */
-
-- for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors)
-- verify_one_parity_sector(rbio, pointers, sectornr);
-+ for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors) {
-+ const int stripe = verify_one_parity_sector(rbio, pointers, sectornr,
-+ !test_bit(sectornr, &read_errors));
-+
-+ if (stripe >= 0) {
-+ __set_bit(sectornr, &rebuilt);
-+ rebuilt_stripe[sectornr] = stripe;
-+ }
-+ }
-
- kunmap_local(pointers[nr_data]);
- __free_page(phys_to_page(p_paddr));
-@@ -2776,6 +2915,26 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
- if (rbio->scrub_readonly)
- goto submit_write;
-
-+ /* Write the data sectors rebuilt from P and Q. */
-+ for_each_set_bit(sectornr, &rebuilt, rbio->stripe_nsectors) {
-+ const int stripe = rebuilt_stripe[sectornr];
-+ const struct btrfs_io_stripe *io_stripe = &bioc->stripes[stripe];
-+
-+ btrfs_warn_rl(bioc->fs_info,
-+"scrub: raid6 data at logical %llu on devid %llu physical %llu did not match P and Q, rebuilt it",
-+ bioc->full_stripe_logical +
-+ btrfs_stripe_nr_to_offset(stripe) +
-+ ((u64)sectornr << bioc->fs_info->sectorsize_bits),
-+ io_stripe->dev->devid,
-+ io_stripe->physical +
-+ ((u64)sectornr << bioc->fs_info->sectorsize_bits));
-+ ret = rbio_add_io_paddrs(rbio, &bio_list,
-+ rbio_stripe_paddrs(rbio, stripe, sectornr),
-+ stripe, sectornr, REQ_OP_WRITE);
-+ if (ret)
-+ goto cleanup;
-+ }
-+
- /*
- * time to start writing. Make bios for everything from the
- * higher layers (the bio_list in our rbio) and our p/q. Ignore
---
-2.47.3
-
+++ /dev/null
-From f6b508f255f92a45cbceff07ac7b080e98c49f7d Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 20 Oct 2026 16:15:58 -0400
-Subject: [PATCH 11/13] btrfs: scrub: count raid56 parity mismatches as
- corruption errors
-To: linux-btrfs@vger.kernel.org
-
-When scrub finds raid56 parity that does not match the data, it rewrites
-the parity (or, on RAID6, rebuilds the data stripe that P and Q locate),
-but counts nothing: the device stats do not change, and the scrub
-progress, and so `btrfs scrub status`, says "no errors found". A
-corrupted parity strip, a stale data strip, or a write hole is repaired
-or papered over without a trace.
-
-Count every sector that did not match as a corruption error
-(BTRFS_DEV_STAT_CORRUPTION_ERRS) of the device that held the bad copy,
-and add it to the scrub's corrected_errors:
-
-- a data stripe that P and Q located and that was rebuilt: its device;
-- otherwise the parity being scrubbed: its device.
-
-The second case is not always right. Without a checksum on the data and
-without a second parity to locate the error (RAID5, or a RAID6 row that
-the decode cannot place), a mismatch may as well be a corrupt or stale
-data sector that nothing can detect; scrub rewrites the parity from that
-data, and the parity device is charged. Rows whose stripes had a read
-error are not counted again: the read error was.
-
-The device is the one in the scrub rbio's io context at the stripe that
-held the bad copy. During dev-replace the scrubbed parity is the
-source's (the target is only written), so the source is charged.
-
-Test (raid56-wh-harness raid56-devstats-test.sh, arm P): 4 sectors of a
-P strip (on raid6 also 4 of a Q strip, other rows) overwritten, then
-scrub. Before: no counter moved and scrub said "no errors found".
-After: corruption_errs +4 on exactly the corrupted member(s), Corrected
-4 (raid6 8), and a second scrub finds nothing.
-nodatasum-scrub-repair-test.sh, raid6 with one stale member per row:
-every stale sector is charged once, to the member that held it.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/raid56.c | 33 ++++++++++++++++++++++++++++++++-
- fs/btrfs/raid56.h | 5 ++++-
- fs/btrfs/scrub.c | 8 +++++++-
- 3 files changed, 43 insertions(+), 3 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b3366434f0d90..4d5f61481226e 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -2559,7 +2559,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
- struct btrfs_io_context *bioc,
- struct btrfs_device *scrub_dev,
- unsigned long *dbitmap, int stripe_nsectors,
-- bool readonly)
-+ bool readonly, u32 *corrected)
- {
- struct btrfs_fs_info *fs_info = bioc->fs_info;
- struct btrfs_raid_bio *rbio;
-@@ -2591,6 +2591,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
-
- bitmap_copy(&rbio->dbitmap, dbitmap, stripe_nsectors);
- rbio->scrub_readonly = readonly;
-+ rbio->scrub_corrected = corrected;
- return rbio;
- }
-
-@@ -2818,6 +2819,35 @@ static int verify_one_parity_sector(struct btrfs_raid_bio *rbio,
- return -1;
- }
-
-+/*
-+ * Count each sector that did not match as a corruption error of the device
-+ * that held it: the data stripe rebuilt from P and Q, or else the scrubbed
-+ * parity, which is rewritten from the data. Without a checksum and without
-+ * a decode (RAID5, or a RAID6 row the decode cannot place), the mismatch may
-+ * as well be corrupt data that nothing can find; the parity is charged.
-+ * Rows with a read error are not counted here: the read error was.
-+ */
-+static void count_parity_scrub_errors(struct btrfs_raid_bio *rbio,
-+ unsigned long read_errors,
-+ unsigned long rebuilt,
-+ const u8 *rebuilt_stripe)
-+{
-+ struct btrfs_io_context *bioc = rbio->bioc;
-+ unsigned long parity_bad;
-+ unsigned int sectornr;
-+
-+ bitmap_andnot(&parity_bad, &rbio->dbitmap, &read_errors, rbio->stripe_nsectors);
-+ for_each_set_bit(sectornr, &rebuilt, rbio->stripe_nsectors)
-+ btrfs_dev_stat_inc_and_print(bioc->stripes[rebuilt_stripe[sectornr]].dev,
-+ BTRFS_DEV_STAT_CORRUPTION_ERRS);
-+ for_each_set_bit(sectornr, &parity_bad, rbio->stripe_nsectors)
-+ btrfs_dev_stat_inc_and_print(bioc->stripes[rbio->scrubp].dev,
-+ BTRFS_DEV_STAT_CORRUPTION_ERRS);
-+ if (rbio->scrub_corrected)
-+ *rbio->scrub_corrected += bitmap_weight(&rebuilt, rbio->stripe_nsectors) +
-+ bitmap_weight(&parity_bad, rbio->stripe_nsectors);
-+}
-+
- static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
- {
- struct btrfs_io_context *bioc = rbio->bioc;
-@@ -2902,6 +2932,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
- rebuilt_stripe[sectornr] = stripe;
- }
- }
-+ count_parity_scrub_errors(rbio, read_errors, rebuilt, rebuilt_stripe);
-
- kunmap_local(pointers[nr_data]);
- __free_page(phys_to_page(p_paddr));
-diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 1f68218598072..dc125624fbf14 100644
---- a/fs/btrfs/raid56.h
-+++ b/fs/btrfs/raid56.h
-@@ -170,6 +170,9 @@ struct btrfs_raid_bio {
- /* Stripe number that we're scrubbing */
- u8 scrubp;
-
-+ /* Parity scrub: where to add the number of mismatching sectors. */
-+ u32 *scrub_corrected;
-+
- /* Parity scrub of a read-only scrub: check, but write nothing. */
- bool scrub_readonly;
-
-@@ -283,7 +286,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
- struct btrfs_io_context *bioc,
- struct btrfs_device *scrub_dev,
- unsigned long *dbitmap, int stripe_nsectors,
-- bool readonly);
-+ bool readonly, u32 *corrected);
- void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
-
- void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 690c8c9d76b5d..869e284aff461 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -2279,6 +2279,7 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
- struct bio bio;
- const int data_stripes = nr_data_stripes(map);
- u64 length = btrfs_stripe_nr_to_offset(data_stripes);
-+ u32 corrected = 0;
- int ret;
-
- bio_init(&bio, NULL, NULL, 0, REQ_OP_READ);
-@@ -2295,7 +2296,7 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
- ASSERT(bioc);
- rbio = raid56_parity_alloc_scrub_rbio(&bio, bioc, scrub_dev, extent_bitmap,
- BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits,
-- sctx->readonly);
-+ sctx->readonly, &corrected);
- btrfs_put_bioc(bioc);
- if (!rbio) {
- ret = -ENOMEM;
-@@ -2311,6 +2312,11 @@ static int scrub_raid56_cached_parity(struct scrub_ctx *sctx,
- raid56_parity_submit_scrub_rbio(rbio);
- wait_for_completion_io(&io_done);
- ret = blk_status_to_errno(bio.bi_status);
-+ if (corrected) {
-+ spin_lock(&sctx->stat_lock);
-+ sctx->stat.corrected_errors += corrected;
-+ spin_unlock(&sctx->stat_lock);
-+ }
- out:
- btrfs_bio_counter_dec(fs_info);
- bio_uninit(&bio);
---
-2.47.3
-
--- /dev/null
+From 5a37421678943cb3293ea13905617134297aa7b3 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 20 Oct 2026 22:15:15 -0400
+Subject: [PATCH 11/12] btrfs: scrub: name the device a raid56 data sector was
+ read from
+To: linux-btrfs@vger.kernel.org
+
+scrub_stripe_report_errors() finds the device and physical address for
+its messages by mapping the stripe's logical address with
+BTRFS_MAP_GET_READ_MIRRORS and taking stripes[mirror_num - 1]. On RAID56
+that mapping is the full stripe's write mapping, and stripes[0] is the
+device of the full stripe's first data stripe, not the device the sector
+was read from. So "checksum error at logical ... on dev ...", "fixed up
+error ... on dev ..." and "unable to fixup (regular) error ... on dev ..."
+name a device that rotates over the members with the full stripes, and a
+physical address on it that holds something else. The device stats were
+always charged to the right device (stripe->dev).
+
+The scrub stripe already records where it was read from: use
+stripe->dev and stripe->physical. For the mirrored and striped profiles
+that is the same device and address as before.
+
+Test (raid56-wh-harness scrub-blame-test.sh): with damaged data sectors
+on one raid5/raid6 member, every per-sector line names that member, in
+every scrub order. Before: 1 to 8 of up to 10 lines named another
+member, always the predicted stripes[0].
+
+Fixes: 0096580713ff ("btrfs: scrub: introduce error reporting functionality for scrub_stripe")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 31 +++++++------------------------
+ 1 file changed, 7 insertions(+), 24 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 799e78a892d10..a776b519acb8f 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -1004,34 +1004,17 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
+ return;
+
+ /*
+- * Init needed infos for error reporting.
+- *
+- * Although our scrub_stripe infrastructure is mostly based on btrfs_submit_bio()
+- * thus no need for dev/physical, error reporting still needs dev and physical.
++ * The sectors were read from @stripe->dev at @stripe->physical. Mapping
++ * @stripe->logical back with BTRFS_MAP_GET_READ_MIRRORS does not give that
++ * on RAID56: it returns the full stripe's write mapping, whose
++ * stripes[mirror_num - 1] is the device of the full stripe's first data
++ * stripe.
+ */
+ if (!bitmap_empty(&errors->init_error_bitmap, stripe->nr_sectors)) {
+- u64 mapped_len = fs_info->sectorsize;
+- struct btrfs_io_context *bioc = NULL;
+- int stripe_index = stripe->mirror_num - 1;
+- int ret;
+-
+- /* For scrub, our mirror_num should always start at 1. */
+- ASSERT(stripe->mirror_num >= 1, "stripe->mirror_num=%d", stripe->mirror_num);
+- ret = btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS,
+- stripe->logical, &mapped_len, &bioc,
+- NULL, NULL);
+- /*
+- * If we failed, dev will be NULL, and later detailed reports
+- * will just be skipped.
+- */
+- if (ret < 0)
+- goto skip;
+- physical = bioc->stripes[stripe_index].physical;
+- dev = bioc->stripes[stripe_index].dev;
+- btrfs_put_bioc(bioc);
++ dev = stripe->dev;
++ physical = stripe->physical;
+ }
+
+-skip:
+ for_each_set_bit(sector_nr, &extent_bitmap, stripe->nr_sectors) {
+ const u64 sector_logical = stripe->logical +
+ ((u64)sector_nr << fs_info->sectorsize_bits);
+--
+2.47.3
+
--- /dev/null
+From b7b4005cacc44b50375cbb55d550f35eed1662f6 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 20 Oct 2026 22:15:16 -0400
+Subject: [PATCH 12/12] btrfs: scrub: count the raid56 data repairs made by a
+ parity scrub
+To: linux-btrfs@vger.kernel.org
+
+The scrub of a RAID56 P/Q device reads every data stripe of each full
+stripe it checks, verifies and repairs them, and writes the repairs back,
+but counts nothing (SCRUB_STRIPE_FLAG_NO_REPORT): neither the scrub
+progress nor the device stats. When the P/Q device's scrub reaches a
+full stripe before the data device's own scrub does, the data device's
+scrub finds the sector already repaired, and the error is counted
+nowhere. With all devices scrubbed at once that is a large share of the
+errors (one failing raid5 member: 25831 of 42371 damaged data sectors
+counted; raid6: 7894 of 34146), and when the damaged device is scrubbed
+last, none of them.
+
+Count the sectors that the parity scrub repaired and wrote back, as the
+data device's scrub would have: read, checksum and verify errors in the
+device stats of the data stripe's own device, and in the parity scrub's
+progress with corrected_errors. To count each bad sector once:
+
+- errors left unrepaired are not counted: they stay on disk for the data
+ device's own scrub;
+- a read-only scrub counts nothing here: nothing is written back, and the
+ data device's own scrub will see the same errors;
+- when the data device is being scrubbed at the same time (its
+ scrub_ctx is set), that scrub repairs and counts its errors itself, so
+ the parity scrub neither writes back nor counts them. It still uses
+ the repaired data for its parity check. Crediting the data device's
+ scrub from here instead would count a sector twice whenever both scrubs
+ read it before either wrote the repair back, which is common when all
+ devices are scrubbed at once, since they move through the full stripes
+ together.
+
+A missing data device is not counted against.
+
+Test (raid56-wh-harness scrub-blame-test.sh): 8 damaged data sectors (or
+whole damaged strips: 288 raid5, 224 raid6) on one member, all devices
+scrubbed at once, the damaged one first, or last: every damaged sector
+counted once in every order, the device stats charged to that member
+only; read-only scrubs too. Before: 7 of 8 (raid6 2 of 8) at once, 0
+with the damaged member last. failing-member-scrub-test.sh, one member
+failing under load: raid5 36128 of 36128, raid6 30231 of 30231 damaged
+sectors counted; before, 26519 of 40556 and 11049 of 30723.
+
+Fixes: 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 109 +++++++++++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 105 insertions(+), 4 deletions(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index a776b519acb8f..86c9801ca3155 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -85,10 +85,17 @@ enum scrub_stripe_flags {
+
+ /*
+ * Set for data stripes if it's triggered from P/Q stripe.
+- * During such scrub, we should not report errors in data stripes, nor
+- * update the accounting.
++ * During such scrub, only the errors repaired and written back are
++ * reported and counted, see scrub_report_parity_repairs().
+ */
+ SCRUB_STRIPE_FLAG_NO_REPORT,
++
++ /*
++ * Set for such a data stripe whose own device is being scrubbed at the
++ * same time: that scrub repairs and counts its errors, so they are not
++ * written back or counted here.
++ */
++ SCRUB_STRIPE_FLAG_OWN_SCRUB,
+ };
+
+ /*
+@@ -327,6 +334,12 @@ struct scrub_error_records {
+ unsigned int nr_csum_errors;
+ unsigned int nr_meta_errors;
+ unsigned int nr_meta_gen_errors;
++
++ /* The initial errors per type, for scrub_report_parity_repairs(). */
++ unsigned long init_io_error_bitmap;
++ unsigned long init_csum_error_bitmap;
++ unsigned long init_meta_error_bitmap;
++ unsigned long init_meta_gen_error_bitmap;
+ };
+
+ static void release_scrub_stripe(struct scrub_stripe *stripe)
+@@ -983,6 +996,73 @@ static void scrub_stripe_submit_repair_read(struct scrub_stripe *stripe,
+ }
+ }
+
++/*
++ * A RAID56 P/Q scrub reads, verifies and repairs the data stripes of each full
++ * stripe it checks, and writes the repairs back, so the data device's own
++ * scrub, if it gets there later, finds nothing. Count here what was repaired
++ * and written back, as that scrub would have: in the device stats of the data
++ * stripe's device and in the progress of this scrub.
++ *
++ * Nothing else is counted here. Errors left unrepaired, and everything in a
++ * read-only scrub, stay on disk for the data device's own scrub to find; and a
++ * data device that is being scrubbed at the same time repairs and counts its
++ * own errors (SCRUB_STRIPE_FLAG_OWN_SCRUB: nothing is written back here). So
++ * each bad sector is counted once.
++ */
++static void scrub_report_parity_repairs(struct scrub_ctx *sctx,
++ struct scrub_stripe *stripe,
++ const struct scrub_error_records *errors)
++{
++ struct btrfs_fs_info *fs_info = sctx->fs_info;
++ const unsigned long error_bitmap = scrub_bitmap_read_error(stripe);
++ const unsigned int nr_sectors = stripe->nr_sectors;
++ unsigned long repaired;
++ unsigned int nr_io_errors;
++ unsigned int nr_csum_errors;
++ unsigned int nr_meta_errors;
++ unsigned int nr_meta_gen_errors;
++ int sector_nr;
++
++ if (sctx->readonly || test_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state) ||
++ !stripe->dev->bdev)
++ return;
++ bitmap_andnot(&repaired, &errors->init_error_bitmap, &error_bitmap, nr_sectors);
++ if (bitmap_empty(&repaired, nr_sectors))
++ return;
++
++ nr_io_errors = bitmap_weight_and(&repaired, &errors->init_io_error_bitmap,
++ nr_sectors);
++ nr_csum_errors = bitmap_weight_and(&repaired, &errors->init_csum_error_bitmap,
++ nr_sectors);
++ nr_meta_errors = bitmap_weight_and(&repaired, &errors->init_meta_error_bitmap,
++ nr_sectors);
++ nr_meta_gen_errors = bitmap_weight_and(&repaired,
++ &errors->init_meta_gen_error_bitmap,
++ nr_sectors);
++
++ for_each_set_bit(sector_nr, &repaired, nr_sectors)
++ btrfs_err_rl(fs_info,
++ "scrub: fixed up error at logical %llu on dev %s physical %llu",
++ stripe->logical + ((u64)sector_nr << fs_info->sectorsize_bits),
++ btrfs_dev_name(stripe->dev),
++ stripe->physical + ((u64)sector_nr << fs_info->sectorsize_bits));
++
++ for (int i = 0; i < nr_io_errors; i++)
++ btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_READ_ERRS);
++ for (int i = 0; i < nr_csum_errors; i++)
++ btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_CORRUPTION_ERRS);
++ for (int i = 0; i < nr_meta_gen_errors;
++ i += (fs_info->nodesize >> fs_info->sectorsize_bits))
++ btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_GENERATION_ERRS);
++
++ spin_lock(&sctx->stat_lock);
++ sctx->stat.read_errors += nr_io_errors;
++ sctx->stat.csum_errors += nr_csum_errors;
++ sctx->stat.verify_errors += nr_meta_errors + nr_meta_gen_errors;
++ sctx->stat.corrected_errors += bitmap_weight(&repaired, nr_sectors);
++ spin_unlock(&sctx->stat_lock);
++}
++
+ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
+ struct scrub_stripe *stripe,
+ const struct scrub_error_records *errors)
+@@ -1000,8 +1080,10 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
+ int nr_repaired_sectors = 0;
+ int sector_nr;
+
+- if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state))
++ if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state)) {
++ scrub_report_parity_repairs(sctx, stripe, errors);
+ return;
++ }
+
+ /*
+ * The sectors were read from @stripe->dev at @stripe->physical. Mapping
+@@ -1153,6 +1235,10 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
+ errors.nr_csum_errors = scrub_bitmap_weight_csum_error(stripe);
+ errors.nr_meta_errors = scrub_bitmap_weight_meta_error(stripe);
+ errors.nr_meta_gen_errors = scrub_bitmap_weight_meta_gen_error(stripe);
++ errors.init_io_error_bitmap = scrub_bitmap_read_io_error(stripe);
++ errors.init_csum_error_bitmap = scrub_bitmap_read_csum_error(stripe);
++ errors.init_meta_error_bitmap = scrub_bitmap_read_meta_error(stripe);
++ errors.init_meta_gen_error_bitmap = scrub_bitmap_read_meta_gen_error(stripe);
+
+ if (bitmap_empty(&errors.init_error_bitmap, stripe->nr_sectors))
+ goto out;
+@@ -1207,7 +1293,8 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
+ */
+ bitmap_andnot(&repaired, &errors.init_error_bitmap, &error,
+ stripe->nr_sectors);
+- if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
++ if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors) &&
++ !test_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state)) {
+ if (btrfs_is_zoned(fs_info)) {
+ btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
+ } else {
+@@ -2381,6 +2468,18 @@ static void scrub_raid56_copy_parity_rows(struct scrub_ctx *sctx,
+ kfree(buf);
+ }
+
++/* Is @dev being scrubbed right now, by a scrub other than @sctx? */
++static bool scrubbed_by_other(struct scrub_ctx *sctx, struct btrfs_device *dev)
++{
++ struct btrfs_fs_info *fs_info = sctx->fs_info;
++ bool ret;
++
++ mutex_lock(&fs_info->scrub_lock);
++ ret = dev->scrub_ctx && dev->scrub_ctx != sctx;
++ mutex_unlock(&fs_info->scrub_lock);
++ return ret;
++}
++
+ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+ struct btrfs_device *scrub_dev,
+ struct btrfs_block_group *bg,
+@@ -2439,6 +2538,8 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
+
+ scrub_reset_stripe(stripe);
+ set_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state);
++ if (scrubbed_by_other(sctx, map->stripes[stripe_index].dev))
++ set_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state);
+ ret = scrub_find_fill_first_stripe(bg, &extent_path, &csum_path,
+ map->stripes[stripe_index].dev, physical, 1,
+ full_stripe_start +
+--
+2.47.3
+
+++ /dev/null
-From 302044132402f123134b510a46f366a1a1544135 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 20 Oct 2026 22:15:15 -0400
-Subject: [PATCH 12/13] btrfs: scrub: name the device a raid56 data sector was
- read from
-To: linux-btrfs@vger.kernel.org
-
-scrub_stripe_report_errors() finds the device and physical address for
-its messages by mapping the stripe's logical address with
-BTRFS_MAP_GET_READ_MIRRORS and taking stripes[mirror_num - 1]. On RAID56
-that mapping is the full stripe's write mapping, and stripes[0] is the
-device of the full stripe's first data stripe, not the device the sector
-was read from. So "checksum error at logical ... on dev ...", "fixed up
-error ... on dev ..." and "unable to fixup (regular) error ... on dev ..."
-name a device that rotates over the members with the full stripes, and a
-physical address on it that holds something else. The device stats were
-always charged to the right device (stripe->dev).
-
-The scrub stripe already records where it was read from: use
-stripe->dev and stripe->physical. For the mirrored and striped profiles
-that is the same device and address as before.
-
-Test (raid56-wh-harness scrub-blame-test.sh): with damaged data sectors
-on one raid5/raid6 member, every per-sector line names that member, in
-every scrub order. Before: 1 to 8 of up to 10 lines named another
-member, always the predicted stripes[0].
-
-Fixes: 0096580713ff ("btrfs: scrub: introduce error reporting functionality for scrub_stripe")
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 31 +++++++------------------------
- 1 file changed, 7 insertions(+), 24 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 869e284aff461..d704fd0d64435 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -996,34 +996,17 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
- return;
-
- /*
-- * Init needed infos for error reporting.
-- *
-- * Although our scrub_stripe infrastructure is mostly based on btrfs_submit_bio()
-- * thus no need for dev/physical, error reporting still needs dev and physical.
-+ * The sectors were read from @stripe->dev at @stripe->physical. Mapping
-+ * @stripe->logical back with BTRFS_MAP_GET_READ_MIRRORS does not give that
-+ * on RAID56: it returns the full stripe's write mapping, whose
-+ * stripes[mirror_num - 1] is the device of the full stripe's first data
-+ * stripe.
- */
- if (!bitmap_empty(&errors->init_error_bitmap, stripe->nr_sectors)) {
-- u64 mapped_len = fs_info->sectorsize;
-- struct btrfs_io_context *bioc = NULL;
-- int stripe_index = stripe->mirror_num - 1;
-- int ret;
--
-- /* For scrub, our mirror_num should always start at 1. */
-- ASSERT(stripe->mirror_num >= 1, "stripe->mirror_num=%d", stripe->mirror_num);
-- ret = btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS,
-- stripe->logical, &mapped_len, &bioc,
-- NULL, NULL);
-- /*
-- * If we failed, dev will be NULL, and later detailed reports
-- * will just be skipped.
-- */
-- if (ret < 0)
-- goto skip;
-- physical = bioc->stripes[stripe_index].physical;
-- dev = bioc->stripes[stripe_index].dev;
-- btrfs_put_bioc(bioc);
-+ dev = stripe->dev;
-+ physical = stripe->physical;
- }
-
--skip:
- for_each_set_bit(sector_nr, &extent_bitmap, stripe->nr_sectors) {
- const u64 sector_logical = stripe->logical +
- ((u64)sector_nr << fs_info->sectorsize_bits);
---
-2.47.3
-
+++ /dev/null
-From 9970d7e44abf0e5a7c67c93228908af5a0303f86 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 20 Oct 2026 22:15:16 -0400
-Subject: [PATCH 13/13] btrfs: scrub: count the raid56 data repairs made by a
- parity scrub
-To: linux-btrfs@vger.kernel.org
-
-The scrub of a RAID56 P/Q device reads every data stripe of each full
-stripe it checks, verifies and repairs them, and writes the repairs back,
-but counts nothing (SCRUB_STRIPE_FLAG_NO_REPORT): neither the scrub
-progress nor the device stats. When the P/Q device's scrub reaches a
-full stripe before the data device's own scrub does, the data device's
-scrub finds the sector already repaired, and the error is counted
-nowhere. With all devices scrubbed at once that is a large share of the
-errors (one failing raid5 member: 25831 of 42371 damaged data sectors
-counted; raid6: 7894 of 34146), and when the damaged device is scrubbed
-last, none of them.
-
-Count the sectors that the parity scrub repaired and wrote back, as the
-data device's scrub would have: read, checksum and verify errors in the
-device stats of the data stripe's own device, and in the parity scrub's
-progress with corrected_errors. To count each bad sector once:
-
-- errors left unrepaired are not counted: they stay on disk for the data
- device's own scrub;
-- a read-only scrub counts nothing here: nothing is written back, and the
- data device's own scrub will see the same errors;
-- when the data device is being scrubbed at the same time (its
- scrub_ctx is set), that scrub repairs and counts its errors itself, so
- the parity scrub neither writes back nor counts them. It still uses
- the repaired data for its parity check. Crediting the data device's
- scrub from here instead would count a sector twice whenever both scrubs
- read it before either wrote the repair back, which is common when all
- devices are scrubbed at once, since they move through the full stripes
- together.
-
-A missing data device is not counted against.
-
-Test (raid56-wh-harness scrub-blame-test.sh): 8 damaged data sectors (or
-whole damaged strips: 288 raid5, 224 raid6) on one member, all devices
-scrubbed at once, the damaged one first, or last: every damaged sector
-counted once in every order, the device stats charged to that member
-only; read-only scrubs too. Before: 7 of 8 (raid6 2 of 8) at once, 0
-with the damaged member last. failing-member-scrub-test.sh, one member
-failing under load: raid5 36128 of 36128, raid6 30231 of 30231 damaged
-sectors counted; before, 26519 of 40556 and 11049 of 30723.
-
-Fixes: 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/scrub.c | 109 +++++++++++++++++++++++++++++++++++++++++++++--
- 1 file changed, 105 insertions(+), 4 deletions(-)
-
-diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index d704fd0d64435..5cf7830c63a4b 100644
---- a/fs/btrfs/scrub.c
-+++ b/fs/btrfs/scrub.c
-@@ -85,10 +85,17 @@ enum scrub_stripe_flags {
-
- /*
- * Set for data stripes if it's triggered from P/Q stripe.
-- * During such scrub, we should not report errors in data stripes, nor
-- * update the accounting.
-+ * During such scrub, only the errors repaired and written back are
-+ * reported and counted, see scrub_report_parity_repairs().
- */
- SCRUB_STRIPE_FLAG_NO_REPORT,
-+
-+ /*
-+ * Set for such a data stripe whose own device is being scrubbed at the
-+ * same time: that scrub repairs and counts its errors, so they are not
-+ * written back or counted here.
-+ */
-+ SCRUB_STRIPE_FLAG_OWN_SCRUB,
- };
-
- /*
-@@ -326,6 +333,12 @@ struct scrub_error_records {
- unsigned int nr_csum_errors;
- unsigned int nr_meta_errors;
- unsigned int nr_meta_gen_errors;
-+
-+ /* The initial errors per type, for scrub_report_parity_repairs(). */
-+ unsigned long init_io_error_bitmap;
-+ unsigned long init_csum_error_bitmap;
-+ unsigned long init_meta_error_bitmap;
-+ unsigned long init_meta_gen_error_bitmap;
- };
-
- static void release_scrub_stripe(struct scrub_stripe *stripe)
-@@ -975,6 +988,73 @@ static void scrub_stripe_submit_repair_read(struct scrub_stripe *stripe,
- }
- }
-
-+/*
-+ * A RAID56 P/Q scrub reads, verifies and repairs the data stripes of each full
-+ * stripe it checks, and writes the repairs back, so the data device's own
-+ * scrub, if it gets there later, finds nothing. Count here what was repaired
-+ * and written back, as that scrub would have: in the device stats of the data
-+ * stripe's device and in the progress of this scrub.
-+ *
-+ * Nothing else is counted here. Errors left unrepaired, and everything in a
-+ * read-only scrub, stay on disk for the data device's own scrub to find; and a
-+ * data device that is being scrubbed at the same time repairs and counts its
-+ * own errors (SCRUB_STRIPE_FLAG_OWN_SCRUB: nothing is written back here). So
-+ * each bad sector is counted once.
-+ */
-+static void scrub_report_parity_repairs(struct scrub_ctx *sctx,
-+ struct scrub_stripe *stripe,
-+ const struct scrub_error_records *errors)
-+{
-+ struct btrfs_fs_info *fs_info = sctx->fs_info;
-+ const unsigned long error_bitmap = scrub_bitmap_read_error(stripe);
-+ const unsigned int nr_sectors = stripe->nr_sectors;
-+ unsigned long repaired;
-+ unsigned int nr_io_errors;
-+ unsigned int nr_csum_errors;
-+ unsigned int nr_meta_errors;
-+ unsigned int nr_meta_gen_errors;
-+ int sector_nr;
-+
-+ if (sctx->readonly || test_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state) ||
-+ !stripe->dev->bdev)
-+ return;
-+ bitmap_andnot(&repaired, &errors->init_error_bitmap, &error_bitmap, nr_sectors);
-+ if (bitmap_empty(&repaired, nr_sectors))
-+ return;
-+
-+ nr_io_errors = bitmap_weight_and(&repaired, &errors->init_io_error_bitmap,
-+ nr_sectors);
-+ nr_csum_errors = bitmap_weight_and(&repaired, &errors->init_csum_error_bitmap,
-+ nr_sectors);
-+ nr_meta_errors = bitmap_weight_and(&repaired, &errors->init_meta_error_bitmap,
-+ nr_sectors);
-+ nr_meta_gen_errors = bitmap_weight_and(&repaired,
-+ &errors->init_meta_gen_error_bitmap,
-+ nr_sectors);
-+
-+ for_each_set_bit(sector_nr, &repaired, nr_sectors)
-+ btrfs_err_rl(fs_info,
-+ "scrub: fixed up error at logical %llu on dev %s physical %llu",
-+ stripe->logical + ((u64)sector_nr << fs_info->sectorsize_bits),
-+ btrfs_dev_name(stripe->dev),
-+ stripe->physical + ((u64)sector_nr << fs_info->sectorsize_bits));
-+
-+ for (int i = 0; i < nr_io_errors; i++)
-+ btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_READ_ERRS);
-+ for (int i = 0; i < nr_csum_errors; i++)
-+ btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_CORRUPTION_ERRS);
-+ for (int i = 0; i < nr_meta_gen_errors;
-+ i += (fs_info->nodesize >> fs_info->sectorsize_bits))
-+ btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_GENERATION_ERRS);
-+
-+ spin_lock(&sctx->stat_lock);
-+ sctx->stat.read_errors += nr_io_errors;
-+ sctx->stat.csum_errors += nr_csum_errors;
-+ sctx->stat.verify_errors += nr_meta_errors + nr_meta_gen_errors;
-+ sctx->stat.corrected_errors += bitmap_weight(&repaired, nr_sectors);
-+ spin_unlock(&sctx->stat_lock);
-+}
-+
- static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
- struct scrub_stripe *stripe,
- const struct scrub_error_records *errors)
-@@ -992,8 +1072,10 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
- int nr_repaired_sectors = 0;
- int sector_nr;
-
-- if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state))
-+ if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state)) {
-+ scrub_report_parity_repairs(sctx, stripe, errors);
- return;
-+ }
-
- /*
- * The sectors were read from @stripe->dev at @stripe->physical. Mapping
-@@ -1145,6 +1227,10 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
- errors.nr_csum_errors = scrub_bitmap_weight_csum_error(stripe);
- errors.nr_meta_errors = scrub_bitmap_weight_meta_error(stripe);
- errors.nr_meta_gen_errors = scrub_bitmap_weight_meta_gen_error(stripe);
-+ errors.init_io_error_bitmap = scrub_bitmap_read_io_error(stripe);
-+ errors.init_csum_error_bitmap = scrub_bitmap_read_csum_error(stripe);
-+ errors.init_meta_error_bitmap = scrub_bitmap_read_meta_error(stripe);
-+ errors.init_meta_gen_error_bitmap = scrub_bitmap_read_meta_gen_error(stripe);
-
- if (bitmap_empty(&errors.init_error_bitmap, stripe->nr_sectors))
- goto out;
-@@ -1199,7 +1285,8 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
- */
- bitmap_andnot(&repaired, &errors.init_error_bitmap, &error,
- stripe->nr_sectors);
-- if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
-+ if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors) &&
-+ !test_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state)) {
- if (btrfs_is_zoned(fs_info)) {
- btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
- } else {
-@@ -2364,6 +2451,18 @@ static void scrub_raid56_copy_parity_rows(struct scrub_ctx *sctx,
- kfree(buf);
- }
-
-+/* Is @dev being scrubbed right now, by a scrub other than @sctx? */
-+static bool scrubbed_by_other(struct scrub_ctx *sctx, struct btrfs_device *dev)
-+{
-+ struct btrfs_fs_info *fs_info = sctx->fs_info;
-+ bool ret;
-+
-+ mutex_lock(&fs_info->scrub_lock);
-+ ret = dev->scrub_ctx && dev->scrub_ctx != sctx;
-+ mutex_unlock(&fs_info->scrub_lock);
-+ return ret;
-+}
-+
- static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
- struct btrfs_device *scrub_dev,
- struct btrfs_block_group *bg,
-@@ -2421,6 +2520,8 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
-
- scrub_reset_stripe(stripe);
- set_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state);
-+ if (scrubbed_by_other(sctx, map->stripes[stripe_index].dev))
-+ set_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state);
- ret = scrub_find_fill_first_stripe(bg, &extent_path, &csum_path,
- map->stripes[stripe_index].dev, physical, 1,
- full_stripe_start + btrfs_stripe_nr_to_offset(i),
---
-2.47.3
-
# Testing: raid56-scrub-replace
+> **Numbering (2026-10-25):** the lane was rebased onto btrfs/for-next
+> `0713fa6a4356`, which contains Filipe Manana's -EIO fix (`ec0795c045c3`),
+> so the series is now 0/12. The patch numbers below are from the earlier
+> 13-patch export: "patch 1" is Filipe's, and patch N here is patch N-1 now.
+
RAID5/6 scrub and device replace with unrepairable data, made to behave
like the other profiles. Patch 1 (Filipe Manana's, in for-next) restores
the -EIO of a full stripe with unrepaired data. Patch 2 checks and
-From 18680c6045be2df3dd156e7cce746b6dcb9532b3 Mon Sep 17 00:00:00 2001
+From ccf8a6c6d49bbbf18675148d9af1a74d7512f6aa Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:18 -0400
+Date: Sun, 25 Oct 2026 03:13:47 -0400
Subject: [PATCH 0/9] btrfs: read policies and per-device read stats (Kai Krakow's series, as carried on misc-next)
To: linux-btrfs@vger.kernel.org
6 files changed, 510 insertions(+), 32 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From e0b5265e83e087232fef5a48067242e0f2602eb8 Mon Sep 17 00:00:00 2001
+From ec0c9ea075a4fa3b568c350fb6b77326ee73178f Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:44:51 +0200
Subject: [PATCH 1/9] btrfs: add io read stats per device to devinfo
bool "Btrfs experimental features"
depends on BTRFS_FS
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..145516adffb73 100644
+index 89b0a4ef4063e..da3c434cd858b 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -26,6 +26,10 @@
/*
* Structure name Path
* --------------------------------------------------------------------------
-@@ -1983,12 +1987,37 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
+@@ -1984,12 +1988,37 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
}
BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
BTRFS_ATTR_PTR(devid, fsid),
BTRFS_ATTR_PTR(devid, in_fs_metadata),
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d3e6a9b429dd9..da86a8a5a3e99 100644
+index ce78a9441c64f..1ee88bb257ac1 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6669,6 +6669,15 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6682,6 +6682,15 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
else
num_stripes = map->num_stripes;
switch (policy) {
default:
/* Shouldn't happen, just warn and use pid instead of failing */
-@@ -6704,14 +6713,29 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6717,14 +6726,29 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
for (tolerance = 0; tolerance < 2; tolerance++) {
if (map->stripes[preferred_mirror].dev->bdev &&
(tolerance || map->stripes[preferred_mirror].dev != srcdev))
* and the io error handling code will clean up eventually
*/
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 6eddda2392215..b3a4e1c085ab7 100644
+index 75b1179776c80..d065cec44e547 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -217,6 +217,14 @@ struct btrfs_device {
-From 5edcbb7d3b4a947aebc5495fca7e112b191fe86c Mon Sep 17 00:00:00 2001
+From 06930d250a45b0deb76222acf79694e5a40b5992 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 13 Dec 2025 18:34:36 +0100
Subject: [PATCH 2/9] btrfs: move read policies out of experimental
bool "Btrfs experimental features"
depends on BTRFS_FS
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index acb704b20c2be..12b2ee47bb383 100644
+index b424cc836bd4a..d975cfb86547e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
-@@ -2587,7 +2587,7 @@ static int __init btrfs_print_mod_info(void)
+@@ -2589,7 +2589,7 @@ static int __init btrfs_print_mod_info(void)
#endif
;
if (btrfs_get_mod_read_policy() == NULL)
pr_info("Btrfs loaded%s\n", options);
else
-@@ -2595,7 +2595,7 @@ static int __init btrfs_print_mod_info(void)
+@@ -2597,7 +2597,7 @@ static int __init btrfs_print_mod_info(void)
options, btrfs_get_mod_read_policy());
#else
pr_info("Btrfs loaded%s\n", options);
return 0;
}
-@@ -2657,11 +2657,11 @@ static const struct init_sequence mod_init_seq[] = {
+@@ -2659,11 +2659,11 @@ static const struct init_sequence mod_init_seq[] = {
}, {
.init_func = btrfs_extent_map_init,
.exit_func = btrfs_extent_map_exit,
.init_func = ordered_data_init,
.exit_func = ordered_data_exit,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 145516adffb73..f920334f4cf5d 100644
+index da3c434cd858b..59e0d97e7ee64 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1209,13 +1209,13 @@ BTRFS_ATTR(, temp_fsid, btrfs_temp_fsid_show);
#endif
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index da86a8a5a3e99..69aaeaba032b5 100644
+index 1ee88bb257ac1..983f4d7910bc6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1293,7 +1293,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
return 0;
}
-@@ -6580,7 +6580,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
+@@ -6593,7 +6593,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
return len;
}
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
for (int index = first; index < first + num_stripes; index++) {
-@@ -6648,7 +6648,7 @@ static int btrfs_read_rr(const struct btrfs_chunk_map *map, int first, int num_s
+@@ -6661,7 +6661,7 @@ static int btrfs_read_rr(const struct btrfs_chunk_map *map, int first, int num_s
read_cycle = total_reads / min_reads_per_dev;
return stripes[read_cycle % num_stripes].num;
}
static int find_live_mirror(struct btrfs_fs_info *fs_info,
struct btrfs_chunk_map *map, int first,
-@@ -6688,14 +6688,14 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6701,14 +6701,14 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
case BTRFS_READ_POLICY_PID:
preferred_mirror = first + (current->pid % num_stripes);
break;
if (dev_replace_is_ongoing &&
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index b3a4e1c085ab7..4ee18de14376f 100644
+index d065cec44e547..fc9bc3f462795 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -334,12 +334,12 @@ enum btrfs_chunk_allocation_policy {
-From 58f1d153286feb1ac4e12b601fd69aa8b831f4b3 Mon Sep 17 00:00:00 2001
+From 9f84f0ee680adf55ff17a0c10277b21216eb100d Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Fri, 25 Apr 2025 21:46:52 +0200
Subject: [PATCH 3/9] btrfs: add in-flight queue read policy
3 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index f920334f4cf5d..153e3de6b17d2 100644
+index 59e0d97e7ee64..c851f6c44207b 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1211,6 +1211,7 @@ static const char *btrfs_read_policy_name[] = {
int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 69aaeaba032b5..39e33f1b7623a 100644
+index 983f4d7910bc6..f94e9a2f58e3b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -35,6 +35,10 @@
#define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
BTRFS_BLOCK_GROUP_RAID10 | \
BTRFS_BLOCK_GROUP_RAID56_MASK)
-@@ -6581,6 +6585,50 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
+@@ -6594,6 +6598,50 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
}
#ifdef CONFIG_BTRFS_READ_POLICIES
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
for (int index = first; index < first + num_stripes; index++) {
-@@ -6692,6 +6740,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6705,6 +6753,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
case BTRFS_READ_POLICY_RR:
preferred_mirror = btrfs_read_rr(map, first, num_stripes);
break;
preferred_mirror = btrfs_read_preferred(map, first, num_stripes);
break;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 4ee18de14376f..8cbdc5f046d37 100644
+index fc9bc3f462795..e81d80273254c 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -337,6 +337,8 @@ enum btrfs_read_policy {
-From e8d03a2eb2b967ebb4dac78581caafa3bd09a484 Mon Sep 17 00:00:00 2001
+From 244eddf9e713458014856e0cc62ab0c5be764871 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Thu, 9 Jul 2026 12:35:14 +0200
Subject: [PATCH 4/9] btrfs: move age io stat out of
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 39e33f1b7623a..d9a6aded882bd 100644
+index f94e9a2f58e3b..42d537ef1b67f 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6717,14 +6717,17 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6730,14 +6730,17 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
else
num_stripes = map->num_stripes;
switch (policy) {
default:
-@@ -6776,17 +6779,19 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6789,17 +6792,19 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
}
out:
/* we couldn't find one that doesn't fail. Just return something
* and the io error handling code will clean up eventually
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 8cbdc5f046d37..8a9121a3a9a6a 100644
+index e81d80273254c..5b94161023664 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -218,10 +218,10 @@ struct btrfs_device {
-From cc52421fcb450bc901264391a0873211ee15e033 Mon Sep 17 00:00:00 2001
+From 776a329bca41446491777ce2bdd5a02518111a19 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Thu, 9 Jul 2026 12:27:18 +0200
Subject: [PATCH 5/9] btrfs: break queue read ties by mirror age
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d9a6aded882bd..bc1d10f04c1d1 100644
+index 42d537ef1b67f..c14768795cda1 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6600,28 +6600,48 @@ static unsigned int part_in_flight(struct block_device *part)
+@@ -6613,28 +6613,48 @@ static unsigned int part_in_flight(struct block_device *part)
return inflight;
}
-From 30bcda8ddcc9e827bb1e552f4f1b7b0206f4d13e Mon Sep 17 00:00:00 2001
+From 9e1ef3d3ea2434fb152e0bfcb8e1695989a00889 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Thu, 9 Jul 2026 13:10:10 +0200
Subject: [PATCH 6/9] btrfs: add read latency health stats to per-device io
3 files changed, 100 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 153e3de6b17d2..41dabaa74d7cb 100644
+index c851f6c44207b..aa7cac991e684 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -1997,15 +1997,18 @@ static ssize_t btrfs_devinfo_read_stats_show(struct kobject *kobj,
+@@ -1998,15 +1998,18 @@ static ssize_t btrfs_devinfo_read_stats_show(struct kobject *kobj,
u64 read_wait = device->bdev ? part_stat_read(device->bdev, nsecs[READ]) : 0;
unsigned long read_ios = device->bdev ?
part_stat_read(device->bdev, ios[READ]) : 0;
BTRFS_ATTR(devid, read_stats, btrfs_devinfo_read_stats_show);
#endif /* CONFIG_BTRFS_PER_DEVICE_IO_STATS */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index bc1d10f04c1d1..41916fccbd534 100644
+index c14768795cda1..d7bbe94175c2d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -35,9 +35,12 @@
#define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
BTRFS_BLOCK_GROUP_RAID10 | \
-@@ -6649,6 +6652,77 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6662,6 +6665,77 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
return best_stripe;
}
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
for (int index = first; index < first + num_stripes; index++) {
-@@ -6749,6 +6823,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6762,6 +6836,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
}
#endif /* CONFIG_BTRFS_READ_POLICIES || CONFIG_BTRFS_PER_DEVICE_IO_STATS */
default:
/* Shouldn't happen, just warn and use pid instead of failing */
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 8a9121a3a9a6a..f53f7054370d7 100644
+index 5b94161023664..c06dc6b33c839 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -224,6 +224,21 @@ struct btrfs_device {
-From ce4d2122a02179d86eff1fab2ce14608bbcd9b19 Mon Sep 17 00:00:00 2001
+From 498e825a967d96cc549d310fbad098402fc60224 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Wed, 8 Jul 2026 16:38:51 +0200
Subject: [PATCH 7/9] btrfs: add queue-adaptive read policy
3 files changed, 200 insertions(+), 19 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 41dabaa74d7cb..53acacb491d7c 100644
+index aa7cac991e684..953b47cbf38ea 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -11,6 +11,10 @@
#endif /* CONFIG_BTRFS_READ_POLICIES */
int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
-@@ -1998,17 +1999,45 @@ static ssize_t btrfs_devinfo_read_stats_show(struct kobject *kobj,
+@@ -1999,17 +2000,45 @@ static ssize_t btrfs_devinfo_read_stats_show(struct kobject *kobj,
unsigned long read_ios = device->bdev ?
part_stat_read(device->bdev, ios[READ]) : 0;
u64 health_avg = (u64)atomic64_read(&device->health_avg_ns);
BTRFS_ATTR(devid, read_stats, btrfs_devinfo_read_stats_show);
#endif /* CONFIG_BTRFS_PER_DEVICE_IO_STATS */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 41916fccbd534..e12cb8df96aa5 100644
+index d7bbe94175c2d..245ae1ef7b363 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -36,11 +36,9 @@
#define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
BTRFS_BLOCK_GROUP_RAID10 | \
-@@ -6652,9 +6650,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6665,9 +6663,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
return best_stripe;
}
#define BTRFS_READ_HEALTH_RECHECK_INTERVAL HZ
#define BTRFS_READ_HEALTH_MIN_SAMPLE_IOS 256ULL
-@@ -6662,6 +6659,15 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6675,6 +6672,15 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
* Refresh the cached windowed avg read latency for the current candidates.
* The avg is a delta against the previous checkpoint, not a lifetime average,
* so unrelated bulk reads can only skew the current window.
*/
static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
int num_stripes)
-@@ -6717,11 +6723,129 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6730,11 +6736,129 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
atomic64_set(&device->health_avg_ns, div64_u64(delta_wait, delta_ios));
atomic64_set(&device->health_check_ios, read_ios);
atomic64_set(&device->health_check_wait, read_wait);
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
-@@ -6823,10 +6947,6 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6836,10 +6960,6 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
}
#endif /* CONFIG_BTRFS_READ_POLICIES || CONFIG_BTRFS_PER_DEVICE_IO_STATS */
switch (policy) {
default:
/* Shouldn't happen, just warn and use pid instead of failing */
-@@ -6845,6 +6965,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6858,6 +6978,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
preferred_mirror = btrfs_read_earliest(fs_info, map, first,
num_stripes);
break;
preferred_mirror = btrfs_read_preferred(map, first, num_stripes);
break;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index f53f7054370d7..c03f4fadf6c02 100644
+index c06dc6b33c839..211b406ab3413 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -225,6 +225,14 @@ struct btrfs_device {
-From c433a2eb15764ab90d4dba71a7f35a79a6950f2a Mon Sep 17 00:00:00 2001
+From 5fa641efa7da094fc3322d307f9077f0f355e2dd Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sun, 12 Jul 2026 14:15:19 +0200
Subject: [PATCH 8/9] btrfs: scale adaptive queue guard with latency
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index e12cb8df96aa5..15d6fe7b7ab02 100644
+index 245ae1ef7b363..5cbec0f704129 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6650,7 +6650,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6663,7 +6663,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
return best_stripe;
}
#define BTRFS_READ_HEALTH_RECHECK_INTERVAL HZ
#define BTRFS_READ_HEALTH_MIN_SAMPLE_IOS 256ULL
-@@ -6745,14 +6746,14 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6758,14 +6759,14 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
* so it can never be stale from a different mirror pairing on a larger
* pool. If the in-flight winner is not derived-slow, done. If it is,
* it's only trusted when its in-flight lead over the best non-slow
*/
static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
struct btrfs_chunk_map *map, int first,
-@@ -6768,6 +6769,8 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
+@@ -6781,6 +6782,8 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
u64 best_healthy_inflight = U64_MAX;
u64 best_healthy_age = 0;
int best_healthy_stripe = -1;
btrfs_update_read_health(map, first, num_stripes);
-@@ -6835,7 +6838,21 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
+@@ -6848,7 +6851,21 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
return best_stripe;
if (best_healthy_stripe < 0)
return best_stripe; /* every candidate derived-slow, no alternative */
-From 18680c6045be2df3dd156e7cce746b6dcb9532b3 Mon Sep 17 00:00:00 2001
+From ccf8a6c6d49bbbf18675148d9af1a74d7512f6aa Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 18 Jul 2026 18:15:38 +0200
Subject: [PATCH 9/9] btrfs: count unstable read health snapshots
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 53acacb491d7c..e8d9ac077b87f 100644
+index 953b47cbf38ea..ec077db33ee4f 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
-@@ -2031,13 +2031,15 @@ static ssize_t btrfs_devinfo_read_stats_show(struct kobject *kobj,
+@@ -2032,13 +2032,15 @@ static ssize_t btrfs_devinfo_read_stats_show(struct kobject *kobj,
}
return scnprintf(buf, PAGE_SIZE,
BTRFS_ATTR(devid, read_stats, btrfs_devinfo_read_stats_show);
#endif /* CONFIG_BTRFS_PER_DEVICE_IO_STATS */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 15d6fe7b7ab02..5070cbf18ebca 100644
+index 5cbec0f704129..63b646073e423 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6696,6 +6696,10 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6709,6 +6709,10 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
checked_jiffies)
continue;
/*
* ios is updated before nsecs. Bracket the wait read to reject a
* completion that could pair newer wait time with an older io count.
-@@ -6703,8 +6707,12 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6716,8 +6720,12 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
read_ios_before = part_stat_read(device->bdev, ios[READ]);
read_wait = part_stat_read(device->bdev, nsecs[READ]);
read_ios = part_stat_read(device->bdev, ios[READ]);
checked_ios = atomic64_read(&device->health_check_ios);
checked_wait = atomic64_read(&device->health_check_wait);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index c03f4fadf6c02..6b5b71b370ba2 100644
+index 211b406ab3413..0234e95d845a0 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -230,6 +230,12 @@ struct btrfs_device {
-From 035bd2f8c1e3e4a22eeb388f4a35a558af9ea424 Mon Sep 17 00:00:00 2001
+From df4629dcf9ad9994c9d40ed0705d072cf58c05d5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 22 Oct 2026 21:56:55 -0400
+Date: Sun, 25 Oct 2026 03:13:48 -0400
Subject: [PATCH 0/4] btrfs: read repair and scrub after a transaction abort
To: linux-btrfs@vger.kernel.org
3 files changed, 47 insertions(+), 3 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From a0d12f2d99a3c84f17228e42e6b0c0c99a798711 Mon Sep 17 00:00:00 2001
+From 020df2f9856ef39d4216e12bbded5107c556506b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 02:16:13 -0400
Subject: [PATCH 1/4] btrfs: give the read repair bio an end_io for submit
-From 49af9ece472850eaf172378e92763600c4792be9 Mon Sep 17 00:00:00 2001
+From f05da064ee63244a7a89d77b6020e44433f2b5f2 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 14:31:46 -0400
Subject: [PATCH 2/4] btrfs: look up a repair read's csums in the same root as
-From 0f853995814e3ab2c39bc79e6ba8a97b2c0caae1 Mon Sep 17 00:00:00 2001
+From 7bc1870e25ad7e6ad2171059bafa41f656acdb9f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 14:31:48 -0400
Subject: [PATCH 3/4] btrfs: do not write back a read repair after a
-From 035bd2f8c1e3e4a22eeb388f4a35a558af9ea424 Mon Sep 17 00:00:00 2001
+From df4629dcf9ad9994c9d40ed0705d072cf58c05d5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 14:31:49 -0400
Subject: [PATCH 4/4] btrfs: scrub: do not write back repairs after a
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 479c0e037015a..6f27040d03eb2 100644
+index 98362c91bce43..4770fd5e8039c 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
-@@ -1213,10 +1213,14 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
+@@ -1221,10 +1221,14 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
/*
* Submit the repaired sectors. For zoned case, we cannot do repair
* in-place, but queue the bg to be relocated.
-From 43c8a1e60a5ae00c430c186df89d3ac462c08b96 Mon Sep 17 00:00:00 2001
+From 1c26761301041e16e2d84460c570ba92f4f66c58 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 17 Oct 2026 22:32:18 -0400
+Date: Sun, 25 Oct 2026 03:13:47 -0400
Subject: [PATCH 0/7] btrfs: dev-replace error accounting, cancel state, and an abort option
To: linux-btrfs@vger.kernel.org
5 files changed, 107 insertions(+), 14 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 065b371cedd915e03a3eddfc6fa39111e4b8dfb9 Mon Sep 17 00:00:00 2001
+From c4c21d9a929883dd69fcdfeae2a9e34ed627477c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 01:19:17 -0400
Subject: [PATCH 1/7] btrfs: commit the canceled state when a device replace
-From 8707d0c1fdbefadce170e75c3ade095e703ad29f Mon Sep 17 00:00:00 2001
+From 2b3a5ba66685a3924a2db09393c2c506dd772d8e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:33 -0400
Subject: [PATCH 2/7] btrfs: scrub: do not count write errors twice, or on the
1 file changed, 3 deletions(-)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 479c0e037015a..268b79ad7601d 100644
+index 98362c91bce43..5128e2989016b 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
-@@ -1257,9 +1257,6 @@ static void scrub_write_endio(struct btrfs_bio *bbio)
+@@ -1265,9 +1265,6 @@ static void scrub_write_endio(struct btrfs_bio *bbio)
bitmap_set(&stripe->write_error_bitmap, sector_nr,
bio_size >> fs_info->sectorsize_bits);
spin_unlock_irqrestore(&stripe->write_error_lock, flags);
-From ad55d5c186f5dc1e6078583063b7b680f84ce413 Mon Sep 17 00:00:00 2001
+From f217a9f8ee76116618ddf8ef59358c69318ba8c5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:34 -0400
Subject: [PATCH 3/7] btrfs: dev-replace: count uncorrectable read errors
1 file changed, 4 insertions(+)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index 268b79ad7601d..d9f0a260b7981 100644
+index 5128e2989016b..88b1f5d43ce89 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
-@@ -1968,6 +1968,10 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+@@ -1984,6 +1984,10 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
has_extent = scrub_bitmap_read_has_extent(stripe);
error = scrub_bitmap_read_error(stripe);
-From f8524757e3ff31fefe7c8b61a4315bb224034978 Mon Sep 17 00:00:00 2001
+From 9488e7f09b4faec770edaf9eda837801d15109f5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 13:58:22 -0400
Subject: [PATCH 4/7] btrfs: dev-replace: do not warn when a resumed replace
-From 6289b310515269227ca61d4ce470a0440a486bdc Mon Sep 17 00:00:00 2001
+From 92f953d555b6e195808b2a299709c2462a0e1aa9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:34 -0400
Subject: [PATCH 5/7] btrfs: dev-replace: count write errors to the target
1 file changed, 19 insertions(+)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index d9f0a260b7981..ffba93f242763 100644
+index 88b1f5d43ce89..1a2bde86c305a 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
-@@ -1966,6 +1966,14 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+@@ -1982,6 +1982,14 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
ASSERT(stripe->dev == fs_info->dev_replace.srcdev);
has_extent = scrub_bitmap_read_has_extent(stripe);
error = scrub_bitmap_read_error(stripe);
bitmap_and(&error, &error, &has_extent, stripe->nr_sectors);
-@@ -1982,6 +1990,17 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
+@@ -1998,6 +2006,17 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
stripe = &sctx->stripes[i];
wait_scrub_stripe_io(stripe);
-From ac61cc3d2484868f5d3f18747768721d622b7d6d Mon Sep 17 00:00:00 2001
+From c010dc2e430ea26fa70d328e45b59da13f217301 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:34 -0400
Subject: [PATCH 6/7] btrfs: dev-replace: report the progress of a canceled
-From 43c8a1e60a5ae00c430c186df89d3ac462c08b96 Mon Sep 17 00:00:00 2001
+From 1c26761301041e16e2d84460c570ba92f4f66c58 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 13:02:21 -0400
Subject: [PATCH 7/7] btrfs: dev-replace: optionally abort on uncorrectable
int is_valid;
int item_needs_writeback;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
-index ffba93f242763..f36299ed6bb0c 100644
+index 1a2bde86c305a..b443c80d8e72f 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
-@@ -2920,6 +2920,16 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
+@@ -2957,6 +2957,16 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
ret = -EIO;
break;
}
-From 8763f9e2126d43bc4504612d63f08807aec86a7e Mon Sep 17 00:00:00 2001
+From 2d41f2a9495dc15edd86861c4e57dcfd6bba3bf6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Wed, 21 Oct 2026 19:15:12 -0400
+Date: Sun, 25 Oct 2026 03:13:48 -0400
Subject: [PATCH 0/1] btrfs: resize: allow shrinking a missing device
To: linux-btrfs@vger.kernel.org
1 file changed, 28 insertions(+), 4 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From 8763f9e2126d43bc4504612d63f08807aec86a7e Mon Sep 17 00:00:00 2001
+From 2d41f2a9495dc15edd86861c4e57dcfd6bba3bf6 Mon Sep 17 00:00:00 2001
From: Qu Wenruo <wqu@suse.com>
Date: Mon, 18 Nov 2019 15:05:25 +0800
Subject: [PATCH 1/1] btrfs: resize: allow shrinking a missing device
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index dec015e6bd29a..ceec0d43123c7 100644
+index ac070c745b0eb..b7ad8289108a4 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1033,6 +1033,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
-From a23064467620f3d39e4cc8c71b5ae12a9bab7572 Mon Sep 17 00:00:00 2001
+From bc8cd9cac405fb573a08f798266215560f19b234 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 22 Oct 2026 07:29:47 -0400
+Date: Sun, 25 Oct 2026 03:13:40 -0400
Subject: [RFC PATCH 000/116] btrfs: close the raid56 write hole for datacow with stripe-exclusive allocation
To: linux-btrfs@vger.kernel.org
Prerequisites and related series
================================
-The series applies on its own to the base (0c48d26d46bd). It was
+The series applies on its own to the base (99bc6552614f). It was
developed and tested on top of these separate series, and the
guarantees below are stated with them applied. Each fixes a
pre-existing bug that this series' tests found:
fs/btrfs/raid56.h | 34 +
fs/btrfs/relocation.c | 302 ++-
fs/btrfs/relocation.h | 2 +-
- fs/btrfs/space-info.c | 339 ++-
+ fs/btrfs/space-info.c | 340 ++-
fs/btrfs/space-info.h | 87 +-
fs/btrfs/super.c | 42 +
fs/btrfs/sysfs.c | 428 ++++
fs/btrfs/zoned.c | 10 -
fs/btrfs/zoned.h | 3 -
include/trace/events/btrfs.h | 60 +
- 42 files changed, 10552 insertions(+), 133 deletions(-)
+ 42 files changed, 10553 insertions(+), 133 deletions(-)
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+base-commit: 99bc6552614f6b25a4a6f07789300d65d384d6ed
--
2.47.3
-From f8aefd3a65eef1fc6ca498e3f7d34fd24bd2d1aa Mon Sep 17 00:00:00 2001
+From 9b74e9eed7b1269451a10e04c2dbd5ffaf04f20b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
Subject: [RFC PATCH 001/116] btrfs: add btrfs_claim_free_stripe_run() for
3 files changed, 376 insertions(+)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 2a40167c3fb65..3f0f25dff0c81 100644
+index bff6e5b372d6c..c776d36b69776 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1874,6 +1874,171 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,
+@@ -1884,6 +1884,171 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,
return ret;
}
-From e4a454e34f91c3246fb8a922f3e472b546622e33 Mon Sep 17 00:00:00 2001
+From edb82fe6c54fbdac3bdb6a7db37bc79827b5117d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
Subject: [RFC PATCH 002/116] btrfs: add open stripe run tracking for
6 files changed, 519 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index b23a543bb3823..4235c924fdaac 100644
+index 027830a53f7dc..9a5d80f77f3f7 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -440,6 +440,350 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group *bg)
struct btrfs_caching_control *btrfs_get_caching_control(
struct btrfs_block_group *cache)
{
-@@ -2432,9 +2776,13 @@ static struct btrfs_block_group *btrfs_create_block_group(
+@@ -2435,9 +2779,13 @@ static struct btrfs_block_group *btrfs_create_block_group(
refcount_set(&cache->refs, 1);
spin_lock_init(&cache->lock);
u64 bytenr);
void btrfs_dec_nocow_writers(struct btrfs_block_group *bg);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index c45cda4290d5a..8626dc042944c 100644
+index c628c5081d923..ccefc67fcbd68 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2783,6 +2783,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2803,6 +2803,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->delayed_iputs);
INIT_LIST_HEAD(&fs_info->delalloc_roots);
INIT_LIST_HEAD(&fs_info->caching_block_groups);
-From a240872477979ccf01ce59b6481be002eac1d59d Mon Sep 17 00:00:00 2001
+From 37db945f876b595303f82b8a24d1bb29a8771479 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
Subject: [RFC PATCH 003/116] btrfs: add the stripe_alloc allocation policy for
8 files changed, 322 insertions(+), 97 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4235c924fdaac..7ec2feb50f85a 100644
+index 9a5d80f77f3f7..7a1b2c5b91484 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -491,6 +491,7 @@ struct btrfs_open_stripe_run {
path = btrfs_alloc_path();
if (unlikely(!path)) {
-@@ -3578,6 +3658,14 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
+@@ -3581,6 +3661,14 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
mutex_unlock(&fs_info->ro_block_group_mutex);
btrfs_end_transaction(trans);
out:
cache->full_stripe_len = orig_fsl;
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
-index 1cda88332284e..d653e84bbdd13 100644
+index 1fa855a0c31a8..4082ac106551e 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
-@@ -2771,16 +2771,6 @@ void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg,
+@@ -2797,16 +2797,6 @@ void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg,
queue_work(system_dfl_wq, &bg->zone_finish_work);
}
-From 34e5adb74d1c65145b60d1a79aac6ba32cf9f5a2 Mon Sep 17 00:00:00 2001
+From 26dd0509689daee7517c91dc14320aba5f01fde2 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
Subject: [RFC PATCH 004/116] btrfs: stripe_alloc: control the policy with a
4 files changed, 162 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 7ec2feb50f85a..2fdfb4ba67ca6 100644
+index 7a1b2c5b91484..242a4b074e71d 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -760,6 +760,76 @@ static bool bg_open_stripes_settled(struct btrfs_block_group *bg, u64 seq)
void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg);
void btrfs_release_data_reloc_bg(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 8626dc042944c..6cc4c609a7d8b 100644
+index ccefc67fcbd68..7540f7d9e3de1 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -3742,6 +3742,30 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
+@@ -3762,6 +3762,30 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
goto fail_qgroup;
}
-From f4900f9d5af6f1fcf7328e5c15eafef33ac4e37d Mon Sep 17 00:00:00 2001
+From fddee442cc1300ee68be619ac1df4cbb9975eab6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
Subject: [RFC PATCH 005/116] btrfs: report stripe run data IO through the
7 files changed, 168 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 2fdfb4ba67ca6..29b3671f2f03f 100644
+index 242a4b074e71d..f4453da153f6a 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -682,6 +682,57 @@ void btrfs_open_stripe_write_done(struct btrfs_block_group *bg, u64 start,
const struct extent_buffer *eb);
int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7c6f6dbfa7798..b91c557441bde 100644
+index b071ed59a583f..5803f5d95d654 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -3400,7 +3400,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
+@@ -3398,7 +3398,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
ordered_extent->disk_bytenr,
ordered_extent->disk_num_bytes,
NULL, true);
ordered_extent->disk_bytenr,
ordered_extent->disk_num_bytes, true);
/*
-@@ -9200,6 +9200,17 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9198,6 +9198,17 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
min_size, 0, *alloc_hint, &ins, true, false);
if (ret)
break;
/*
* We've reserved this space, and thus converted it from
-@@ -9222,8 +9233,8 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9220,8 +9231,8 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
btrfs_dec_block_group_reservations(fs_info, ins.objectid);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
-From dc05aa382bdb79b8f81db968b8d96236d5350ebb Mon Sep 17 00:00:00 2001
+From 3a96b8a5cf6b3ca15e47511ad7e178eed3826067 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
Subject: [RFC PATCH 006/116] btrfs: retire stripe runs at commit and gate
9 files changed, 228 insertions(+), 44 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 29b3671f2f03f..0e7fc096245c3 100644
+index f4453da153f6a..d28895e03f766 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -457,24 +457,28 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group *bg)
/*
* Drop the dedication of a block group to data relocation. Shared by the
* zoned allocator and the stripe allocation policy; both dedicate one
-@@ -4908,6 +4946,14 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
+@@ -4911,6 +4949,14 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
struct btrfs_caching_control *caching_ctl;
struct rb_node *n;
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b91c557441bde..d65b79764d940 100644
+index 5803f5d95d654..b69cc44f58d70 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1869,6 +1869,18 @@ static int can_nocow_file_extent(struct btrfs_path *path,
/*
* Force COW if csums exist in the range. This ensures that csums for a
* given extent are either valid or do not exist.
-@@ -3268,6 +3280,55 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
+@@ -3262,6 +3274,55 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
goto out;
}
/* Only partially filled stripes remain: nothing left to claim. */
ret = btrfs_alloc_from_open_stripe(cache, sectorsize,
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 7431a06f168da..905d3125ad32a 100644
+index d265fac023e58..c2e9a4fd69d3b 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -377,6 +377,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
+@@ -367,6 +367,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
atomic_set(&cur_trans->pending_ordered, 0);
init_waitqueue_head(&cur_trans->pending_wait);
atomic_set(&cur_trans->num_writers, 1);
extwriter_counter_init(cur_trans, type);
init_waitqueue_head(&cur_trans->writer_wait);
init_waitqueue_head(&cur_trans->commit_wait);
-@@ -564,6 +565,31 @@ static inline int is_transaction_blocked(struct btrfs_transaction *trans)
+@@ -554,6 +555,31 @@ static inline int is_transaction_blocked(struct btrfs_transaction *trans)
!TRANS_ABORTED(trans));
}
/* wait for commit against the current transaction to become unblocked
* when this is done, it is safe to start a new transaction, but the current
* transaction might not be fully on disk.
-@@ -2442,6 +2468,27 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2426,6 +2452,27 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
wait_event(cur_trans->pending_wait,
atomic_read(&cur_trans->pending_ordered) == 0);
-From c332d36b889a12ff768cdd448c5b31f72374837e Mon Sep 17 00:00:00 2001
+From 98133152306858e37e4e7d8cf05b155e992252d3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
Subject: [RFC PATCH 007/116] btrfs: add a write-hole invariant checker to the
4 files changed, 80 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 0e7fc096245c3..bfdbc7b8ff1d5 100644
+index d28895e03f766..aa363733b4df4 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -978,6 +978,57 @@ bool btrfs_stripe_alloc_forces_cow(struct btrfs_fs_info *fs_info, u64 bytenr)
ffe_ctl->search_start = offset;
return 0;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5ec31299f1c30..75154f43261ac 100644
+index 59aad807f98ab..4be6361413f21 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -21,6 +21,7 @@
/* set when additional merges to this rbio are not allowed */
#define RBIO_RMW_LOCKED_BIT 1
-@@ -2451,6 +2452,16 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2468,6 +2469,16 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
int sectornr;
int ret = 0;
-From ee439d57937755a384015dabef3bd5fea72283c7 Mon Sep 17 00:00:00 2001
+From 2f1ee8114d2451c80045b6bea0de84f7d3ca9e13 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
Subject: [RFC PATCH 008/116] btrfs: account stripe_alloc trapped free space
9 files changed, 474 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index bfdbc7b8ff1d5..1a6aa23920a3b 100644
+index aa363733b4df4..03ecf86d707f6 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -855,6 +855,38 @@ int btrfs_stripe_alloc_check_support(struct btrfs_fs_info *fs_info)
btrfs_remove_free_space_cache(block_group);
spin_lock(&block_group->space_info->lock);
-@@ -2066,12 +2184,26 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -2068,12 +2186,26 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
ret = 0;
} else if (sinfo->flags & BTRFS_BLOCK_GROUP_DATA) {
u64 sinfo_used = btrfs_space_info_used(sinfo, true);
ret = 0;
} else {
/*
-@@ -2098,6 +2230,14 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -2100,6 +2232,14 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
out:
spin_unlock(&cache->lock);
spin_unlock(&sinfo->lock);
if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) {
btrfs_info(cache->fs_info,
"unable to make block group %llu ro", cache->start);
-@@ -3223,6 +3363,15 @@ static int read_one_block_group(struct btrfs_fs_info *info,
+@@ -3226,6 +3366,15 @@ static int read_one_block_group(struct btrfs_fs_info *info,
trace_btrfs_add_block_group(info, cache, 0);
- btrfs_add_bg_to_space_info(info, cache);
+ btrfs_add_bg_to_space_info(cache);
+ /*
+ * Full or empty groups are marked cached above without going through
set_avail_alloc_bits(info, cache->flags);
if (btrfs_chunk_writeable(info, cache->start)) {
if (cache->used == 0 && cache->remap_bytes == 0) {
-@@ -3739,6 +3888,9 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
+@@ -3742,6 +3891,9 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
btrfs_link_bg_list(cache, &trans->new_bgs);
btrfs_inc_delayed_refs_rsv_bg_inserts(fs_info);
set_avail_alloc_bits(fs_info, type);
return cache;
}
-@@ -3882,6 +4034,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
+@@ -3885,6 +4037,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
{
struct btrfs_space_info *sinfo = cache->space_info;
BUG_ON(!cache->ro);
-@@ -3899,9 +4052,18 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
+@@ -3902,9 +4055,18 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
}
sinfo->bytes_readonly -= btrfs_block_group_available_space(cache);
list_del_init(&cache->ro_list);
void btrfs_stripe_check_write(struct btrfs_fs_info *fs_info,
u64 full_stripe_start, bool sub_stripe);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 3f0f25dff0c81..b85084f8c8698 100644
+index c776d36b69776..9837562d348a5 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1481,6 +1481,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
+@@ -1491,6 +1491,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
return 0;
}
int btrfs_add_free_space(struct btrfs_block_group *block_group,
u64 bytenr, u64 size)
{
-@@ -1496,6 +1498,7 @@ int btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1506,6 +1508,7 @@ int btrfs_add_free_space(struct btrfs_block_group *block_group,
if (btrfs_test_opt(block_group->fs_info, DISCARD_SYNC))
trim_state = BTRFS_TRIM_STATE_TRIMMED;
return __btrfs_add_free_space(block_group, bytenr, size, trim_state);
}
-@@ -1874,6 +1877,218 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,
+@@ -1884,6 +1887,218 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,
return ret;
}
/*
* Align an offset up to the next full stripe boundary. Full stripe geometry
* is relative to the start of the block group, which is not necessarily
-@@ -2033,6 +2248,8 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2043,6 +2258,8 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
btrfs_discard_update_discardable(block_group);
spin_unlock(&ctl->tree_lock);
u64 bytes);
int btrfs_find_space_cluster(struct btrfs_block_group *block_group,
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index d0130c8ba3dda..ef5a0ea9039db 100644
+index 0456b0d2d1b4a..51098227f9171 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -150,6 +150,12 @@ struct btrfs_space_info {
}
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index acb704b20c2be..4416fd622019d 100644
+index b424cc836bd4a..a64d9cd48d12e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
-@@ -1733,6 +1733,24 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
+@@ -1735,6 +1735,24 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
factor = btrfs_bg_type_to_factor(
btrfs_raid_array[i].bg_flag);
}
/*
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..9bb5ee9217318 100644
+index 89b0a4ef4063e..357c669e6ea15 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -778,6 +778,35 @@ static ssize_t btrfs_force_chunk_alloc_store(struct kobject *kobj,
NULL,
};
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 905d3125ad32a..0dccce2c57c9d 100644
+index c2e9a4fd69d3b..4f781df772202 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -2700,6 +2700,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2684,6 +2684,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
if (unlikely(ret))
goto scrub_continue;
-From a3f76d9a2a78b3892650a7be8380d418b53e761a Mon Sep 17 00:00:00 2001
+From 427ea2e48fe7637468e2647834a26d2c9b069800 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
Subject: [RFC PATCH 009/116] btrfs: stripe_alloc: keep an open run per size
3 files changed, 176 insertions(+), 67 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 1a6aa23920a3b..4388d21cdfaf8 100644
+index 03ecf86d707f6..0141b06ed0639 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -504,12 +504,30 @@ static bool open_stripe_run_drained(const struct btrfs_open_stripe_run *run)
-From 05efb9e0701c1438661bf6ac88349252b9a2c8ee Mon Sep 17 00:00:00 2001
+From 03b190f8691326607d8d2ef286b54bde277fe7bc Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
Subject: [RFC PATCH 010/116] btrfs: stripe_alloc: grow the frontier run
2 files changed, 76 insertions(+), 29 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4388d21cdfaf8..480af5c67d538 100644
+index 0141b06ed0639..f88fc9fe9bd10 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -589,8 +589,11 @@ static u64 stripe_run_place(struct btrfs_block_group *bg,
-From 19fdab82489824f188e6656c429f9f44d633c593 Mon Sep 17 00:00:00 2001
+From 760a3334bc0d471e65f3dda103c4f4dcb6518588 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:29 -0400
Subject: [RFC PATCH 011/116] btrfs: raid56: batch stripe_alloc partial writes
5 files changed, 448 insertions(+), 113 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 480af5c67d538..6c2131985c3b7 100644
+index f88fc9fe9bd10..a10d59bb8aa49 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -770,6 +770,152 @@ int btrfs_alloc_from_open_stripe(struct btrfs_block_group *bg, u64 num_bytes,
}
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 75154f43261ac..1503dcaa0223c 100644
+index 4be6361413f21..279c15cf229e8 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -37,8 +37,28 @@
h = table->table;
-@@ -563,6 +596,8 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
+@@ -567,6 +600,8 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
{
if (!info->stripe_hash_table)
return;
btrfs_clear_rbio_cache(info);
kvfree(info->stripe_hash_table);
info->stripe_hash_table = NULL;
-@@ -687,6 +722,196 @@ static int rbio_can_merge(struct btrfs_raid_bio *last,
+@@ -692,6 +727,196 @@ static int rbio_can_merge(struct btrfs_raid_bio *last,
return 1;
}
+ spin_lock(&table->parked_lock);
+ list_for_each_entry_safe(rbio, tmp, &table->parked, parked_node) {
+ u64 rbio_start = rbio->bioc->full_stripe_logical;
-+ u64 rbio_len = (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
++ u64 rbio_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
+
+ if (rbio_start + rbio_len <= start ||
+ (num_bytes != U64_MAX && rbio_start >= start + num_bytes))
/* Return the sector index for @stripe_nr and @sector_nr. */
static unsigned int rbio_sector_index(const struct btrfs_raid_bio *rbio,
unsigned int stripe_nr,
-@@ -802,7 +1027,35 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+@@ -807,7 +1032,35 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
/* Can we merge into the lock owner? */
if (rbio_can_merge(cur, rbio)) {
+ */
+ if (test_bit(RBIO_PARKED_BIT, &cur->flags)) {
+ if (cur->bio_list_bytes ==
-+ cur->nr_data * BTRFS_STRIPE_LEN) {
++ cur->nr_data * cur->bioc->stripe_len) {
+ unpark_full_rbio(cur);
+ } else if (sync) {
+ struct btrfs_stripe_hash_table *table =
spin_unlock(&cur->bio_list_lock);
freeit = rbio;
ret = 1;
-@@ -1101,6 +1354,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
+@@ -1107,6 +1360,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
spin_lock_init(&rbio->bio_list_lock);
INIT_LIST_HEAD(&rbio->stripe_cache);
INIT_LIST_HEAD(&rbio->hash_list);
btrfs_get_bioc(bioc);
rbio->bioc = bioc;
rbio->nr_pages = num_pages;
-@@ -2546,8 +2800,11 @@ static void rmw_rbio_work(struct work_struct *work)
+@@ -2563,8 +2817,11 @@ static void rmw_rbio_work(struct work_struct *work)
struct btrfs_raid_bio *rbio;
rbio = container_of(work, struct btrfs_raid_bio, work);
static void rmw_rbio_work_locked(struct work_struct *work)
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 8542648199f1a..07ba71ae8e54f 100644
+index 8700910b8dc99..f5b8d788b1fff 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -132,6 +132,15 @@ struct btrfs_raid_bio {
+@@ -130,6 +130,15 @@ struct btrfs_raid_bio {
*/
struct list_head plug_list;
/* Flags that tell us if it is safe to merge with this bio. */
unsigned long flags;
-@@ -287,5 +296,7 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+@@ -282,5 +291,7 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
-From d012dbc97bfc5dc275a789a7e3c464efa09851f6 Mon Sep 17 00:00:00 2001
+From 39bf390edbf806623171491e8928f1c26b15062a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:30 -0400
Subject: [RFC PATCH 012/116] btrfs: stripe_alloc: never claim stripes covered
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 6c2131985c3b7..9f8f73dbfe0a0 100644
+index a10d59bb8aa49..7e820fd50bb03 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -770,6 +770,40 @@ int btrfs_alloc_from_open_stripe(struct btrfs_block_group *bg, u64 num_bytes,
int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info);
void btrfs_disable_stripe_alloc(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index b85084f8c8698..6c086dbe1bd41 100644
+index 9837562d348a5..4a1db014b19b0 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2201,7 +2201,9 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2211,7 +2211,9 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
if (entry->bitmap) {
if (find_stripe_run_in_bitmap(ctl, entry, want_bytes,
goto found;
continue;
}
-@@ -2212,6 +2214,9 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2222,6 +2224,9 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
run_len = min(want_bytes,
div64_u64(entry->offset + entry->bytes - run_start,
fsl) * fsl);
-From 14839547353dd2ff06d13c3a321b286878abf7c1 Mon Sep 17 00:00:00 2001
+From 6841c0aaa73bc51fea259a58d46b66268d6cd7ab Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:31 -0400
Subject: [RFC PATCH 013/116] btrfs: stripe_alloc: settle a logged extent's
3 files changed, 111 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 9f8f73dbfe0a0..cb632a48c8851 100644
+index 7e820fd50bb03..c5f7df4ca8f3d 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -804,6 +804,86 @@ bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info);
void btrfs_disable_stripe_alloc(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
-index 1d9dfb63fc5a4..51aeb3ed680e9 100644
+index e50f924bca59f..6aa8db5b1044e 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
-@@ -4847,6 +4847,23 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
- inode->last_reflink_trans < trans->transid)
- continue;
+@@ -4875,6 +4875,23 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
+ return BTRFS_LOG_FORCE_COMMIT;
+ }
+ /*
+ * New data extent made durable by this log commit: settle its
if (skip_csum)
goto add_to_batch;
-@@ -5132,6 +5149,18 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
+@@ -5163,6 +5180,18 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
block_len = em->disk_num_bytes;
compress_type = btrfs_extent_map_compression(em);
-From 36f2da531ea7492f5eadadcbcc1865d5e7bfec58 Mon Sep 17 00:00:00 2001
+From c92a00aaf5df8f99c84022b2efbf24badeb03954 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:31 -0400
Subject: [RFC PATCH 014/116] btrfs: stripe_alloc: private per-inode stripe
9 files changed, 245 insertions(+), 31 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index cb632a48c8851..3b2379ebb60c4 100644
+index c5f7df4ca8f3d..25cb8dac15a9e 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -495,6 +495,7 @@ struct btrfs_open_stripe_run {
/*
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index d65b79764d940..d39947e779a4f 100644
+index b69cc44f58d70..faa45e7231e79 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1070,7 +1070,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
if (ret < 0) {
*ret_alloc_size = cur_len;
return ret;
-@@ -8096,6 +8097,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
+@@ -8094,6 +8095,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
ei->last_unlink_trans = 0;
ei->last_reflink_trans = 0;
ei->last_log_commit = 0;
spin_lock_init(&ei->lock);
ei->outstanding_extents = 0;
-@@ -9257,7 +9259,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9255,7 +9257,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
* sized chunks.
*/
cur_bytes = min(cur_bytes, last_alloc);
min_size, 0, *alloc_hint, &ins, true, false);
if (ret)
break;
-@@ -10094,7 +10096,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10092,7 +10094,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
}
}
-From 720d3e3ab3b0c4ed892edddf9a210034a30dd06b Mon Sep 17 00:00:00 2001
+From 4a26f6f8349a32272a71baa5f307b73e65e7998b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:37 -0400
Subject: [RFC PATCH 015/116] btrfs: stripe_alloc: carry an inode's log tail
8 files changed, 295 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 3b2379ebb60c4..f70adc063a22d 100644
+index 25cb8dac15a9e..be8aa2fc103f8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -937,6 +937,63 @@ static bool stripe_log_range_settled(struct btrfs_block_group *bg, u64 bytenr)
* Start of the last extent allocated from this inode's private
* LOG-class stripe run (see BTRFS_INODE_LOG_ALLOC). Advisory only:
diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
-index 7010d714cfe10..6c460dcc431a6 100644
+index cbc532b49c67d..d383a5abe7e2b 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
-@@ -1254,6 +1254,157 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
+@@ -1263,6 +1263,157 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
return ret;
}
* Before we acquired the inode's lock and the mmap lock, someone may
* have dirtied more pages in the target range. We need to make sure
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index d39947e779a4f..792b834005fa5 100644
+index faa45e7231e79..afe0cc331deb8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -8098,6 +8098,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
+@@ -8096,6 +8096,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
ei->last_reflink_trans = 0;
ei->last_log_commit = 0;
ei->log_run_hint = 0;
spin_lock_init(&ei->lock);
ei->outstanding_extents = 0;
-@@ -8137,6 +8138,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
+@@ -8135,6 +8136,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
void btrfs_test_destroy_inode(struct inode *inode)
{
btrfs_drop_extent_map_range(BTRFS_I(inode), 0, (u64)-1, false);
kfree(BTRFS_I(inode)->file_extent_tree);
kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
}
-@@ -8144,6 +8146,7 @@ void btrfs_test_destroy_inode(struct inode *inode)
+@@ -8142,6 +8144,7 @@ void btrfs_test_destroy_inode(struct inode *inode)
void btrfs_free_inode(struct inode *inode)
{
kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
}
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
-index 51aeb3ed680e9..e9b688024aed6 100644
+index 6aa8db5b1044e..d902d169680a4 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
-@@ -4859,9 +4859,12 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
+@@ -4887,9 +4887,12 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
disk_num_bytes =
btrfs_file_extent_disk_num_bytes(src, extent);
if (disk_bytenr)
}
if (skip_csum)
-@@ -5158,8 +5161,10 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
+@@ -5189,8 +5192,10 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
*/
if (!(em->flags & EXTENT_FLAG_PREALLOC) &&
em->disk_bytenr < EXTENT_MAP_LAST_BYTE)
-From bdc754626ebf4622fdb443bf7618eb55d626bf1c Mon Sep 17 00:00:00 2001
+From 4125cef50ff22f035dce63a99a06c3bddb8d6250 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:38 -0400
Subject: [RFC PATCH 016/116] btrfs: stripe_alloc: kick parked rbios before the
-From a737dc4313e4b2f0d01d818cb220ae1b79682676 Mon Sep 17 00:00:00 2001
+From d751a574bd21ed06cfd5ba7163822ec3c07249e7 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:38 -0400
Subject: [RFC PATCH 017/116] btrfs: raid56: pad sub-stripe writes to full
3 files changed, 144 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index f70adc063a22d..04bd5feec1f1c 100644
+index be8aa2fc103f8..2e5bb7491363a 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -919,6 +919,49 @@ bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
u64 file_len, u64 bytenr, u64 num_bytes);
int btrfs_stripe_alloc_check_support(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 1503dcaa0223c..34098e7414051 100644
+index 279c15cf229e8..30c664babecd3 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -45,6 +45,16 @@
#define RBIO_CACHE_SIZE 1024
/*
-@@ -1724,7 +1734,12 @@ static int rmw_assemble_write_bios(struct btrfs_raid_bio *rbio,
+@@ -1737,7 +1747,12 @@ static int rmw_assemble_write_bios(struct btrfs_raid_bio *rbio,
continue;
if (stripe < rbio->nr_data) {
if (paddrs == NULL)
continue;
} else {
-@@ -2677,6 +2692,73 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2694,6 +2709,73 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
}
}
+ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
+ const u64 stripe_start = rbio->bioc->full_stripe_logical;
+ const u32 sectorsize = fs_info->sectorsize;
-+ const u64 stripe_len = (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
++ const u64 stripe_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
+ u64 pad_from;
+ int i;
+
/*
* To determine if we need to read any sector from the disk.
* Should only be utilized in RMW path, to skip cached rbio.
-@@ -2727,8 +2809,22 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2744,8 +2826,22 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
/*
* Either full stripe write, or we have every data sector already
* cached, can go to write path immediately.
-From 56d65bde49a8f81bcbcbea7083ff885ceb6edeb7 Mon Sep 17 00:00:00 2001
+From 56f960dce657f0f9a18ba36bc984d1d967365e67 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:39 -0400
Subject: [RFC PATCH 018/116] btrfs: stripe_alloc: isolate nodatacow and
7 files changed, 72 insertions(+), 38 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 04bd5feec1f1c..4e9c8c6c4be81 100644
+index 2e5bb7491363a..490a2bd401c72 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -793,6 +793,7 @@ int btrfs_alloc_from_open_stripe(struct btrfs_block_group *bg, u64 num_bytes,
struct extent_buffer *buf, bool full_backref);
int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 792b834005fa5..ea95ebd1b17f1 100644
+index afe0cc331deb8..0aaa5a568ba71 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1072,7 +1072,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
if (ret < 0) {
*ret_alloc_size = cur_len;
return ret;
-@@ -9262,8 +9262,9 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9260,8 +9260,9 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
* sized chunks.
*/
cur_bytes = min(cur_bytes, last_alloc);
if (ret)
break;
/*
-@@ -10100,7 +10101,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10098,7 +10099,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
}
ret = btrfs_reserve_extent(root, inode, disk_num_bytes, disk_num_bytes,
-From 7a2128a6af7b447537f4ce836354b9071f914cc4 Mon Sep 17 00:00:00 2001
+From bd29e332429ed54addde7e66642710d851633b10 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:40 -0400
Subject: [RFC PATCH 019/116] btrfs: stripe_alloc: allow-rmw policy, and
8 files changed, 368 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4e9c8c6c4be81..e2d9b32107a41 100644
+index 490a2bd401c72..88fcd964b7036 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -919,6 +919,247 @@ bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
u64 file_len, u64 bytenr, u64 num_bytes);
int btrfs_stripe_alloc_check_support(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
-index 6c460dcc431a6..d2d5f41b578e6 100644
+index d383a5abe7e2b..918a82f6b9035 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
-@@ -1383,6 +1383,9 @@ void btrfs_carry_log_tail(struct btrfs_inode *inode)
+@@ -1392,6 +1392,9 @@ void btrfs_carry_log_tail(struct btrfs_inode *inode)
if (!btrfs_test_opt(inode->root->fs_info, STRIPE_ALLOC))
return;
{
clear_and_wake_up_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index ea95ebd1b17f1..6cb5c292899f0 100644
+index 0aaa5a568ba71..7a9cc1ba095c6 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1877,9 +1877,18 @@ static int can_nocow_file_extent(struct btrfs_path *path,
-From ff24d23dc643075ff828e20456e26b7fafb21566 Mon Sep 17 00:00:00 2001
+From efce6f5f7eaa8a46e982e2b61d0acddec70c5f6a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:41 -0400
Subject: [RFC PATCH 020/116] btrfs: stripe_alloc: persist nocow runs across
6 files changed, 289 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index e2d9b32107a41..42c50bfca2ee5 100644
+index 88fcd964b7036..c7b21de26540e 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -487,6 +487,12 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group *bg)
}
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 6c086dbe1bd41..2e7bf3505d1c7 100644
+index 4a1db014b19b0..118fced160032 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2157,6 +2157,68 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
+@@ -2167,6 +2167,68 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
* Returns 0 on success, -ENOSPC if no aligned fully-free stripe is present
* in this block group.
*/
u64 want_bytes, u64 *start, u64 *len);
void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *block_group);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 6cb5c292899f0..511f4aa7f3c19 100644
+index 7a9cc1ba095c6..d243e078435b5 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -5671,6 +5671,7 @@ void btrfs_evict_inode(struct inode *inode)
+@@ -5669,6 +5669,7 @@ void btrfs_evict_inode(struct inode *inode)
goto clear_inode;
fs_info = inode_to_fs_info(inode);
-From aee560fcabf96893e8ec946cfcb4693942e697c3 Mon Sep 17 00:00:00 2001
+From ddcf7587cde779f7f02de4e59be48768ad92b0fc Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:42 -0400
Subject: [RFC PATCH 021/116] btrfs: raid56: do not park sync writes into nocow
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 34098e7414051..5430824cd80b8 100644
+index 30c664babecd3..eeeef54635e60 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -779,8 +779,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -784,8 +784,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
struct btrfs_stripe_hash_table *table = fs_info->stripe_hash_table;
unsigned int timeout_ms = BTRFS_RBIO_PARK_TIMEOUT_MS;
return false;
spin_lock(&rbio->bio_list_lock);
-@@ -788,6 +791,17 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -793,6 +796,17 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
timeout_ms = BTRFS_RBIO_PARK_SYNC_TIMEOUT_MS;
spin_unlock(&rbio->bio_list_lock);
-From 45a865e1a62c17737f0839e3178dd45790b9999a Mon Sep 17 00:00:00 2001
+From 9218820fa26e920552140a8015c978c674b13bb6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:43 -0400
Subject: [RFC PATCH 022/116] btrfs: raid56: expose parking statistics in sysfs
u32 stripe_rmw_opt;
u32 stripe_rmw_prop;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5430824cd80b8..6d1c4127b7e23 100644
+index eeeef54635e60..4f3968313f501 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -55,6 +55,9 @@
#define RBIO_CACHE_SIZE 1024
/*
-@@ -494,6 +497,9 @@ static void steal_rbio(struct btrfs_raid_bio *src, struct btrfs_raid_bio *dest)
+@@ -498,6 +501,9 @@ static void steal_rbio(struct btrfs_raid_bio *src, struct btrfs_raid_bio *dest)
static void merge_rbio(struct btrfs_raid_bio *dest,
struct btrfs_raid_bio *victim)
{
bio_list_merge_init(&dest->bio_list, &victim->bio_list);
dest->bio_list_bytes += victim->bio_list_bytes;
/* Also inherit the bitmaps from @victim. */
-@@ -804,6 +810,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -809,6 +815,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
spin_lock(&table->parked_lock);
set_bit(RBIO_PARKED_BIT, &rbio->flags);
rbio->park_deadline = jiffies + msecs_to_jiffies(timeout_ms);
/*
* Take a reference of our own before publishing. The moment
-@@ -822,6 +829,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -827,6 +834,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
refcount_inc(&rbio->refs);
list_add_tail(&rbio->parked_node, &table->parked);
spin_unlock(&table->parked_lock);
queue_delayed_work(system_percpu_wq, &table->parked_work,
msecs_to_jiffies(BTRFS_RBIO_PARK_SCAN_MS));
-@@ -867,6 +875,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
+@@ -872,6 +880,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
}
rbio_unpark_locked(rbio);
spin_unlock(&table->parked_lock);
start_async_work(rbio, rmw_rbio_work_locked);
}
-@@ -900,6 +909,7 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
+@@ -905,6 +914,7 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
list_for_each_entry_safe(rbio, tmp, &flush, parked_node) {
list_del_init(&rbio->parked_node);
start_async_work(rbio, rmw_rbio_work_locked);
}
}
-@@ -929,6 +939,7 @@ static void parked_rbios_timeout_work(struct work_struct *work)
+@@ -934,6 +944,7 @@ static void parked_rbios_timeout_work(struct work_struct *work)
list_for_each_entry_safe(rbio, tmp, &flush, parked_node) {
list_del_init(&rbio->parked_node);
start_async_work(rbio, rmw_rbio_work_locked);
}
if (rearm)
-@@ -2770,6 +2781,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2787,6 +2798,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
set_bit(RBIO_PADDED_BIT, &rbio->flags);
/* The whole stripe goes out: every vertical position is written. */
bitmap_set(&rbio->dbitmap, 0, rbio->stripe_nsectors);
return true;
}
-@@ -2839,6 +2851,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2856,6 +2868,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
*/
if (!rbio_is_full(rbio) && !rmw_try_pad_full(rbio) &&
need_read_stripe_sectors(rbio)) {
* Now we're doing sub-stripe write, also need all data stripes
* to do the full RMW.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9bb5ee9217318..46389b3688e64 100644
+index 357c669e6ea15..a36754036846b 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1109,6 +1109,29 @@ static ssize_t btrfs_commit_stats_store(struct kobject *kobj,
-From a7895fde7eb406a254050d73cca1962ec84111e9 Mon Sep 17 00:00:00 2001
+From f5b0c9d155f96d732d35de297cafc368c6240d40 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:44 -0400
Subject: [RFC PATCH 023/116] btrfs: raid56: skip parking for sync rbios
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 6d1c4127b7e23..f78ed04cf9d17 100644
+index 4f3968313f501..850011c8b5555 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -55,6 +55,14 @@
/* Set at park time and never cleared: this rbio once parked (stats). */
#define RBIO_WAS_PARKED_BIT 7
-@@ -808,6 +816,18 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -813,6 +821,18 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
timeout_ms == BTRFS_RBIO_PARK_SYNC_TIMEOUT_MS)
return false;
spin_lock(&table->parked_lock);
set_bit(RBIO_PARKED_BIT, &rbio->flags);
set_bit(RBIO_WAS_PARKED_BIT, &rbio->flags);
-@@ -2078,12 +2098,15 @@ static void raid_unplug(struct blk_plug_cb *cb, bool from_schedule)
+@@ -2095,12 +2115,15 @@ static void raid_unplug(struct blk_plug_cb *cb, bool from_schedule)
free_raid_bio(cur);
continue;
}
-From 807bda7889b06996e4506808acb3a7536a460d8d Mon Sep 17 00:00:00 2001
+From 70f17f325b3784e23a50958d3a80c500bffe3759 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:45 -0400
Subject: [RFC PATCH 024/116] btrfs: stripe_alloc: count open stripe run
3 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 42c50bfca2ee5..058778a519d9d 100644
+index c7b21de26540e..31b420a979943 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -557,11 +557,46 @@ static u64 close_open_stripe_run(struct btrfs_block_group *bg,
* Membership in fs_info->open_stripe_bgs, protected by
* fs_info->open_stripe_lock; holds a block group reference.
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index ef5a0ea9039db..c50f0046f3609 100644
+index 51098227f9171..44d7014b697f8 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -153,9 +153,19 @@ struct btrfs_space_info {
-From 697d334f1241e81347df4ce5a5eab5a7fa90352d Mon Sep 17 00:00:00 2001
+From eecce5dd3ebd561dc1e7888d98ef8c38e3012a2f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:46 -0400
Subject: [RFC PATCH 025/116] btrfs: stripe_alloc: pessimistic data reservation
Assisted-by: Claude:claude-fable-5
---
- fs/btrfs/block-group.c | 6 ++++
+ fs/btrfs/block-group.c | 6 +++
fs/btrfs/btrfs_inode.h | 3 ++
- fs/btrfs/defrag.c | 4 ++-
- fs/btrfs/delalloc-space.c | 50 ++++++++++++++++++++++++--
+ fs/btrfs/defrag.c | 4 +-
+ fs/btrfs/delalloc-space.c | 50 +++++++++++++++++++++++--
fs/btrfs/delalloc-space.h | 3 +-
fs/btrfs/direct-io.c | 9 ++++-
- fs/btrfs/extent-tree.c | 26 ++++++++++++++
- fs/btrfs/file.c | 9 +++--
- fs/btrfs/free-space-cache.c | 46 ++++++++++++++++++++++++
- fs/btrfs/fs.h | 8 +++++
- fs/btrfs/inode.c | 4 ++-
- fs/btrfs/space-info.c | 72 +++++++++++++++++++++++++++++++++++--
- fs/btrfs/space-info.h | 14 ++++++++
- fs/btrfs/sysfs.c | 4 +++
- 14 files changed, 247 insertions(+), 11 deletions(-)
+ fs/btrfs/extent-tree.c | 26 +++++++++++++
+ fs/btrfs/file.c | 9 ++++-
+ fs/btrfs/free-space-cache.c | 46 +++++++++++++++++++++++
+ fs/btrfs/fs.h | 8 ++++
+ fs/btrfs/inode.c | 4 +-
+ fs/btrfs/space-info.c | 73 ++++++++++++++++++++++++++++++++++++-
+ fs/btrfs/space-info.h | 14 +++++++
+ fs/btrfs/sysfs.c | 4 ++
+ 14 files changed, 248 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 058778a519d9d..11848c9ab51e1 100644
+index 31b420a979943..29473031c9226 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2095,6 +2095,12 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
/*
diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
-index d2d5f41b578e6..3fc0d4100f502 100644
+index 918a82f6b9035..5d319df6524d8 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
-@@ -1276,6 +1276,7 @@ static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
+@@ -1285,6 +1285,7 @@ static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
const unsigned int nr_pages = ((start + len - 1) >> PAGE_SHIFT) -
(start >> PAGE_SHIFT) + 1;
u64 cur;
int ret = 0;
ASSERT(IS_ALIGNED(start, fs_info->sectorsize) &&
-@@ -1329,10 +1330,11 @@ static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
+@@ -1338,10 +1339,11 @@ static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
* stays in its old stripe (see btrfs_carry_log_tail).
*/
ret = btrfs_check_data_free_space(inode, &data_reserved, start, len,
if (!only_release_metadata)
btrfs_free_reserved_data_space(inode, data_reserved,
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 2e7bf3505d1c7..594396b738fa7 100644
+index 118fced160032..62b8803e63251 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1483,6 +1483,51 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
+@@ -1493,6 +1493,51 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
int btrfs_add_free_space(struct btrfs_block_group *block_group,
u64 bytenr, u64 size)
{
-@@ -1499,6 +1544,7 @@ int btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1509,6 +1554,7 @@ int btrfs_add_free_space(struct btrfs_block_group *block_group,
trim_state = BTRFS_TRIM_STATE_TRIMMED;
stripe_unusable_mark_dirty(block_group);
spinlock_t swapfile_pins_lock;
struct rb_root swapfile_pins;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 511f4aa7f3c19..7b5e55c926e17 100644
+index d243e078435b5..98d376ce99eb8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -5087,6 +5087,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
+@@ -5085,6 +5085,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
struct extent_changeset *data_reserved = NULL;
bool only_release_metadata = false;
u32 blocksize = fs_info->sectorsize;
pgoff_t index = (offset >> PAGE_SHIFT);
struct folio *folio;
gfp_t mask = btrfs_alloc_write_mask(mapping);
-@@ -5139,7 +5140,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
+@@ -5137,7 +5138,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
block_end = block_start + blocksize - 1;
ret = btrfs_check_data_free_space(inode, &data_reserved, block_start,
if (ret < 0) {
size_t write_bytes = blocksize;
-@@ -5153,6 +5154,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
+@@ -5151,6 +5152,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
}
}
ret = btrfs_delalloc_reserve_metadata(inode, blocksize, blocksize, false);
if (!only_release_metadata)
btrfs_free_reserved_data_space(inode, data_reserved,
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 82d4ac418a2de..b7ce04192af22 100644
+index d5a84fa97462c..2137d58015412 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -16,6 +16,7 @@
/*
* HOW DOES SPACE RESERVATION WORK
-@@ -387,6 +388,18 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
+@@ -386,6 +387,19 @@ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group)
factor = btrfs_bg_type_to_factor(block_group->flags);
+ */
+ if ((block_group->flags & BTRFS_BLOCK_GROUP_DATA) &&
+ (block_group->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
-+ block_group->full_stripe_len > READ_ONCE(info->stripe_margin_unit))
-+ WRITE_ONCE(info->stripe_margin_unit,
++ block_group->full_stripe_len >
++ READ_ONCE(block_group->fs_info->stripe_margin_unit))
++ WRITE_ONCE(block_group->fs_info->stripe_margin_unit,
+ block_group->full_stripe_len);
+
spin_lock(&space_info->lock);
if (!(block_group->flags & BTRFS_BLOCK_GROUP_REMAPPED) ||
-@@ -412,6 +425,59 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
+@@ -409,6 +423,59 @@ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group)
up_write(&space_info->groups_sem);
}
struct btrfs_space_info *btrfs_find_space_info(const struct btrfs_fs_info *info,
u64 flags)
{
-@@ -655,10 +721,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
+@@ -652,10 +719,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
(s64)(info->total_bytes - btrfs_space_info_used(info, true)),
info->full ? "" : "not ");
btrfs_info(fs_info,
void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index c50f0046f3609..39e32ed85636e 100644
+index 44d7014b697f8..13c24536731c5 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -166,6 +166,16 @@ struct btrfs_space_info {
+
int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
+void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod);
- void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
- struct btrfs_block_group *block_group);
+ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group);
void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
+ u64 chunk_size);
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 46389b3688e64..8d89c8e521952 100644
+index a36754036846b..dc12af3ed39a9 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -818,6 +818,8 @@ SPACE_INFO_ATTR(bytes_may_use);
-From b639bc5d11cf7bddb4d4237ab937eadad2f0a677 Mon Sep 17 00:00:00 2001
+From bd75d78d258e5774fe98c815c3b879113b515f3f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:47 -0400
Subject: [RFC PATCH 026/116] btrfs: stripe_alloc: claim fully-free stripes
1 file changed, 212 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 594396b738fa7..0a4380e4637cb 100644
+index 62b8803e63251..c266c0f35f2f1 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2195,13 +2195,19 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
+@@ -2205,13 +2205,19 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
*
* want_bytes must be a full_stripe_len multiple and is a maximum; the
* smallest successful claim is a single full stripe. A fully-free stripe
*/
/*
* Claim exactly [start, start + len) from the free space cache, failing
-@@ -2265,6 +2271,183 @@ int btrfs_claim_stripe_tail(struct btrfs_block_group *block_group,
+@@ -2275,6 +2281,183 @@ int btrfs_claim_stripe_tail(struct btrfs_block_group *block_group,
return btrfs_remove_free_space(block_group, start, len);
}
int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
u64 want_bytes, u64 *start, u64 *len)
{
-@@ -2274,7 +2457,9 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2284,7 +2467,9 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
const u64 fsl = block_group->full_stripe_len;
struct btrfs_free_space *entry;
struct rb_node *node;
u64 head_start = 0;
u64 head_len = 0;
u64 run_start;
-@@ -2327,6 +2512,26 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2337,6 +2522,26 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
continue;
goto found;
}
goto out;
found:
-@@ -2361,6 +2566,8 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2371,6 +2576,8 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
btrfs_discard_update_discardable(block_group);
spin_unlock(&ctl->tree_lock);
-From 7a956b197fb633fae63d44cea3d3aba1ab518989 Mon Sep 17 00:00:00 2001
+From 8e25e060df10050ba0d652f78319d7fd1a4a275c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:47 -0400
Subject: [RFC PATCH 027/116] btrfs: stripe_alloc: warn when raid56 metadata is
1 file changed, 23 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 11848c9ab51e1..0d41c6ecdd735 100644
+index 29473031c9226..81eecb45190b8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1690,6 +1690,28 @@ static void stripe_alloc_sweep_groups(struct btrfs_fs_info *fs_info, bool arm)
-From cde49689a8ca53fa1964cc93e1afc3ac5329368a Mon Sep 17 00:00:00 2001
+From cf439cf4ee591597df487b491b3b8641d5361f3b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:48 -0400
Subject: [RFC PATCH 028/116] btrfs: stripe_alloc: report read-modify-write of
/* BTRFS_STRIPE_RMW_* masks; see btrfs_stripe_allow_rmw(). */
u32 stripe_rmw_opt;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index f78ed04cf9d17..dcd59c92766de 100644
+index 850011c8b5555..8248960c7c150 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2831,6 +2831,43 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -2848,6 +2848,43 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
return false;
}
static void rmw_rbio(struct btrfs_raid_bio *rbio)
{
struct bio_list bio_list;
-@@ -2893,6 +2930,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2910,6 +2947,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
goto out;
}
* At this stage we're not allowed to add any new bios to the
* bio list any more, anyone else that wants to change this stripe
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 8d89c8e521952..125dc4c601d76 100644
+index dc12af3ed39a9..106e804b6363e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1125,14 +1125,16 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 3758928da147179fac4d9ecdbd3e6c703eda36d1 Mon Sep 17 00:00:00 2001
+From 30d77543640f438ee389f66b5e06fb766dbab2bc Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:49 -0400
Subject: [RFC PATCH 029/116] btrfs: raid56: say whether a metadata
/* BTRFS_STRIPE_RMW_* masks; see btrfs_stripe_allow_rmw(). */
u32 stripe_rmw_opt;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index dcd59c92766de..7dbf0a71405d4 100644
+index 8248960c7c150..7c15583651fc2 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2831,6 +2831,132 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -2848,6 +2848,132 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
return false;
}
+ const int stripe_nr = i / rbio->stripe_nsectors;
+ const int sectornr = i % rbio->stripe_nsectors;
+ const u64 logical = rbio->bioc->full_stripe_logical +
-+ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)stripe_nr * rbio->bioc->stripe_len +
+ (u64)sectornr * fs_info->sectorsize;
+ const phys_addr_t *paddrs = from_bio ? rbio->bio_paddrs
+ : rbio->stripe_paddrs;
/*
* Report a sub-stripe write that is going out as a read-modify-write.
*
-@@ -2863,6 +2989,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -2880,6 +3006,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
return;
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
"read-modify-write of full stripe %llu: this block group is not covered by stripe_alloc, the raid56 write hole applies to it",
rbio->bioc->full_stripe_logical);
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 125dc4c601d76..0d9dcfb7bbd1a 100644
+index 106e804b6363e..beabada2eacd7 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1126,7 +1126,10 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 9bd6e8e81e4445fb261378e2f6386fc195cfe535 Mon Sep 17 00:00:00 2001
+From 897917b2d1c3004bd01f804fd778ef3360ee920c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:50 -0400
Subject: [RFC PATCH 030/116] btrfs: stripe_alloc: tunable park deadlines, and
5 files changed, 127 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 0d41c6ecdd735..602a7f2821745 100644
+index 81eecb45190b8..e46ce260f71ad 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1315,14 +1315,19 @@ bool btrfs_stripe_run_pad_start(struct btrfs_fs_info *fs_info,
return ret;
}
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 6cc4c609a7d8b..71e38307ee92b 100644
+index 7540f7d9e3de1..5d306267e3f47 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2784,6 +2784,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2804,6 +2804,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->delalloc_roots);
INIT_LIST_HEAD(&fs_info->caching_block_groups);
INIT_LIST_HEAD(&fs_info->open_stripe_bgs);
/* Private scrub information */
struct mutex scrub_lock;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 7dbf0a71405d4..aae82b458bb86 100644
+index 7c15583651fc2..d117cf701b807 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -75,8 +75,6 @@
/* Scan period of the park timer while anything is parked. */
#define BTRFS_RBIO_PARK_SCAN_MS 3
-@@ -792,7 +790,9 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -797,7 +795,9 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
{
struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
struct btrfs_stripe_hash_table *table = fs_info->stripe_hash_table;
enum btrfs_stripe_run_class class;
if (!btrfs_stripe_open_run_class(fs_info,
-@@ -802,9 +802,13 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -807,9 +807,13 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
spin_lock(&rbio->bio_list_lock);
if (rbio_has_sync_bio(rbio))
/*
* A sync write into a nodatacow inode's private run has a waiter
* behind it and nothing worth waiting to merge with: in-place
-@@ -813,7 +817,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -818,7 +822,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
* async writeback there.
*/
if (class == BTRFS_STRIPE_RUN_NOCOW &&
return false;
/*
-@@ -825,7 +829,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -830,7 +834,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
* path kicks it as soon as they have all been submitted.)
*/
if (test_bit(RBIO_BATCH_DONE_BIT, &rbio->flags) &&
return false;
spin_lock(&table->parked_lock);
-@@ -1101,7 +1105,8 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+@@ -1106,7 +1110,8 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
struct btrfs_stripe_hash_table *table =
cur->bioc->fs_info->stripe_hash_table;
unsigned long dl = jiffies +
spin_lock(&table->parked_lock);
if (test_bit(RBIO_PARKED_BIT,
-@@ -3038,10 +3043,17 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3055,10 +3060,17 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
*/
if (!rbio_is_full(rbio) && !rmw_try_pad_full(rbio) &&
need_read_stripe_sectors(rbio)) {
* Now we're doing sub-stripe write, also need all data stripes
* to do the full RMW.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 0d9dcfb7bbd1a..9369b05c7afc4 100644
+index beabada2eacd7..fbd5158babd99 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1126,6 +1126,10 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From addef1dec9727eecb057bc479be793829bd049f7 Mon Sep 17 00:00:00 2001
+From cae5a5d0a6e9a7a0a1b11229920cdb81b1f81769 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:51 -0400
Subject: [RFC PATCH 031/116] btrfs: stripe_alloc: trace why padding declined,
6 files changed, 128 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 602a7f2821745..d53f8f9e7bc0c 100644
+index e46ce260f71ad..5c3239f41f538 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1311,7 +1311,8 @@ bool btrfs_stripe_nocow_writable(struct btrfs_inode *inode, u64 start,
/*
* Breakdown of what a metadata read-modify-write found in the
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index aae82b458bb86..381834cf7fe83 100644
+index d117cf701b807..7f70c0ed81e9f 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2760,20 +2760,40 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2777,20 +2777,40 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
const u64 stripe_start = rbio->bioc->full_stripe_logical;
const u32 sectorsize = fs_info->sectorsize;
- const u64 stripe_len = (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
+ const u64 stripe_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
- u64 pad_from;
+ struct btrfs_stripe_pad_info info;
+ const u32 total = rbio->nr_data * rbio->stripe_nsectors;
const int stripe_nr = i / rbio->stripe_nsectors;
const int sectornr = i % rbio->stripe_nsectors;
u64 logical = stripe_start + stripe_nr * BTRFS_STRIPE_LEN +
-@@ -2781,8 +2801,19 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2798,8 +2818,19 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
continue;
if (alloc_rbio_data_pages(rbio) < 0)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9369b05c7afc4..470094efa25b3 100644
+index fbd5158babd99..4059b8e0974a8 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1130,6 +1130,7 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From ba78c5bdb23c33d2159470c5a0b11b182ab90aa8 Mon Sep 17 00:00:00 2001
+From 138ec473477dae46a688181c42319f862d01ec56 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:52 -0400
Subject: [RFC PATCH 032/116] btrfs: stripe_alloc: complete parked writes on
8 files changed, 155 insertions(+), 14 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index d53f8f9e7bc0c..4d63d1f7cd3d8 100644
+index 5c3239f41f538..59b7232c6482e 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1309,6 +1309,43 @@ bool btrfs_stripe_nocow_writable(struct btrfs_inode *inode, u64 start,
test_bit(BTRFS_ORDERED_COMPLETE,
&entry->flags),
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 381834cf7fe83..d778cc37667a0 100644
+index 7f70c0ed81e9f..370893ab20223 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -66,6 +66,13 @@
#define RBIO_CACHE_SIZE 1024
/*
-@@ -780,6 +787,29 @@ static bool rbio_has_sync_bio(struct btrfs_raid_bio *rbio)
+@@ -785,6 +792,29 @@ static bool rbio_has_sync_bio(struct btrfs_raid_bio *rbio)
return false;
}
+{
+ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
+ const u64 stripe_start = rbio->bioc->full_stripe_logical;
-+ const u64 stripe_len = (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
++ const u64 stripe_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
+ u64 ceiling;
+
+ ceiling = btrfs_stripe_run_alloc_ceiling(fs_info, stripe_start,
/*
* Park a partial write rbio that owns its stripe lock, if its stripe is
* covered by an open stripe run. Returns true if the rbio was parked (or
-@@ -835,7 +865,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -840,7 +870,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
spin_lock(&table->parked_lock);
set_bit(RBIO_PARKED_BIT, &rbio->flags);
set_bit(RBIO_WAS_PARKED_BIT, &rbio->flags);
/*
* Take a reference of our own before publishing. The moment
* parked_lock is dropped this rbio is visible to every flusher, and a
-@@ -887,7 +921,8 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -892,7 +926,8 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
* write. Callers may hold the stripe hash and bio_list locks; parked_lock
* nests inside both.
*/
{
struct btrfs_stripe_hash_table *table =
rbio->bioc->fs_info->stripe_hash_table;
-@@ -899,7 +934,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
+@@ -904,7 +939,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
}
rbio_unpark_locked(rbio);
spin_unlock(&table->parked_lock);
start_async_work(rbio, rmw_rbio_work_locked);
}
-@@ -909,7 +944,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
+@@ -914,7 +949,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
* ordered-extent waiters, and the park timer.
*/
void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
{
struct btrfs_stripe_hash_table *table = fs_info->stripe_hash_table;
struct btrfs_raid_bio *rbio;
-@@ -926,6 +961,17 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
+@@ -931,6 +966,17 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
if (rbio_start + rbio_len <= start ||
(num_bytes != U64_MAX && rbio_start >= start + num_bytes))
continue;
rbio_unpark_locked(rbio);
list_add_tail(&rbio->parked_node, &flush);
}
-@@ -956,14 +1002,35 @@ static void parked_rbios_timeout_work(struct work_struct *work)
+@@ -961,14 +1007,35 @@ static void parked_rbios_timeout_work(struct work_struct *work)
rearm = true;
continue;
}
start_async_work(rbio, rmw_rbio_work_locked);
}
if (rearm)
-@@ -1098,9 +1165,21 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+@@ -1103,9 +1170,21 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
* this stripe.
*/
if (test_bit(RBIO_PARKED_BIT, &cur->flags)) {
+ cur->bioc->fs_info;
+
if (cur->bio_list_bytes ==
- cur->nr_data * BTRFS_STRIPE_LEN) {
+ cur->nr_data * cur->bioc->stripe_len) {
- unpark_full_rbio(cur);
+ unpark_ready_rbio(cur,
+ &cfs->stripe_park_stats.filled);
} else if (sync) {
struct btrfs_stripe_hash_table *table =
cur->bioc->fs_info->stripe_hash_table;
-@@ -1110,9 +1189,13 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+@@ -1115,9 +1194,13 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
spin_lock(&table->parked_lock);
if (test_bit(RBIO_PARKED_BIT,
}
}
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 07ba71ae8e54f..ca15c45f8f4be 100644
+index f5b8d788b1fff..11b843095903e 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -140,6 +140,8 @@ struct btrfs_raid_bio {
+@@ -138,6 +138,8 @@ struct btrfs_raid_bio {
*/
struct list_head parked_node;
unsigned long park_deadline;
/* Flags that tell us if it is safe to merge with this bio. */
unsigned long flags;
-@@ -297,6 +299,6 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+@@ -292,6 +294,6 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
#endif
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 470094efa25b3..6d084a70758cd 100644
+index 4059b8e0974a8..25d8c61d72a9e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1122,8 +1122,10 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 470e5e7b910d21431589778c95abc362bc6c1712 Mon Sep 17 00:00:00 2001
+From b5b297cec9569dd1040ab925a60f6df4bc13c227 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:53 -0400
Subject: [RFC PATCH 033/116] btrfs: stripe_alloc: track per-sector liveness
5 files changed, 357 insertions(+), 145 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4d63d1f7cd3d8..572ecbfb3514f 100644
+index 59b7232c6482e..974ffc73f3b1e 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -504,6 +504,21 @@ struct btrfs_open_stripe_run {
if (root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 0a4380e4637cb..80703492a5647 100644
+index c266c0f35f2f1..aabf456b70d97 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2272,9 +2272,70 @@ int btrfs_claim_stripe_tail(struct btrfs_block_group *block_group,
+@@ -2282,9 +2282,70 @@ int btrfs_claim_stripe_tail(struct btrfs_block_group *block_group,
}
/*
* with point lookups, looking for a run of fully-free full stripes no
* single entry contains.
*
-@@ -2456,7 +2517,6 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2466,7 +2527,6 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
&block_group->fs_info->discard_ctl;
const u64 fsl = block_group->full_stripe_len;
struct btrfs_free_space *entry;
struct btrfs_free_space *spare = NULL;
enum btrfs_trim_state head_trim_state = BTRFS_TRIM_STATE_UNTRIMMED;
bool spare_used = false;
-@@ -2473,68 +2533,30 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2483,68 +2543,30 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
spin_lock(&ctl->tree_lock);
if (!btrfs_free_space_trimmed(entry))
atomic64_add(run_len, &discard_ctl->discard_bytes_saved);
-@@ -2576,6 +2598,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2586,6 +2608,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
return ret;
}
* given a cluster, put all of its extents back into the free space
* cache. If a block group is passed, this function will only free
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index d778cc37667a0..09fe3c65dd6df 100644
+index 370893ab20223..92c48cb4578da 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2245,6 +2245,7 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc)
+@@ -2262,6 +2262,7 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc)
rbio->operation = BTRFS_RBIO_WRITE;
rbio_add_bio(rbio, bio);
/*
* Don't plug on full rbios, just get them out the door
* as quickly as we can
-@@ -2830,74 +2831,78 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2847,74 +2848,78 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
/*
* Try to avoid the RMW read phase of a sub-stripe write by zero-filling
struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
const u64 stripe_start = rbio->bioc->full_stripe_logical;
- const u32 sectorsize = fs_info->sectorsize;
- const u64 stripe_len = (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
+ const u64 stripe_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
+ const u32 sectorsize = fs_info->sectorsize;
+ const u32 nsectors = rbio->nr_data * rbio->stripe_nsectors;
struct btrfs_stripe_pad_info info;
-From 5eecaf54aa231b7e7a6bc68f5f16b905aee89bbb Mon Sep 17 00:00:00 2001
+From e41a35a9dc376c6b027def1b5cf16607cec0a75f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:54 -0400
Subject: [RFC PATCH 034/116] btrfs: stripe_alloc: count claimable whole-stripe
7 files changed, 138 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 572ecbfb3514f..234db161586a7 100644
+index 974ffc73f3b1e..857638d2d506c 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2332,6 +2332,7 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 80703492a5647..8995f90fdebc2 100644
+index aabf456b70d97..eed6f8b7de197 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1350,6 +1350,10 @@ static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl,
+@@ -1360,6 +1360,10 @@ static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl,
}
}
static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
u64 offset, u64 bytes,
enum btrfs_trim_state trim_state)
-@@ -1404,6 +1408,19 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1414,6 +1418,19 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
if (ret)
kmem_cache_free(btrfs_free_space_cachep, info);
out:
btrfs_discard_update_discardable(block_group);
spin_unlock(&ctl->tree_lock);
-@@ -1483,6 +1500,48 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
+@@ -1493,6 +1510,48 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
/*
* stripe_alloc: count the sub-stripe fragments of a returning free range
* as trapped immediately, without waiting for the commit-time rescan.
-@@ -1609,6 +1668,19 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group,
+@@ -1619,6 +1678,19 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group,
spin_lock(&ctl->tree_lock);
again:
ret = 0;
if (!bytes)
-@@ -2022,7 +2094,7 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
+@@ -2032,7 +2104,7 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
{
struct btrfs_free_space_ctl *ctl = bg->free_space_ctl;
u32 *freep;
if (!btrfs_is_stripe_alloc_bg(bg))
-@@ -2043,14 +2115,19 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2053,14 +2125,19 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
}
trapped = stripe_unusable_scan(bg, freep, nstripes);
bg->stripe_unusable = trapped;
spin_unlock(&bg->space_info->lock);
}
}
-@@ -2067,6 +2144,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2077,6 +2154,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
{
struct btrfs_free_space_ctl *ctl = bg->free_space_ctl;
u64 trapped;
if (!btrfs_is_stripe_alloc_bg(bg))
return;
-@@ -2077,13 +2155,17 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2087,13 +2165,17 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
return;
}
trapped = bg->stripe_unusable;
spin_unlock(&bg->space_info->lock);
}
}
-@@ -2111,8 +2193,27 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2121,8 +2203,27 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
return;
spin_lock(&ctl->tree_lock);
spin_unlock(&ctl->tree_lock);
kvfree(freep);
/*
-@@ -2551,6 +2652,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2561,6 +2662,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
goto out;
spare_used = claim_stripe_run_pieces(block_group, run_start,
run_len, spare);
*start = run_start;
*len = run_len;
ret = 0;
-@@ -2581,6 +2683,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2591,6 +2693,7 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
kmem_cache_free(btrfs_free_space_cachep, entry);
}
}
*len = run_len;
ret = 0;
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index b7ce04192af22..7222811993279 100644
+index 2137d58015412..13e0db4aa1c42 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -721,11 +721,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
+@@ -719,11 +719,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
(s64)(info->total_bytes - btrfs_space_info_used(info, true)),
info->full ? "" : "not ");
btrfs_info(fs_info,
}
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 39e32ed85636e..65c976e84fcc3 100644
+index 13c24536731c5..c8143f39f89b0 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -158,6 +158,10 @@ struct btrfs_space_info {
static inline u64 btrfs_space_info_used(const struct btrfs_space_info *s_info,
bool may_use_included)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 6d084a70758cd..198ca6a6c3735 100644
+index 25d8c61d72a9e..2559c37f8af85 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -818,6 +818,7 @@ SPACE_INFO_ATTR(bytes_may_use);
-From db091c0b27f9c41bde8be5b39e01f1dc63cf2a25 Mon Sep 17 00:00:00 2001
+From 4384767186cded93819133007b4b6eaf5117ddf6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:55 -0400
Subject: [RFC PATCH 035/116] btrfs: raid56: adaptive park deadline from the
/* Private scrub information */
struct mutex scrub_lock;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 09fe3c65dd6df..1af74be9b6c87 100644
+index 92c48cb4578da..8c587dd13965a 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -774,6 +774,7 @@ static void rbio_unpark_locked(struct btrfs_raid_bio *rbio)
+@@ -779,6 +779,7 @@ static void rbio_unpark_locked(struct btrfs_raid_bio *rbio)
{
list_del_init(&rbio->parked_node);
clear_bit(RBIO_PARKED_BIT, &rbio->flags);
}
/* Does any bio gathered in @rbio carry a sync hint (a blocked waiter)? */
-@@ -862,6 +863,29 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -867,6 +868,29 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
timeout_ms == sync_timeout_ms)
return false;
spin_lock(&table->parked_lock);
set_bit(RBIO_PARKED_BIT, &rbio->flags);
set_bit(RBIO_WAS_PARKED_BIT, &rbio->flags);
-@@ -886,6 +910,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -891,6 +915,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
*/
refcount_inc(&rbio->refs);
list_add_tail(&rbio->parked_node, &table->parked);
atomic64_inc(&fs_info->stripe_park_stats.parked);
queue_delayed_work(system_percpu_wq, &table->parked_work,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 198ca6a6c3735..6eb2d5362f204 100644
+index 2559c37f8af85..0369a7c04c54f 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1138,7 +1138,9 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From aff2aee44cbf33530bdb4578906ef260a084049d Mon Sep 17 00:00:00 2001
+From 3002a7e4dce8259c68b19a47f454e8996e7c8cbf Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:56 -0400
Subject: [RFC PATCH 036/116] btrfs: stripe_alloc: gate data admission on
1 file changed, 65 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 7222811993279..eb5e0a9472acc 100644
+index 13e0db4aa1c42..53a4d3c3decfb 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -649,6 +649,66 @@ static void remove_ticket(struct btrfs_space_info *space_info,
+@@ -647,6 +647,66 @@ static void remove_ticket(struct btrfs_space_info *space_info,
spin_unlock(&ticket->lock);
}
/*
* This is for space we already have accounted in space_info->bytes_may_use, so
* basically when we're returning space from block_rsv's.
-@@ -671,8 +731,9 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
+@@ -669,8 +729,9 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
used_after = used + ticket->bytes;
/* Check and see if our ticket can be satisfied now. */
btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes);
remove_ticket(space_info, ticket, 0);
space_info->tickets_id++;
-@@ -1904,7 +1965,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1902,7 +1963,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
*/
if (!pending_tickets &&
((used + orig_bytes <= space_info->total_bytes) ||
-From 46fa2be98daec9cc359d0f216cd6725837f142b5 Mon Sep 17 00:00:00 2001
+From 9cbe3ca82143309b0b8e1fac5f67e131cbff4470 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:57 -0400
Subject: [RFC PATCH 037/116] btrfs: stripe_alloc: cache a failed stripe run
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 234db161586a7..f00ba4b29a47d 100644
+index 857638d2d506c..c984b5ffcf465 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -4529,6 +4529,7 @@ static struct btrfs_block_group *btrfs_create_block_group(
+@@ -4532,6 +4532,7 @@ static struct btrfs_block_group *btrfs_create_block_group(
cache->fs_info = fs_info;
cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start);
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 8995f90fdebc2..dbda642a1d45d 100644
+index eed6f8b7de197..b9074d21f90f6 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1378,6 +1378,12 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1388,6 +1388,12 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
spin_lock(&ctl->tree_lock);
if (try_merge_free_space(ctl, info, true))
goto link;
-@@ -2634,6 +2640,26 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2644,6 +2650,26 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
spin_lock(&ctl->tree_lock);
entry = find_free_stripe_run(block_group, want_bytes, &run_start, &run_len);
if (!entry) {
/*
-@@ -2648,8 +2674,17 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2658,8 +2684,17 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
return -ENOMEM;
spin_lock(&ctl->tree_lock);
if (!find_free_stripe_run_slow(block_group, want_bytes,
-From 4b4d6efe8d64cc91a3d94c7de469b449fa6cf16e Mon Sep 17 00:00:00 2001
+From dde098ab4e495aebe9bb82a19e2d9ea01b6918e8 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:58 -0400
Subject: [RFC PATCH 038/116] btrfs: stripe_meta: allocate tree blocks by whole
8 files changed, 482 insertions(+), 16 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index f00ba4b29a47d..6a1b84d917d99 100644
+index c984b5ffcf465..d64f882cec24d 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -501,6 +501,7 @@ struct btrfs_open_stripe_run {
bg_ret);
return do_allocation_clustered(block_group, ffe_ctl, bg_ret);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
-index 55e9144d47595..b4fd33de1a615 100644
+index 5ff630630490e..188e167848f91 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2392,6 +2392,16 @@ static void end_bbio_meta_write(struct btrfs_bio *bbio)
if (ret == -EBUSY) {
ret = 0;
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index dbda642a1d45d..075c00ea55b38 100644
+index b9074d21f90f6..e4671fc7e5c15 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2103,7 +2103,7 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2113,7 +2113,7 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
u64 trapped, claimable, nstripes;
u32 *freep;
if (READ_ONCE(bg->stripe_unusable_ready))
return;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 1af74be9b6c87..d95211d124ef4 100644
+index 8c587dd13965a..d1e961ce4e490 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3125,6 +3125,8 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3142,6 +3142,8 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
{
struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
return;
-@@ -3139,6 +3141,21 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3156,6 +3158,21 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
audit_uncovered_rmw(rbio);
"read-modify-write of full stripe %llu: this block group is not covered by stripe_alloc, the raid56 write hole applies to it",
rbio->bioc->full_stripe_logical);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 0dccce2c57c9d..c3cdaf2c6cc41 100644
+index 4f781df772202..6007dce716bf5 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -23,6 +23,8 @@
#include "space-info.h"
#include "fs.h"
#include "accessors.h"
-@@ -1361,6 +1363,13 @@ static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans)
+@@ -1345,6 +1347,13 @@ static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans)
blk_start_plug(&plug);
ret = btrfs_write_marked_extents(fs_info, dirty_pages, EXTENT_DIRTY);
blk_finish_plug(&plug);
ret2 = btrfs_wait_extents(fs_info, dirty_pages);
if (ret)
-@@ -2677,6 +2686,16 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2661,6 +2670,16 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
goto scrub_continue;
}
/*
* the super is written, we can safely allow the tree-loggers
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
-index e9b688024aed6..28a1439f0416b 100644
+index d902d169680a4..3a2391b616694 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
-@@ -2936,6 +2936,28 @@ static int clean_log_buffer(struct btrfs_trans_handle *trans,
+@@ -2938,6 +2938,28 @@ static int clean_log_buffer(struct btrfs_trans_handle *trans,
wait_on_extent_buffer_writeback(eb);
btrfs_tree_unlock(eb);
-From 4d8e0574bf5043d83a69e17e41ec1e48fbaea885 Mon Sep 17 00:00:00 2001
+From 5fc8c3c4793dfd054c91db27d0d7c85330922a4c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:59 -0400
Subject: [RFC PATCH 039/116] btrfs: stripe_alloc: drain the legacy allocator's
4 files changed, 49 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 6a1b84d917d99..4997b00c4ae41 100644
+index d64f882cec24d..989cbbaa33c38 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -5,6 +5,8 @@
void btrfs_stripe_check_write(struct btrfs_fs_info *fs_info,
u64 full_stripe_start, bool sub_stripe);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 71e38307ee92b..a75fb22137e39 100644
+index 5d306267e3f47..37d87114f69e4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2784,6 +2784,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2804,6 +2804,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->delalloc_roots);
INIT_LIST_HEAD(&fs_info->caching_block_groups);
INIT_LIST_HEAD(&fs_info->open_stripe_bgs);
fs_info->stripe_park_timeout_ms = BTRFS_RBIO_PARK_TIMEOUT_MS;
fs_info->stripe_park_sync_timeout_ms = BTRFS_RBIO_PARK_SYNC_TIMEOUT_MS;
spin_lock_init(&fs_info->open_stripe_lock);
-@@ -4482,6 +4483,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
+@@ -4502,6 +4503,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
*/
btrfs_run_delayed_iputs(fs_info);
-From 3962fc1138c917d8bef1818bc692eb54b7e6e501 Mon Sep 17 00:00:00 2001
+From a453b51b9a437ef2b973388abb60efb07a27d2a4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:00 -0400
Subject: [RFC PATCH 040/116] btrfs: stripe_alloc: keep the admitted bytes
1 file changed, 25 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4997b00c4ae41..12fd159b096c9 100644
+index 989cbbaa33c38..2ca280f3d24bd 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -3879,6 +3879,31 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -3881,6 +3881,31 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
*/
if (sinfo_used - trapped + num_bytes <= sinfo->total_bytes)
ret = 0;
-From 8fd5354672fd14d804216a575c2ec72e5ad6c950 Mon Sep 17 00:00:00 2001
+From f43d637979ad59db61287dd03e80db53252d0b77 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:01 -0400
Subject: [RFC PATCH 041/116] btrfs: stripe_alloc: never let relocation wait on
bytes = ALIGN(bytes, fs_info->sectorsize);
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index eb5e0a9472acc..e4091bef175ba 100644
+index 53a4d3c3decfb..1cc48844089f1 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -1820,6 +1820,7 @@ static int handle_reserve_ticket(struct btrfs_space_info *space_info,
+@@ -1818,6 +1818,7 @@ static int handle_reserve_ticket(struct btrfs_space_info *space_info,
switch (flush) {
case BTRFS_RESERVE_FLUSH_DATA:
case BTRFS_RESERVE_FLUSH_ALL:
case BTRFS_RESERVE_FLUSH_ALL_STEAL:
wait_reserve_ticket(space_info, ticket);
-@@ -1897,8 +1898,13 @@ static inline bool can_steal(enum btrfs_reserve_flush_enum flush)
+@@ -1895,8 +1896,13 @@ static inline bool can_steal(enum btrfs_reserve_flush_enum flush)
*/
static inline bool can_ticket(enum btrfs_reserve_flush_enum flush)
{
}
/*
-@@ -1940,7 +1946,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1938,7 +1944,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
ASSERT(flush != BTRFS_RESERVE_FLUSH_EVICT, "flush=%d", flush);
}
async_work = &fs_info->async_data_reclaim_work;
else
async_work = &fs_info->async_reclaim_work;
-@@ -2098,9 +2105,12 @@ int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
+@@ -2096,9 +2103,12 @@ int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
int ret;
ASSERT(flush == BTRFS_RESERVE_FLUSH_DATA ||
(unsigned long)current->journal_info, flush);
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 65c976e84fcc3..3d6141665a9d6 100644
+index c8143f39f89b0..867c0b9cc3eed 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -66,6 +66,14 @@ enum btrfs_reserve_flush_enum {
-From 6cbe3c02a360975097941fd3a390fd607a3c9c1f Mon Sep 17 00:00:00 2001
+From 306fa981802bac422d18668da6b26b483cabaebf Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:02 -0400
Subject: [RFC PATCH 042/116] btrfs: stripe_alloc: give a queued stripe group a
1 file changed, 28 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 12fd159b096c9..0e3c23e2066a8 100644
+index 2ca280f3d24bd..186f06965412e 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -4427,6 +4427,34 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -4429,6 +4429,34 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
u64 old_total;
int ret = 0;
-From 62886760223cf86cadcd40bfca85e7db871ef4f0 Mon Sep 17 00:00:00 2001
+From b32e47af319c32883e41c50ac16c18d3088e6539 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:03 -0400
Subject: [RFC PATCH 043/116] btrfs: stripe_alloc: charge relocation a margin
1 file changed, 32 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index e4091bef175ba..2683ac00a2ecf 100644
+index 1cc48844089f1..9ff38370833e9 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -455,6 +455,12 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
+@@ -453,6 +453,12 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
if (!unit || !sinfo || mod == 0)
return;
if (btrfs_test_opt(fs_info, STRIPE_ALLOC)) {
/* charges and releases both live */
} else if (mod > 0 || READ_ONCE(sinfo->bytes_stripe_margin) == 0) {
-@@ -667,7 +673,8 @@ static void remove_ticket(struct btrfs_space_info *space_info,
+@@ -665,7 +671,8 @@ static void remove_ticket(struct btrfs_space_info *space_info,
* FLUSH_DATA ticket retry). A later phase adds bytes_stripe_open to the bound to
* match statfs exactly and recover that space.
*/
{
struct btrfs_fs_info *fs_info = space_info->fs_info;
const u64 unit = READ_ONCE(fs_info->stripe_margin_unit);
-@@ -676,19 +683,28 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
+@@ -674,19 +681,28 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
!(space_info->flags & BTRFS_BLOCK_GROUP_DATA) || !unit)
return true;
/*
/*
* Every outstanding data extent holds a whole-stripe margin
* (bytes_stripe_margin) as collateral against the commit that
-@@ -733,7 +749,7 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
+@@ -731,7 +747,7 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
/* Check and see if our ticket can be satisfied now. */
if ((used_after <= space_info->total_bytes ||
can_overcommit(space_info, used, ticket->bytes, flush)) &&
btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes);
remove_ticket(space_info, ticket, 0);
space_info->tickets_id++;
-@@ -1973,7 +1989,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1971,7 +1987,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
if (!pending_tickets &&
((used + orig_bytes <= space_info->total_bytes) ||
can_overcommit(space_info, used, orig_bytes, flush)) &&
-From acf9c88ceacb8d92f6a5fbc83674f1d3196864c3 Mon Sep 17 00:00:00 2001
+From 9d0303ebca525fb6bcfdbdf18579bf824c6e8ce2 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:04 -0400
Subject: [RFC PATCH 044/116] btrfs: stripe_alloc: keep the relocation group's
5 files changed, 94 insertions(+), 35 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 0e3c23e2066a8..afd6b0b7e4525 100644
+index 186f06965412e..f100a2badde76 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2669,6 +2669,7 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
return 1;
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 075c00ea55b38..b4526c199ffb5 100644
+index e4671fc7e5c15..4533159a01929 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1533,6 +1533,12 @@ static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta)
+@@ -1543,6 +1543,12 @@ static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta)
sinfo->bytes_stripe_claimable = 0;
else
btrfs_space_info_update_bytes_stripe_claimable(sinfo, delta);
spin_unlock(&sinfo->lock);
}
-@@ -2172,6 +2178,8 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2182,6 +2188,8 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
-(s64)trapped);
btrfs_space_info_update_bytes_stripe_claimable(bg->space_info,
-(s64)claimable);
}
}
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 2683ac00a2ecf..3d74bdea16cac 100644
+index 9ff38370833e9..1e9946369c184 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -687,42 +687,59 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
+@@ -685,42 +685,59 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
* placed): charge it whole stripes plus one, the tail its own open
* runs can lose at the next commit.
*/
/*
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 3d6141665a9d6..702222bb54ae4 100644
+index 867c0b9cc3eed..5abb8fd072b3c 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -166,6 +166,11 @@ struct btrfs_space_info {
-From 8907d8718d7362ec87fc3f669bb819a07b1a9f57 Mon Sep 17 00:00:00 2001
+From fcea2a2a870153edcc955ec89836193e11a9395b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:05 -0400
Subject: [RFC PATCH 045/116] btrfs: stripe_alloc: let a data write fall back
-From 1646d2e379cbc9675bd69a08ea24ba28af54c64d Mon Sep 17 00:00:00 2001
+From d9236a5d0b0a3ce1ecc3243f5f6be0a636bb4d30 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:06 -0400
Subject: [RFC PATCH 046/116] btrfs: stripe_alloc: hand groups full of trapped
4 files changed, 125 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index afd6b0b7e4525..c6ff2a7dc6010 100644
+index f100a2badde76..d9097e961f2a8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -4684,21 +4684,74 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
+@@ -4686,21 +4686,74 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
btrfs_reclaim_block_groups(fs_info, -1);
}
struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans,
struct btrfs_space_info *space_info,
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index b4526c199ffb5..58f02314aef85 100644
+index 4533159a01929..b49c551276dd5 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2185,6 +2185,45 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2195,6 +2195,45 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
}
/*
* Recompute a stripe_alloc block group's trapped free space from a fresh scan
* and fold the change into the space_info total. Called at commit for groups
-@@ -2195,6 +2234,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2205,6 +2244,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
{
struct btrfs_free_space_ctl *ctl = bg->free_space_ctl;
u64 nstripes;
u32 *freep;
-@@ -2227,9 +2267,34 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2237,9 +2277,34 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
"bg %llu incremental stripe_claimable %llu above scanned %llu",
bg->start, bg->stripe_claimable, scanned);
bg->stripe_claimable = scanned;
-From 15b5f3d5a5f85702371cb95182b011bfcf3754e6 Mon Sep 17 00:00:00 2001
+From 5d738c8b02afd0dfa89f40059067b19f68082130 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:06 -0400
Subject: [RFC PATCH 047/116] btrfs: stripe_alloc: relocate a queued stripe
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index c6ff2a7dc6010..2442d3f274bbc 100644
+index d9097e961f2a8..64030c597705f 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -4479,12 +4479,21 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -4481,12 +4481,21 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
spin_lock(&space_info->lock);
spin_lock(&bg->lock);
-From 6c71f48b7ba8a42c9cf25656b8c5e199be0e22e8 Mon Sep 17 00:00:00 2001
+From 62783d7e1cf15e3bf7142abededac55926f35cb3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:07 -0400
Subject: [RFC PATCH 048/116] btrfs: stripe_meta: maintain trapped free space
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 2442d3f274bbc..4369501c81eec 100644
+index 64030c597705f..ef7f53471de4a 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2672,7 +2672,13 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
continue;
down_read(&sinfo->groups_sem);
for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) {
-@@ -3929,8 +3935,16 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -3931,8 +3937,16 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
* btrfs_can_overcommit check here, and we need to pass in
* BTRFS_RESERVE_NO_FLUSH to give ourselves the most amount of
* leeway to allow us to mark this block group as read only.
}
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 58f02314aef85..0c23fa3429dbe 100644
+index b49c551276dd5..c005065b2b532 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2158,7 +2158,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2168,7 +2168,7 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
u64 trapped;
u64 claimable;
return;
spin_lock(&ctl->tree_lock);
-@@ -2238,7 +2238,7 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2248,7 +2248,7 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
u64 nstripes;
u32 *freep;
-From dcb5f0fbf44351d3d5ef2175b66c35649609deb8 Mon Sep 17 00:00:00 2001
+From 0af088bb8082f875a17f43d079ce2118ced9b8f7 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:08 -0400
Subject: [RFC PATCH 049/116] btrfs: stripe_meta: back the global reserve with
-From 04bca28a857b67ce23c2b2a8805cb17eca9bbd4b Mon Sep 17 00:00:00 2001
+From a2d61f5c5b26a8f88bc1f79eb1236e290937624c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:12 -0400
Subject: [RFC PATCH 050/116] btrfs: stripe_meta: hold back whole stripes so
6 files changed, 125 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4369501c81eec..849b91807485f 100644
+index ef7f53471de4a..3225bc71af203 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2006,8 +2006,21 @@ static void stripe_alloc_sweep_groups(struct btrfs_fs_info *fs_info, bool arm)
/*
* The rescan usually lowers the counter (mid-transaction
* incremental adds overcount conservatively); admission
-@@ -3944,7 +3997,7 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -3946,7 +3999,7 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
if (READ_ONCE(cache->stripe_unusable_ready))
trapped = min(READ_ONCE(cache->stripe_unusable), num_bytes);
if (btrfs_can_overcommit(sinfo, num_bytes - trapped,
out_put_rc:
put_reloc_control(rc);
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 3d74bdea16cac..1afec444a0f32 100644
+index 1e9946369c184..df50d0c7e1fd2 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -187,6 +187,8 @@ struct reserve_ticket {
struct list_head list;
wait_queue_head_t wait;
spinlock_t lock;
-@@ -614,7 +616,7 @@ static inline bool can_overcommit(const struct btrfs_space_info *space_info,
+@@ -612,7 +614,7 @@ static inline bool can_overcommit(const struct btrfs_space_info *space_info,
}
bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
{
u64 used;
-@@ -623,6 +625,13 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
+@@ -621,6 +623,13 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
return false;
used = btrfs_space_info_used(space_info, true);
return check_can_overcommit(space_info, used, bytes, flush);
}
-@@ -759,14 +768,22 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
+@@ -757,14 +766,22 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
while (!list_empty(head)) {
struct reserve_ticket *ticket;
u64 used_after;
btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes);
remove_ticket(space_info, ticket, 0);
space_info->tickets_id++;
-@@ -815,13 +832,13 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
+@@ -813,13 +830,13 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
(s64)(info->total_bytes - btrfs_space_info_used(info, true)),
info->full ? "" : "not ");
btrfs_info(fs_info,
}
void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
-@@ -1964,6 +1981,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -1962,6 +1979,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
u64 used;
int ret = -ENOSPC;
bool pending_tickets;
ASSERT(orig_bytes, "orig_bytes=%llu", orig_bytes);
/*
-@@ -2003,6 +2022,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2001,6 +2020,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
* Carry on if we have enough space (short-circuit) OR call
* can_overcommit() to ensure we can overcommit to continue.
*/
if (!pending_tickets &&
((used + orig_bytes <= space_info->total_bytes) ||
can_overcommit(space_info, used, orig_bytes, flush)) &&
-@@ -2039,6 +2060,7 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2037,6 +2058,7 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
init_waitqueue_head(&ticket.wait);
spin_lock_init(&ticket.lock);
ticket.steal = can_steal(flush);
start_ns = ktime_get_ns();
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 702222bb54ae4..e9a984a7af34e 100644
+index 5abb8fd072b3c..6a3711ae00cf3 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -192,7 +192,25 @@ struct btrfs_space_info {
(may_use_included ? s_info->bytes_may_use : 0);
}
-@@ -359,7 +378,7 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
+@@ -358,7 +377,7 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
enum btrfs_reserve_flush_enum flush);
void btrfs_try_granting_tickets(struct btrfs_space_info *space_info);
bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
static inline void btrfs_space_info_free_bytes_may_use(
struct btrfs_space_info *space_info,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 6eb2d5362f204..ba2392dcb4efa 100644
+index 0369a7c04c54f..cb844168fde51 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -821,6 +821,7 @@ SPACE_INFO_ATTR(bytes_stripe_unusable);
-From 7cff178b3a5b7d534853720b13afc9fb1021acbd Mon Sep 17 00:00:00 2001
+From a345272f69ec86151bdbbf98cbcd474333c50386 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:13 -0400
Subject: [RFC PATCH 051/116] btrfs: stripe_meta: do not steal from the global
3 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index a75fb22137e39..5e172348ee019 100644
+index 37d87114f69e4..8986bab67590e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -3125,17 +3125,22 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
+@@ -3145,17 +3145,22 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
if (ret)
return ret;
/* data_alloc_cluster is only used in ssd_spread mode */
struct btrfs_free_cluster data_alloc_cluster;
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 1afec444a0f32..a35fa570e3a7d 100644
+index df50d0c7e1fd2..ed883c7b398cb 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -189,6 +189,8 @@ struct reserve_ticket {
struct list_head list;
wait_queue_head_t wait;
spinlock_t lock;
-@@ -1288,6 +1290,28 @@ static bool steal_from_global_rsv(struct btrfs_space_info *space_info,
+@@ -1286,6 +1288,28 @@ static bool steal_from_global_rsv(struct btrfs_space_info *space_info,
if (global_rsv->space_info != space_info)
return false;
spin_lock(&global_rsv->lock);
min_bytes = mult_perc(global_rsv->size, 10);
if (global_rsv->reserved < min_bytes + ticket->bytes) {
-@@ -2061,6 +2085,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2059,6 +2083,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
spin_lock_init(&ticket.lock);
ticket.steal = can_steal(flush);
ticket.reloc = reloc;
-From dafd9cfe4b2fdba8bea8b5293b466176a027531b Mon Sep 17 00:00:00 2001
+From e14fa735950e55e7e840b6e6a5c60af1bf5525e1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:14 -0400
Subject: [RFC PATCH 052/116] btrfs: stripe_meta: let the transaction
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index a35fa570e3a7d..361c4d40e90fd 100644
+index ed883c7b398cb..41ade2b7e89a1 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -2005,8 +2005,20 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2003,8 +2003,20 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
u64 used;
int ret = -ENOSPC;
bool pending_tickets;
-From 4186b21d2136070c7e62e6ac601cb081752329c1 Mon Sep 17 00:00:00 2001
+From 046e0e80fdb7b805226ce232e0302807a1d4c4af Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:15 -0400
Subject: [RFC PATCH 053/116] btrfs: stripe_meta: let a group go read-only for
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 849b91807485f..b8244895a213f 100644
+index 3225bc71af203..6032c4dc6f7fe 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -3996,8 +3996,15 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -3998,8 +3998,15 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
if (READ_ONCE(cache->stripe_unusable_ready))
trapped = min(READ_ONCE(cache->stripe_unusable), num_bytes);
-From a672e3917d47044aece23d6b98ff97c10ef29f16 Mon Sep 17 00:00:00 2001
+From b3cc985b256acbf78501db4bf618b11f962e5663 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:16 -0400
Subject: [RFC PATCH 054/116] btrfs: stripe_alloc: show per-group trapped bytes
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 361c4d40e90fd..5f8da071417a0 100644
+index 41ade2b7e89a1..07e5aacc07c58 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -866,11 +866,15 @@ void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
+@@ -864,11 +864,15 @@ void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
spin_lock(&cache->lock);
avail = btrfs_block_group_available_space(cache);
-From 7310972a63b8be7d9d744724270bf91f6e6f099b Mon Sep 17 00:00:00 2001
+From b6509d0f3eb7ec6b053b7e4881f0beeac41b6ab2 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:17 -0400
Subject: [RFC PATCH 055/116] btrfs: stripe_alloc: tell a dead tree block from
atomic64_t congestion_short;
} stripe_park_stats;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index d95211d124ef4..e9ccf168693a5 100644
+index d1e961ce4e490..7a825b3507033 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3023,6 +3023,66 @@ static bool rmw_peek_eb_generation(struct btrfs_raid_bio *rbio, u32 i,
+@@ -3040,6 +3040,66 @@ static bool rmw_peek_eb_generation(struct btrfs_raid_bio *rbio, u32 i,
return found_bytenr == logical && !bad_fsid;
}
/*
* Decide whether an uncovered read-modify-write is a write hole or only a
* cost, by looking at what is actually in the stripe.
-@@ -3099,10 +3159,36 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3116,10 +3176,36 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_cur);
continue;
}
+ const int stripe_nr = i / rbio->stripe_nsectors;
+ const int sectornr = i % rbio->stripe_nsectors;
+ const u64 logical = rbio->bioc->full_stripe_logical +
-+ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)stripe_nr * rbio->bioc->stripe_len +
+ (u64)sectornr * fs_info->sectorsize;
+ u64 refs;
+ u64 egen;
}
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index ba2392dcb4efa..609c6b458280f 100644
+index cb844168fde51..1481ed2cf1571 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1140,6 +1140,7 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 3ba7acf2e3c5e7ab07529aff1b016b49f0a8de40 Mon Sep 17 00:00:00 2001
+From 868e49a6d6d0474e799e3fb02bc41ab131b379d9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:18 -0400
Subject: [RFC PATCH 056/116] btrfs: stripe_alloc: do not read an inline
1 file changed, 15 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index b8244895a213f..f69fc42484d97 100644
+index 6032c4dc6f7fe..09a6f47937882 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1437,6 +1437,21 @@ static bool stripe_extents_owned_by(struct btrfs_fs_info *fs_info,
-From 72db9e2da64153d2e8f18458e596483dab5902e5 Mon Sep 17 00:00:00 2001
+From 46a0df1d2260a3afec5094779745bc6878f564ce Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:19 -0400
Subject: [RFC PATCH 057/116] btrfs: stripe_alloc: count whole stripes stranded
6 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index f69fc42484d97..ac086a889631d 100644
+index 09a6f47937882..94c5bbe457907 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -686,6 +686,14 @@ static void free_open_stripe_run(struct btrfs_block_group *bg,
u64 run_start, u64 *run_len);
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 0c23fa3429dbe..6ec021f23ed1a 100644
+index c005065b2b532..5e8362205e3b9 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2091,6 +2091,13 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
+@@ -2101,6 +2101,13 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
"stripe_unusable_scan counted=%llu != free_space=%llu",
counted, ctl->free_space);
for (i = 0; i < nstripes; i++)
if (freep[i] && freep[i] < fsl)
trapped += freep[i];
-@@ -2206,7 +2213,13 @@ bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
+@@ -2216,7 +2223,13 @@ bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
struct btrfs_space_info *sinfo = bg->space_info;
const int thresh = READ_ONCE(sinfo->bg_reclaim_threshold);
const u64 used = READ_ONCE(bg->used);
u64 promised;
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 5f8da071417a0..39e5165923dc0 100644
+index 07e5aacc07c58..0c5757218960f 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -834,11 +834,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
+@@ -832,11 +832,12 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
(s64)(info->total_bytes - btrfs_space_info_used(info, true)),
info->full ? "" : "not ");
btrfs_info(fs_info,
info->bytes_stripe_margin, info->bytes_stripe_reserve);
}
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index e9a984a7af34e..34d8491e2605f 100644
+index 6a3711ae00cf3..b4d7e2ad9daf8 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -166,6 +166,11 @@ struct btrfs_space_info {
in the group dedicated to data
relocation (fs_info->data_reloc_bg):
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 609c6b458280f..d583ce8dee057 100644
+index 1481ed2cf1571..391eeabd029f8 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -818,6 +818,7 @@ SPACE_INFO_ATTR(bytes_may_use);
-From 8d46931722459e4cace54fe7215127319d21744a Mon Sep 17 00:00:00 2001
+From 2c0f474a19cfc3a7cd92e3e19a78097cf20ea3ff Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:19 -0400
Subject: [RFC PATCH 058/116] btrfs: stripe_alloc: give nocow extents a private
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index ac086a889631d..1a388d5fa1974 100644
+index 94c5bbe457907..c13d6e4d4f8ae 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -507,6 +507,7 @@ struct btrfs_open_stripe_run {
-From 3e051c111fc267a5cc6ba4d9697008d527787ebe Mon Sep 17 00:00:00 2001
+From 6a7339d6329e4cb1899e0ef9d379aa6e58bb63f0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:20 -0400
Subject: [RFC PATCH 059/116] btrfs: stripe_alloc: count nocow run lifecycles
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 1a388d5fa1974..d63568da84101 100644
+index c13d6e4d4f8ae..5edba31e090d3 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -693,8 +693,10 @@ static void free_open_stripe_run(struct btrfs_block_group *bg,
u32 stripe_rmw_opt;
u32 stripe_rmw_prop;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index d583ce8dee057..4a613361d0958 100644
+index 391eeabd029f8..786a6dbb02fe0 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1170,6 +1170,23 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From e6d0215595c784679b9190d820a1ece1741b7bc0 Mon Sep 17 00:00:00 2001
+From 452563014c9870e31709cf8dd8a271d8b0fdb26f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:21 -0400
Subject: [RFC PATCH 060/116] btrfs: stripe_alloc: hold a stripe of margin
goto out_unlock;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 7b5e55c926e17..512d4c579b4e3 100644
+index 98d376ce99eb8..d5732d8938f14 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -9945,6 +9945,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -9943,6 +9943,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
u64 num_bytes, ram_bytes, disk_num_bytes;
struct btrfs_key ins;
bool extent_reserved = false;
struct extent_map *em;
ssize_t ret;
-@@ -10086,7 +10087,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10084,7 +10085,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
* We don't use the higher-level delalloc space functions because our
* num_bytes and disk_num_bytes are different.
*/
if (ret)
goto out_unlock;
ret = btrfs_qgroup_reserve_data(inode, &data_reserved, start, num_bytes);
-@@ -10115,6 +10117,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10113,6 +10115,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
ret = btrfs_reserve_extent(root, inode, disk_num_bytes, disk_num_bytes,
disk_num_bytes, 0, 0, &ins, true, true,
false);
if (ret)
goto out_delalloc_release;
extent_reserved = true;
-@@ -10163,6 +10167,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10161,6 +10165,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
if (ret < 0)
btrfs_qgroup_free_data(inode, data_reserved, start, num_bytes, NULL);
out_free_data_space:
if (cur_offset < prealloc_end)
btrfs_free_reserved_data_space_noquota(inode,
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 39e5165923dc0..e9a6d4df82c7c 100644
+index 0c5757218960f..a672d1b304cfb 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -191,6 +191,13 @@ struct reserve_ticket {
struct list_head list;
wait_queue_head_t wait;
spinlock_t lock;
-@@ -487,6 +494,52 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
+@@ -485,6 +492,52 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
spin_unlock(&sinfo->lock);
}
struct btrfs_space_info *btrfs_find_space_info(const struct btrfs_fs_info *info,
u64 flags)
-@@ -787,6 +840,8 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
+@@ -785,6 +838,8 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
can_overcommit(space_info, tused, ticket->bytes, flush)) &&
stripe_claimable_admit(space_info, ticket->bytes, ticket->reloc)) {
btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes);
remove_ticket(space_info, ticket, 0);
space_info->tickets_id++;
used = used_after;
-@@ -2000,8 +2055,8 @@ static inline bool can_ticket(enum btrfs_reserve_flush_enum flush)
+@@ -1998,8 +2053,8 @@ static inline bool can_ticket(enum btrfs_reserve_flush_enum flush)
* regain reservations will be made and this will fail if there is not enough
* space already.
*/
{
struct btrfs_fs_info *fs_info = space_info->fs_info;
struct work_struct *async_work;
-@@ -2071,6 +2126,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2069,6 +2124,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
stripe_claimable_admit(space_info, orig_bytes,
flush == BTRFS_RESERVE_FLUSH_DATA_RELOC)) {
btrfs_space_info_update_bytes_may_use(space_info, orig_bytes);
ret = 0;
}
-@@ -2104,6 +2161,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2102,6 +2159,8 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
ticket.reloc = reloc;
ticket.mount_cleanup =
READ_ONCE(fs_info->mount_cleanup_task) == current;
if (trace_btrfs_reserve_ticket_enabled())
start_ns = ktime_get_ns();
-@@ -2151,7 +2210,10 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
+@@ -2149,7 +2208,10 @@ static int reserve_bytes(struct btrfs_space_info *space_info, u64 orig_bytes,
if (!ret || !can_ticket(flush))
return ret;
}
/*
-@@ -2174,7 +2236,7 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
+@@ -2172,7 +2234,7 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
{
int ret;
if (ret == -ENOSPC) {
struct btrfs_fs_info *fs_info = space_info->fs_info;
-@@ -2199,6 +2261,18 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
+@@ -2197,6 +2259,18 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
*/
int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
enum btrfs_reserve_flush_enum flush)
{
struct btrfs_fs_info *fs_info = space_info->fs_info;
int ret;
-@@ -2213,7 +2287,9 @@ int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
+@@ -2211,7 +2285,9 @@ int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
"current->journal_info=0x%lx flush=%d",
(unsigned long)current->journal_info, flush);
trace_btrfs_space_reservation(fs_info, "space_info:enospc",
space_info->flags, bytes, 1);
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 34d8491e2605f..9031719314ec2 100644
+index b4d7e2ad9daf8..61f942e0141d0 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -369,6 +369,9 @@ struct btrfs_inode;
+int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes,
+ enum btrfs_reserve_flush_enum flush, u64 *held);
+void btrfs_stripe_prealloc_release(struct btrfs_fs_info *fs_info, u64 held);
- void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
- struct btrfs_block_group *block_group);
+ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group);
void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
+ u64 chunk_size);
--
2.47.3
-From 9c3f5e2a5a7c2e6b251c0014c132b7341065a71f Mon Sep 17 00:00:00 2001
+From 8896655ef1341641de95f80d6ae08632f18e25df Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:22 -0400
Subject: [RFC PATCH 061/116] btrfs: stripe_meta: carry raid56 metadata groups
1 file changed, 37 insertions(+), 18 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index d63568da84101..f880280200672 100644
+index 5edba31e090d3..aa1eee2a61ca5 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2080,8 +2080,9 @@ int btrfs_stripe_alloc_check_support(struct btrfs_fs_info *fs_info)
-From 6269c79f5f2d9e468f4bb02952cb0cef6dae89d4 Mon Sep 17 00:00:00 2001
+From 0fd02d55577b85d92fb6429ed2065691fa3ce01e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:23 -0400
Subject: [RFC PATCH 062/116] btrfs: stripe_alloc: return a group's allocation
1 file changed, 27 insertions(+)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 6ec021f23ed1a..9809c4106f95f 100644
+index 5e8362205e3b9..d01d480609b6a 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2104,6 +2104,31 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
+@@ -2114,6 +2114,31 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
return trapped;
}
/*
* Compute a stripe_alloc block group's initial trapped free space once its
* free space cache is loaded, and enable incremental accounting from here on.
-@@ -2126,6 +2151,7 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2136,6 +2161,7 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
if (!freep)
return;
spin_lock(&ctl->tree_lock);
if (bg->stripe_unusable_ready) {
spin_unlock(&ctl->tree_lock);
-@@ -2259,6 +2285,7 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2269,6 +2295,7 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
if (!freep)
return;
-From ec648ceaf7412f288964cd2f969132a3c886478a Mon Sep 17 00:00:00 2001
+From 3fe10c2fdcd6ba4afb17117499cf4403d11d132f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:24 -0400
Subject: [RFC PATCH 063/116] btrfs: stripe_alloc: release open stripe runs
3 files changed, 47 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index f880280200672..5e5381195d1e3 100644
+index aa1eee2a61ca5..98f78ca7897fc 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2551,6 +2551,50 @@ void btrfs_retire_block_group_stripes(struct btrfs_block_group *bg)
bool btrfs_stripe_in_open_run(struct btrfs_fs_info *fs_info, u64 logical);
bool btrfs_defer_stripe_meta_write(struct btrfs_fs_info *fs_info,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 5e172348ee019..b40f2a19abf3e 100644
+index 8986bab67590e..8c5070a598750 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -3836,6 +3836,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
+@@ -3856,6 +3856,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
fail_sb_buffer:
btrfs_stop_all_workers(fs_info);
btrfs_free_block_groups(fs_info);
fail_alloc:
btrfs_mapping_tree_free(fs_info);
-@@ -4607,6 +4608,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
+@@ -4627,6 +4628,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
* accounting appear to be wrong because there's pending reserved bytes,
* so make sure we do the block group cleanup afterwards.
*/
-From d7611f8eab54eddec75365914a085acbfe30808f Mon Sep 17 00:00:00 2001
+From 4b5986416d18781e2714aa6fda831007af8f2d95 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:25 -0400
Subject: [RFC PATCH 064/116] btrfs: stripe_alloc: say at mount whether the
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 5e5381195d1e3..8085c9998be90 100644
+index 98f78ca7897fc..9e4369b8b99f7 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2221,10 +2221,16 @@ int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info)
}
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index 4416fd622019d..d329181b98e9e 100644
+index a64d9cd48d12e..903bce51fb1fd 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -943,6 +943,23 @@ static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objec
-From 5f54dd568678edd647946e21d412f18c0aa344a4 Mon Sep 17 00:00:00 2001
+From cbab48fd82cc6f288ad264a5afcad068e2343b03 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 20 Sep 2026 01:33:09 -0400
Subject: [RFC PATCH 065/116] btrfs: stripe_meta: cover raid56 system chunks
3 files changed, 52 insertions(+), 39 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 8085c9998be90..28e64f7009e88 100644
+index 9e4369b8b99f7..60fcfde839ba1 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2092,7 +2092,8 @@ static void stripe_alloc_sweep_groups(struct btrfs_fs_info *fs_info, bool arm)
continue;
down_read(&sinfo->groups_sem);
for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) {
-@@ -4947,7 +4922,8 @@ static void btrfs_stripe_reclaim_tick(struct btrfs_fs_info *fs_info)
+@@ -4949,7 +4924,8 @@ static void btrfs_stripe_reclaim_tick(struct btrfs_fs_info *fs_info)
int raid;
if (!(sinfo->flags & (BTRFS_BLOCK_GROUP_DATA |
continue;
if (READ_ONCE(sinfo->bg_reclaim_threshold) <= 0)
continue;
-@@ -7006,6 +6982,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
+@@ -7009,6 +6985,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_space_info *info;
u64 left;
bool want_system_chunk, need_system_chunk;
int ret = 0;
-@@ -7020,12 +6997,41 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
+@@ -7023,12 +7000,41 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
spin_lock(&info->lock);
left = info->total_bytes - btrfs_space_info_used(info, true);
want_system_chunk = info->total_bytes < system_space_target(info);
(bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK);
}
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index e9ccf168693a5..13031c46b1f57 100644
+index 7a825b3507033..abfadfec54f5a 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3231,9 +3231,9 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3248,9 +3248,9 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
* A raid56 metadata group under stripe_meta is covered: its
* read-modify-writes are partial writes inside one transaction's
* run, counted by the audit as meta_rmw_cur, and the audit warns
-From b57d7b9fd543eb50dcd6f234944b65cc5cc12eed Mon Sep 17 00:00:00 2001
+From 6c7a6f089b7eacf99d6026721884742426ce0ff3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 23 Sep 2026 01:47:12 -0400
Subject: [RFC PATCH 066/116] btrfs: stripe_alloc: close dead nocow stripe runs
5 files changed, 92 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 28e64f7009e88..5c20aadf6985b 100644
+index 60fcfde839ba1..4b821c9af73e9 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -664,6 +664,33 @@ static void run_live_set(struct btrfs_open_stripe_run *run, u64 start, u64 len,
u64 run_start, u64 *run_len);
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 9809c4106f95f..0d5bb057d4f33 100644
+index d01d480609b6a..2c3e32aea935c 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1616,6 +1616,7 @@ int btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1626,6 +1626,7 @@ int btrfs_add_free_space(struct btrfs_block_group *block_group,
stripe_unusable_mark_dirty(block_group);
stripe_unusable_account_add(block_group, bytenr, size);
/* BTRFS_STRIPE_RMW_* masks; see btrfs_stripe_allow_rmw(). */
u32 stripe_rmw_opt;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 4a613361d0958..69568759eaaa1 100644
+index 786a6dbb02fe0..f367a0fc707a9 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1179,11 +1179,13 @@ static ssize_t btrfs_stripe_run_stats_show(struct kobject *kobj,
-From be6877e4568053ef1d4b08e76f14ff5d7514345d Mon Sep 17 00:00:00 2001
+From fa5cdd7e9ffe41c2e15e670e59a8020924f641d5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 23 Sep 2026 15:30:45 -0400
Subject: [RFC PATCH 067/116] btrfs: stripe_alloc: do not round a full stripe
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 5c20aadf6985b..d6fc1f165ae5c 100644
+index 4b821c9af73e9..c893d0f299f72 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -584,6 +584,27 @@ static bool open_stripe_run_drained(const struct btrfs_open_stripe_run *run)
-From 24b8a9adadc5b04e224ff065efde5cde14e3e2a3 Mon Sep 17 00:00:00 2001
+From 378ae1181fb6c49489157587062078b9f8ca5769 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 24 Sep 2026 02:21:12 -0400
Subject: [RFC PATCH 068/116] btrfs: stripe_alloc: do not wait for stripe runs
3 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index d6fc1f165ae5c..867959fc1b484 100644
+index c893d0f299f72..9fc41fe73cb06 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2610,14 +2610,45 @@ static bool bg_open_stripes_settled(struct btrfs_block_group *bg, u64 seq)
}
/*
-@@ -4931,6 +4962,11 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -4933,6 +4964,11 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
LIST_HEAD(retry_list);
int reclaimed = 0;
-From 22e42d6d532311a8e03edbb8b36a73668ad6e173 Mon Sep 17 00:00:00 2001
+From 40ab3d57819b5a60d8a52de1c2eb33932ddf8f4e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 24 Sep 2026 07:55:39 -0400
Subject: [RFC PATCH 069/116] btrfs: stripe_alloc: end the commit-time and log
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 867959fc1b484..725c4af39f21e 100644
+index 9fc41fe73cb06..289ec278ac4f8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2131,7 +2131,8 @@ void btrfs_log_settle_stripes(struct btrfs_inode *inode, u64 file_start,
-From 9997aec01d002fa95fc96f0372fdab6f30f74882 Mon Sep 17 00:00:00 2001
+From bda94d6e75730c4a28cbfcf5004ac9c16c644626 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 29 Sep 2026 05:29:38 -0400
Subject: [RFC PATCH 070/116] btrfs: stripe_alloc: compact mostly live groups
10 files changed, 511 insertions(+), 42 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 725c4af39f21e..3718d69e95955 100644
+index 289ec278ac4f8..e39f266016306 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -4800,6 +4800,7 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -4802,6 +4802,7 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
u64 reserved;
u64 old_total;
int ret = 0;
/*
* A stripe_alloc / stripe_meta group's live extents can only move into
-@@ -4813,9 +4814,13 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -4815,9 +4816,13 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
*/
if (btrfs_is_stripe_alloc_bg(bg) || btrfs_is_stripe_meta_bg(bg)) {
u64 elsewhere = READ_ONCE(space_info->bytes_stripe_claimable);
struct btrfs_trans_handle *trans;
trans = btrfs_join_transaction(fs_info->tree_root);
-@@ -4887,10 +4892,19 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -4889,10 +4894,19 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
* the first place.
*/
if (!should_reclaim_block_group(bg, bg->length)) {
}
spin_unlock(&bg->lock);
-@@ -4938,7 +4952,23 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -4940,7 +4954,23 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
spin_unlock(&bg->lock);
trace_btrfs_reclaim_block_group(bg);
btrfs_dec_block_group_ro(bg);
btrfs_debug(fs_info, "deferring reclaim of chunk %llu", bg->start);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index b40f2a19abf3e..a7841e98811be 100644
+index 8c5070a598750..3d3a51cd963d0 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2786,6 +2786,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2806,6 +2806,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->open_stripe_bgs);
INIT_WORK(&fs_info->stripe_alloc_enable_work, btrfs_stripe_alloc_enable_work);
fs_info->stripe_park_timeout_ms = BTRFS_RBIO_PARK_TIMEOUT_MS;
spin_lock_init(&fs_info->open_stripe_lock);
spin_lock_init(&fs_info->delalloc_root_lock);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 0d5bb057d4f33..b9768adf48c5d 100644
+index 2c3e32aea935c..f0c3187554deb 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2038,26 +2038,18 @@ static u64 stripe_unusable_nstripes(const struct btrfs_block_group *bg)
+@@ -2048,26 +2048,18 @@ static u64 stripe_unusable_nstripes(const struct btrfs_block_group *bg)
}
/*
lockdep_assert_held(&ctl->tree_lock);
-@@ -2086,6 +2078,29 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
+@@ -2096,6 +2088,29 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
e->offset + e->bytes, &counted);
}
}
/* Every free byte was distributed to exactly one stripe (debug check). */
ASSERT(counted == ctl->free_space,
-@@ -2105,6 +2120,38 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
+@@ -2115,6 +2130,38 @@ static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
return trapped;
}
/*
* The legacy allocator parks a group's free space in an allocation cluster
* (for a metadata group, its whole initial extent), where the group's own
-@@ -2224,18 +2271,26 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2234,18 +2281,26 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
* zoned's zone_unusable reclaim: once enough of the group's FREE space is
* trapped in partially used stripes (zoned compares with the capacity, but a
* stripe group also holds claimable whole stripes), relocation packs the live
{
struct btrfs_space_info *sinfo = bg->space_info;
const int thresh = READ_ONCE(sinfo->bg_reclaim_threshold);
-@@ -2247,21 +2302,55 @@ bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
+@@ -2257,21 +2312,55 @@ bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
* relocating the group would only force that.
*/
const u64 trapped = unusable - min(unusable, READ_ONCE(bg->stripe_stranded));
int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 69568759eaaa1..34284d504564d 100644
+index f367a0fc707a9..1f14e9a16f5bc 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1180,12 +1180,20 @@ static ssize_t btrfs_stripe_run_stats_show(struct kobject *kobj,
NULL,
};
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d3e6a9b429dd9..422bd66239239 100644
+index ce78a9441c64f..6e7419b87ddcd 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -3732,7 +3732,8 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
+@@ -3737,7 +3737,8 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
return ret;
}
{
struct btrfs_block_group *block_group;
int ret;
-@@ -3759,7 +3760,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3764,7 +3765,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
/* step one, relocate all the extents inside this chunk */
btrfs_scrub_pause(fs_info);
btrfs_scrub_continue(fs_info);
if (ret) {
/*
-@@ -3771,6 +3772,10 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3776,6 +3777,10 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
return ret;
}
block_group = btrfs_lookup_block_group(fs_info, chunk_offset);
if (!block_group)
return -ENOENT;
-@@ -3786,6 +3791,25 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3791,6 +3796,25 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
return ret;
}
{
struct btrfs_root *chunk_root = fs_info->chunk_root;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 6eddda2392215..e99caf4e36a1e 100644
+index 75b1179776c80..982d88264ca5a 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -783,6 +783,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
+@@ -787,6 +787,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset,
bool verbose);
-From a4e8a846911c3922128fb10291ebf3a8113e0b09 Mon Sep 17 00:00:00 2001
+From 81b9d74a3c498c8df94b99b9d6c72c68f077ce04 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 30 Sep 2026 18:07:52 -0400
Subject: [RFC PATCH 071/116] btrfs: stripe_alloc: attribute each data
6 files changed, 153 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 3718d69e95955..ebb46e896a278 100644
+index e39f266016306..9c032d762b8f4 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1792,13 +1792,19 @@ bool btrfs_stripe_run_pad_mask(struct btrfs_fs_info *fs_info, u64 stripe_start,
/*
* Breakdown of what a metadata read-modify-write found in the
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 13031c46b1f57..5ad9c388e5f04 100644
+index abfadfec54f5a..1195f667784ca 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -22,6 +22,7 @@
/*
* Set when a parked rbio carries (or merged) a REQ_SYNC bio: a waiter
* is blocked on it, so deadlines stay authoritative and neither the
-@@ -2854,6 +2858,65 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2871,6 +2875,65 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
}
}
/*
* Try to avoid the RMW read phase of a sub-stripe write by zero-filling
* the uncovered data sectors. Legal only where the stripe's run says the
-@@ -2875,6 +2938,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2892,6 +2955,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
bool ok = false;
int i;
if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
return false;
-@@ -2883,6 +2947,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2900,6 +2964,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
return false;
if (!btrfs_stripe_run_pad_mask(fs_info, stripe_start, stripe_len, dead,
&info)) {
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, 0, nsectors,
info.run_start, info.run_end,
-@@ -2912,6 +2977,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2929,6 +2994,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
if (!test_bit(i, dead)) {
atomic64_inc(&fs_info->stripe_park_stats.pad_decline_uncovered);
info.reason = BTRFS_STRIPE_PAD_UNCOVERED;
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, covered,
nsectors,
-@@ -2929,6 +2995,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2946,6 +3012,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
if (!ok)
return false;
if (alloc_rbio_data_pages(rbio) < 0)
return false;
-@@ -3298,6 +3366,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3315,6 +3383,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
* count that should be zero.
*/
atomic64_inc(&fs_info->stripe_park_stats.data_rmw);
if (test_bit(RBIO_WAS_PARKED_BIT, &rbio->flags))
atomic64_inc(&fs_info->stripe_park_stats.rmw_reads);
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index ca15c45f8f4be..5fcf4ff346bc2 100644
+index 11b843095903e..56e0e9790473a 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -146,6 +146,15 @@ struct btrfs_raid_bio {
+@@ -144,6 +144,15 @@ struct btrfs_raid_bio {
/* Flags that tell us if it is safe to merge with this bio. */
unsigned long flags;
* Set if we're doing a parity rebuild for a read from higher up, which
* is handled differently from a parity rebuild as part of RMW.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 34284d504564d..95ea71d1c261c 100644
+index 1f14e9a16f5bc..eefb17551e594 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1139,6 +1139,20 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From e463b8e99b116061c0753e4af1e2aa570dec4222 Mon Sep 17 00:00:00 2001
+From db1269b9f63e72b7581f48836f4919c8607d28f3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 30 Sep 2026 18:07:56 -0400
Subject: [RFC PATCH 072/116] btrfs: stripe_alloc: optionally audit data
6 files changed, 402 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index ebb46e896a278..89827b2e3a777 100644
+index 9c032d762b8f4..e63ca269e6721 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1817,6 +1817,8 @@ bool btrfs_stripe_run_pad_mask(struct btrfs_fs_info *fs_info, u64 stripe_start,
* Stripe run lifecycle observability: lifetime counters exposed
* through sysfs stripe_run_stats, so a test can show it exercised
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5ad9c388e5f04..73750065ebc85 100644
+index 1195f667784ca..865ecb86b9ead 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -23,6 +23,7 @@
/* set when additional merges to this rbio are not allowed */
#define RBIO_RMW_LOCKED_BIT 1
-@@ -2863,6 +2864,13 @@ static void rbio_record_pad(struct btrfs_raid_bio *rbio,
+@@ -2880,6 +2881,13 @@ static void rbio_record_pad(struct btrfs_raid_bio *rbio,
{
rbio->pad_reason = info->reason;
rbio->pad_norun = info->norun;
}
static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
-@@ -2870,6 +2878,302 @@ static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
+@@ -2887,6 +2895,302 @@ static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
static_assert(BTRFS_STRIPE_NORUN_NR ==
ARRAY_SIZE(((struct btrfs_fs_info *)0)->stripe_park_stats.data_rmw_norun));
+ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
+ const u64 stripe_start = rbio->bioc->full_stripe_logical;
+ const u64 stripe_end = stripe_start +
-+ (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
++ (u64)rbio->nr_data * rbio->bioc->stripe_len;
+ const u32 bits = fs_info->sectorsize_bits;
+ struct btrfs_root *extent_root = btrfs_extent_root(fs_info, stripe_start);
+ struct rmw_audit_ext e = { 0 };
/*
* Attribute a read-modify-write to why padding declined for this rbio. With
* allow_rmw empty, a data RMW in a stripe_alloc group is expected in two
-@@ -2915,6 +3219,8 @@ static void rbio_count_rmw_reason(struct btrfs_raid_bio *rbio)
+@@ -2932,6 +3236,8 @@ static void rbio_count_rmw_reason(struct btrfs_raid_bio *rbio)
/* Disjoint from the frontier count, so the two can be summed. */
if (reloc_writer && idx != BTRFS_STRIPE_PAD_UNCOVERED)
atomic64_inc(&fs_info->stripe_park_stats.data_rmw_reloc_writer);
/*
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 5fcf4ff346bc2..99ba94032dd91 100644
+index 56e0e9790473a..8a618b86a5f18 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -154,6 +154,14 @@ struct btrfs_raid_bio {
+@@ -152,6 +152,14 @@ struct btrfs_raid_bio {
*/
u8 pad_reason;
u8 pad_norun;
/*
* Set if we're doing a parity rebuild for a read from higher up, which
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 95ea71d1c261c..1ace1fc52cca4 100644
+index eefb17551e594..8895a53668415 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -525,7 +525,70 @@ static const struct attribute *discard_attrs[] = {
-From 44a1ac24083c094fe75d4a6f4eb9ed05b13af283 Mon Sep 17 00:00:00 2001
+From f5fc101c0c49bbd2ca341ad13bdf8d495daa2899 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 00:57:50 -0400
Subject: [RFC PATCH 073/116] btrfs: stripe_alloc: keep relocation's stripe
3 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 89827b2e3a777..b43728684b9c1 100644
+index e63ca269e6721..946102aea2df6 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -508,6 +508,12 @@ struct btrfs_open_stripe_run {
atomic64_t compact_runs;
/* compaction plans over the cap, relocated whole instead */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 1ace1fc52cca4..d7b4dafdc80b6 100644
+index 8895a53668415..5cbff0b128288 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1272,6 +1272,8 @@ static ssize_t btrfs_stripe_run_stats_show(struct kobject *kobj,
-From c0886d0274af757dfa3f0be8a04667ea3e62c481 Mon Sep 17 00:00:00 2001
+From 064683b6372aa03e0064c377b0c95b2057c94ad0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 04:20:09 -0400
Subject: [RFC PATCH 074/116] btrfs: stripe_alloc: let relocation allocate a
1 file changed, 32 insertions(+)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index e9a6d4df82c7c..5636c4dc60e89 100644
+index a672d1b304cfb..1dcd20f69fcb1 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -2259,6 +2259,28 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
+@@ -2257,6 +2257,28 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
* This will reserve bytes from the data space info. If there is not enough
* space then we will attempt to flush space as specified by flush.
*/
int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
enum btrfs_reserve_flush_enum flush)
{
-@@ -2290,6 +2312,16 @@ int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes
+@@ -2288,6 +2310,16 @@ int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes
if (held)
*held = 0;
ret = __reserve_bytes(space_info, bytes, flush, held);
-From ec70174eab1dd00bf3a251c225b0398b4bd8e490 Mon Sep 17 00:00:00 2001
+From 5487876f6a49d704e821e2911459e8e1541aa408 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 12:14:49 -0400
Subject: [RFC PATCH 075/116] btrfs: stripe_alloc: keep a stripe in the rbio
5 files changed, 290 insertions(+), 12 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index b43728684b9c1..bd985b6c7e7d1 100644
+index 946102aea2df6..beaa80d48291f 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -528,6 +528,13 @@ struct btrfs_open_stripe_run {
#ifdef CONFIG_BTRFS_DEBUG
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 73750065ebc85..4ac3f43b9b4fc 100644
+index 865ecb86b9ead..c77a26ceab18e 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -78,6 +78,17 @@
/*
* Parked partial write rbios (RBIO_PARKED_BIT), in park order.
* parked_lock nests inside the hash and bio_list locks.
-@@ -559,6 +572,8 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
+@@ -563,6 +576,8 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
if (test_and_clear_bit(RBIO_CACHE_BIT, &rbio->flags)) {
list_del_init(&rbio->stripe_cache);
table->cache_size -= 1;
freeit = true;
/* if the bio list isn't empty, this rbio is
-@@ -637,6 +652,111 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
+@@ -641,6 +656,111 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
info->stripe_hash_table = NULL;
}
+ return false;
+ return btrfs_stripe_run_incomplete(fs_info,
+ rbio->bioc->full_stripe_logical,
-+ (u64)rbio->nr_data * BTRFS_STRIPE_LEN);
++ (u64)rbio->nr_data * rbio->bioc->stripe_len);
+}
+
+/* Re-checked at every prune: the pin ends when its run has written it all. */
/*
* insert an rbio into the stripe cache. It
* must have already been prepared by calling
-@@ -651,10 +771,12 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
+@@ -655,10 +775,12 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
static void cache_rbio(struct btrfs_raid_bio *rbio)
{
struct btrfs_stripe_hash_table *table;
table = rbio->bioc->fs_info->stripe_hash_table;
spin_lock(&table->cache_lock);
-@@ -670,19 +792,11 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
+@@ -674,19 +796,11 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
list_add(&rbio->stripe_cache, &table->stripe_cache);
table->cache_size += 1;
}
spin_unlock(&table->cache_lock);
}
-@@ -1378,6 +1492,10 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
+@@ -1383,6 +1497,10 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
rbio->csum_buf = NULL;
rbio->csum_bitmap = NULL;
* Clear the data bitmap, as the rbio may be cached for later usage.
* do this before unlock_stripe() so there will be no new bio
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index d7b4dafdc80b6..2d48219198b65 100644
+index 5cbff0b128288..ede9047dd1112 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1222,6 +1222,8 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 42d7b94bd97d9a38d48feb9f02a358654e5c4450 Mon Sep 17 00:00:00 2001
+From 3c72edd2884f45c05a461ed4ae62bc790b7f6833 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 2 Oct 2026 02:41:44 -0400
Subject: [RFC PATCH 076/116] btrfs: stripe_alloc: pad a stripe's allocated
5 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index bd985b6c7e7d1..0e62577efbac2 100644
+index beaa80d48291f..9b164bcac06e5 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1791,10 +1791,25 @@ u64 btrfs_stripe_run_alloc_ceiling(struct btrfs_fs_info *fs_info,
* Data read-modify-writes on a block group the allocator
* covers. With allow_rmw empty this is the number the
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 4ac3f43b9b4fc..2ffdb4f9f76e3 100644
+index c77a26ceab18e..7619793710679 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3358,7 +3358,9 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3375,7 +3375,9 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
const u32 nsectors = rbio->nr_data * rbio->stripe_nsectors;
struct btrfs_stripe_pad_info info;
unsigned long *dead;
bool ok = false;
int i;
-@@ -3367,10 +3369,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3384,10 +3386,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
return false;
dead = bitmap_zalloc(nsectors, GFP_NOFS);
rbio_record_pad(rbio, &info);
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, 0, nsectors,
-@@ -3389,11 +3395,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3406,11 +3412,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
covered++;
/*
*/
for (i = 0; i < nsectors; i++) {
if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
-@@ -3412,10 +3421,13 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3429,10 +3438,13 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
info.reason);
goto out;
}
if (!ok)
return false;
-@@ -3446,6 +3458,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3463,6 +3475,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
/* The whole stripe goes out: every vertical position is written. */
bitmap_set(&rbio->dbitmap, 0, rbio->stripe_nsectors);
atomic64_inc(&fs_info->stripe_park_stats.padded);
}
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 2d48219198b65..1ebbd15373586 100644
+index ede9047dd1112..aad4767baad63 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1196,6 +1196,7 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 2cf425545c69f0ec8986ea2d89e4aea793b853f4 Mon Sep 17 00:00:00 2001
+From 0549fac4c074fc636f19a7c0f7e221f1ccd0c477 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 3 Oct 2026 18:57:15 -0400
Subject: [RFC PATCH 077/116] btrfs: stripe_alloc: apply the property before
3 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index a7841e98811be..da97fe48b55d6 100644
+index 3d3a51cd963d0..d61b2c42fd0a8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -47,6 +47,7 @@
#include "relocation.h"
#include "scrub.h"
#include "super.h"
-@@ -3738,6 +3739,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
+@@ -3758,6 +3759,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
if (btrfs_super_log_root(disk_super) != 0 &&
!btrfs_test_opt(fs_info, NOLOGREPLAY)) {
btrfs_info(fs_info, "start tree-log replay");
ret = btrfs_replay_log(fs_info, fs_devices);
if (ret)
goto fail_qgroup;
-@@ -3756,10 +3759,11 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
+@@ -3776,10 +3779,11 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
* policy) before anything that can allocate data -- the resumed
* balance or dev replace kicked off below -- so filesystem-wide
* policy is in force for every allocation this mount ever makes.
-From 0e3f67ce778d663cc44348ec94ac9ef7962b170c Mon Sep 17 00:00:00 2001
+From 7f542d49c81857af6d107e52a8a7911ed0a0acf1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 12:26:45 -0400
Subject: [RFC PATCH 078/116] btrfs: stripe_alloc: count refused rbio pins and
atomic64_t written_not_live;
} stripe_park_stats;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 2ffdb4f9f76e3..f2ff814d20e36 100644
+index 7619793710679..dc62d466e2a22 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -718,19 +718,31 @@ static void rbio_mark_written(struct btrfs_raid_bio *rbio)
+@@ -722,19 +722,31 @@ static void rbio_mark_written(struct btrfs_raid_bio *rbio)
}
}
atomic64_inc(&rbio->bioc->fs_info->stripe_park_stats.rbio_pinned);
} else if (test_and_clear_bit(RBIO_PINNED_BIT, &rbio->flags)) {
table->nr_pinned -= 1;
-@@ -755,6 +767,35 @@ static void rbio_cache_prune(struct btrfs_stripe_hash_table *table,
+@@ -759,6 +771,35 @@ static void rbio_cache_prune(struct btrfs_stripe_hash_table *table,
/* __remove_rbio_from_cache() drops a stale pin's count. */
__remove_rbio_from_cache(found);
}
}
/*
-@@ -3804,6 +3845,8 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3821,6 +3862,8 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
* count that should be zero.
*/
atomic64_inc(&fs_info->stripe_park_stats.data_rmw);
/* A parked-then-flushed write that still had to read. */
if (test_bit(RBIO_WAS_PARKED_BIT, &rbio->flags))
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 99ba94032dd91..d71fc847dd9a2 100644
+index 8a618b86a5f18..1b24e19967cad 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -317,5 +317,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
+@@ -312,5 +312,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
u64 num_bytes, bool force);
#endif
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 1ebbd15373586..05845411b6835 100644
+index aad4767baad63..0e14eca2c6367 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -25,6 +25,7 @@
-From d0d2b845edfcf2bcfc16d4a2562f087f8ee560ce Mon Sep 17 00:00:00 2001
+From 0545e8ac77819e8b6ef84abce5ea6785d4a86d4c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 12:35:08 -0400
Subject: [RFC PATCH 079/116] btrfs: stripe_alloc: sweep stale rbio pins, and
* Read-modify-writes of metadata or system stripes that had to
* read (data_rmw counts them with the data ones): the fsync log
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index f2ff814d20e36..bec096829c5d8 100644
+index dc62d466e2a22..124236fc91c28 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -86,8 +86,19 @@
/*
* Parked partial write rbios (RBIO_PARKED_BIT), in park order.
* parked_lock nests inside the hash and bio_list locks.
-@@ -772,6 +786,73 @@ static void rbio_cache_prune(struct btrfs_stripe_hash_table *table,
+@@ -776,6 +790,73 @@ static void rbio_cache_prune(struct btrfs_stripe_hash_table *table,
table->cache_size);
}
/*
* Cached and pinned rbios now, for sysfs stripe_park_stats. @live re-checks
* each pin against its run, as the prune does: a pin whose run has finished
-@@ -821,6 +902,9 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
+@@ -825,6 +906,9 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
table = rbio->bioc->fs_info->stripe_hash_table;
spin_lock(&table->cache_lock);
/* bump our ref if we were not in the list before */
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index d71fc847dd9a2..7f305f15e7e92 100644
+index 1b24e19967cad..957cc2d857b53 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -319,5 +319,6 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
+@@ -314,5 +314,6 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
u64 num_bytes, bool force);
void btrfs_rbio_cache_usage(struct btrfs_fs_info *fs_info, int *cached,
int *pinned, int *live);
#endif
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 05845411b6835..9284165487ecd 100644
+index 0e14eca2c6367..2fce0ffe5856a 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1233,6 +1233,8 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
atomic64_read(&fs_info->stripe_park_stats.written_not_live),
atomic_read(&fs_info->stripe_parked_now));
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index c3cdaf2c6cc41..97c9cecb0830a 100644
+index 6007dce716bf5..aa251b32b1dcf 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -2497,6 +2497,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2481,6 +2481,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
* no-op when no stripe runs exist.
*/
btrfs_retire_open_stripes(fs_info, cur_trans);
-From d3436b335250591f54e6bd2c2413d7ca419d5071 Mon Sep 17 00:00:00 2001
+From 5c17642cd1a8a7bf3110119ac4d6ae2d675aa1ad Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 17:46:19 -0400
Subject: [RFC PATCH 080/116] btrfs: stripe_alloc: break rbio pins and open
5 files changed, 79 insertions(+), 21 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 0e62577efbac2..fb4ad0c7e0079 100644
+index 9b164bcac06e5..5076e7cdb4ee8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2516,28 +2516,29 @@ static bool run_unwritten_in(struct btrfs_open_stripe_run *run, u64 start,
enum btrfs_stripe_run_class *class);
u64 btrfs_stripe_run_stranded_stripes(struct btrfs_block_group *bg, u32 *freep,
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index bec096829c5d8..a6db24a9b3b60 100644
+index 124236fc91c28..caa30f222def7 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -860,22 +860,34 @@ void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info)
+@@ -864,22 +864,34 @@ void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info)
* evicted or cached again.
*/
void btrfs_rbio_cache_usage(struct btrfs_fs_info *fs_info, int *cached,
+ continue;
+ class = btrfs_stripe_run_incomplete_class(fs_info,
+ rbio->bioc->full_stripe_logical,
-+ (u64)rbio->nr_data * BTRFS_STRIPE_LEN);
++ (u64)rbio->nr_data * rbio->bioc->stripe_len);
+ if (class < 0)
+ continue;
+ *live += 1;
}
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 7f305f15e7e92..2fc1f05c6e66d 100644
+index 957cc2d857b53..bd3b73f040f9a 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -318,7 +318,7 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
+@@ -313,7 +313,7 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
u64 num_bytes, bool force);
void btrfs_rbio_cache_usage(struct btrfs_fs_info *fs_info, int *cached,
#endif
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9284165487ecd..fbb347148dd6d 100644
+index 2fce0ffe5856a..21892535a3c8c 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1187,10 +1187,19 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 944f4a24fde392601ff2682d2eb6bc17281439f0 Mon Sep 17 00:00:00 2001
+From a44ba1c6dac1fb65b1451712c482c708522070a9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 23:16:03 -0400
Subject: [RFC PATCH 081/116] btrfs: stripe_alloc: give each log commit its own
7 files changed, 274 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index fb4ad0c7e0079..ff606c8577ee7 100644
+index 5076e7cdb4ee8..7c7ea3a8a02eb 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -536,6 +536,8 @@ struct btrfs_open_stripe_run {
struct btrfs_inode *inode,
enum btrfs_stripe_run_class class,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index da97fe48b55d6..399fbbdb7ac50 100644
+index d61b2c42fd0a8..24dcb483b96eb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2786,6 +2786,11 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2806,6 +2806,11 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->caching_block_groups);
INIT_LIST_HEAD(&fs_info->open_stripe_bgs);
INIT_WORK(&fs_info->stripe_alloc_enable_work, btrfs_stripe_alloc_enable_work);
/* BTRFS_STRIPE_RMW_* masks; see btrfs_stripe_allow_rmw(). */
u32 stripe_rmw_opt;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index fbb347148dd6d..d18629c7dd080 100644
+index 21892535a3c8c..d3cdc0daa9e98 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1189,7 +1189,7 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 6b52ac73acdfa4e81dc4e827b1b54ce8bc26ce25 Mon Sep 17 00:00:00 2001
+From 77cf7621c923fb0ba6d7b2d0361f1d9fa0f78fe0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 5 Oct 2026 21:13:17 -0400
Subject: [RFC PATCH 082/116] btrfs: stripe_alloc: don't make a parked rbio
1 file changed, 26 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index ff606c8577ee7..00bafb761f829 100644
+index 7c7ea3a8a02eb..6d31001c188a2 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1901,6 +1901,31 @@ bool btrfs_stripe_nocow_writable(struct btrfs_inode *inode, u64 start,
-From b0b570899c985d633a47d9dcb1144ccd2fda84e7 Mon Sep 17 00:00:00 2001
+From 0d8508b1518fcd6952849a84af7bf8dc39a62212 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 6 Oct 2026 00:11:38 -0400
Subject: [RFC PATCH 083/116] btrfs: stripe_alloc: share LOG data runs per log
5 files changed, 227 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 00bafb761f829..4f97ccb130342 100644
+index 6d31001c188a2..d9afc2f6d8e4a 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1296,11 +1296,35 @@ int btrfs_alloc_from_log_stripe_run(struct btrfs_block_group *bg, u64 num_bytes,
if (not_live)
atomic64_add(not_live, &fs_info->stripe_park_stats.written_not_live);
diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
-index 3fc0d4100f502..947696e84353b 100644
+index 5d319df6524d8..fd69a7d34f60c 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
-@@ -1390,6 +1390,9 @@ void btrfs_carry_log_tail(struct btrfs_inode *inode)
+@@ -1399,6 +1399,9 @@ void btrfs_carry_log_tail(struct btrfs_inode *inode)
return;
if (!READ_ONCE(inode->log_carry))
return;
copy = kmalloc(sizeof(*copy), GFP_NOFS);
if (!copy)
return;
-@@ -1403,6 +1406,9 @@ void btrfs_carry_log_tail(struct btrfs_inode *inode)
+@@ -1412,6 +1415,9 @@ void btrfs_carry_log_tail(struct btrfs_inode *inode)
inode->log_carry->nr_ranges = 0;
mutex_unlock(&inode->log_mutex);
carry_one_range(inode, copy->range[i].start,
copy->range[i].len,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 399fbbdb7ac50..419a3eb7527cb 100644
+index 24dcb483b96eb..826341066b242 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2789,8 +2789,12 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2809,8 +2809,12 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
/*
* Closing the log-tree fsync write hole is on by default; sysfs can
* turn it off so the change can be measured against itself on one boot.
/* BTRFS_STRIPE_RMW_* masks; see btrfs_stripe_allow_rmw(). */
u32 stripe_rmw_opt;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index d18629c7dd080..6bd07e15fe707 100644
+index d3cdc0daa9e98..baa3c4e780120 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1321,7 +1321,13 @@ static ssize_t btrfs_stripe_run_stats_show(struct kobject *kobj,
-From edc9be873c6a389b67257aa21cf32bde2ae54133 Mon Sep 17 00:00:00 2001
+From 3ed13bd4b34d1faa4cad991e4c40a9522432a9e8 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 6 Oct 2026 12:40:29 -0400
Subject: [RFC PATCH 084/116] btrfs: stripe_alloc: let relocation allocate as
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 5636c4dc60e89..289ba91be6ab2 100644
+index 1dcd20f69fcb1..781abadf24362 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -2318,9 +2318,15 @@ int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes
+@@ -2316,9 +2316,15 @@ int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes
* a reason to fail while there is unallocated space for a new chunk:
* that made balance fail with ENOSPC on any filesystem whose data chunks
* happened to be full.
-From 526336dd1cb564cd03541dc94f64468e79f1b779 Mon Sep 17 00:00:00 2001
+From 9ceaa90468ee8bd38a0f8eba7e07877fd2ed7935 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:17:47 -0400
Subject: [RFC PATCH 085/116] btrfs: stripe_alloc: key private stripe runs by
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 4f97ccb130342..fe78809c7b410 100644
+index d9afc2f6d8e4a..141ac2b45397b 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -504,7 +504,14 @@ struct btrfs_open_stripe_run {
-From 0249bfbd944033b29a18765023fefb579cba70df Mon Sep 17 00:00:00 2001
+From 7db5408eb960737f39550d1d12576ed34f0f97c5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:49:17 -0400
Subject: [RFC PATCH 086/116] btrfs: stripe_alloc: do not treat an allocation
-From f1dcc0c8b7309bba72e1afcf78102c4c3ac2c5cf Mon Sep 17 00:00:00 2001
+From d6d94cf983c906599778dc6bacb036f7c403d8ee Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:50:45 -0400
Subject: [RFC PATCH 087/116] btrfs: stripe_alloc: mark an ended ordered
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index fe78809c7b410..8a6feca2316c4 100644
+index 141ac2b45397b..89c8af4dfc7a5 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3057,15 +3057,30 @@ struct btrfs_open_stripe_run *btrfs_get_open_stripe_run(
-From 1453b4c48e63017f615c10544b4235189786cf97 Mon Sep 17 00:00:00 2001
+From 8a2735833465c220be2deb2f68995414b6caa48b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:51:15 -0400
Subject: [RFC PATCH 088/116] btrfs: stripe_alloc: read the shared LOG run mode
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 8a6feca2316c4..764bcb81ab936 100644
+index 89c8af4dfc7a5..7888f55c34430 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2435,6 +2435,8 @@ void btrfs_log_settle_stripes(struct btrfs_inode *inode, u64 file_start,
-From 6ca617a49aa15b8ec9b8c7081d1eb2d7507f3f17 Mon Sep 17 00:00:00 2001
+From 11b27450d340cebc88073ef5fbbc188d49cef882 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:54:41 -0400
Subject: [RFC PATCH 089/116] btrfs: stripe_alloc: remove only the set bits of
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index b9768adf48c5d..e4e727456369b 100644
+index f0c3187554deb..c7c55d108486c 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2768,10 +2768,19 @@ static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
+@@ -2778,10 +2778,19 @@ static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
break;
if (info->bitmap) {
-From 4601d72544d8953d695c8f433281690b56ef8c80 Mon Sep 17 00:00:00 2001
+From 7d19226b292f654c6f741534c9dbd4e8b8ca2621 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:54:48 -0400
Subject: [RFC PATCH 090/116] btrfs: stripe_alloc: claim a stripe tail in one
2 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index e4e727456369b..e5c5cf79a355f 100644
+index c7c55d108486c..0489213c4435e 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2519,24 +2519,32 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
+@@ -2529,24 +2529,32 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
* Returns 0 on success, -ENOSPC if no aligned fully-free stripe is present
* in this block group, -ENOMEM if the slow path could not allocate.
*/
spin_lock(&ctl->tree_lock);
for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) {
-@@ -2574,11 +2582,22 @@ int btrfs_claim_stripe_tail(struct btrfs_block_group *block_group,
+@@ -2584,11 +2592,22 @@ int btrfs_claim_stripe_tail(struct btrfs_block_group *block_group,
continue;
found += min(end, e_end) - max(start, e_start);
}
-From bbaa5b42965f3c3a970b39e326f3b6c1dfe9d04c Mon Sep 17 00:00:00 2001
+From f122420a94a8e61bba581893ecf4cdea0432bbc9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:57:34 -0400
Subject: [RFC PATCH 091/116] btrfs: stripe_alloc: keep the stripe totals
2 files changed, 71 insertions(+), 45 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 764bcb81ab936..b5bcd68965463 100644
+index 7888f55c34430..50d8e6f9ad42e 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3624,21 +3624,35 @@ void btrfs_scan_stripe_unusable(struct btrfs_fs_info *fs_info, bool force)
/*
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index e5c5cf79a355f..cb9d3e3bcc804 100644
+index 0489213c4435e..0d006a25295a9 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1514,6 +1514,10 @@ static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
+@@ -1524,6 +1524,10 @@ static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
* ENOSPC, corrected upward by the commit rescan), never HIGH: a
* reservation admitted against phantom supply fails at writeback and
* drops buffered data. Caller holds ctl->tree_lock.
*/
static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta)
{
-@@ -1521,14 +1525,16 @@ static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta)
+@@ -1531,14 +1535,16 @@ static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta)
if (!READ_ONCE(bg->stripe_unusable_ready) || !delta)
return;
if (delta < 0 && sinfo->bytes_stripe_claimable < (u64)-delta)
sinfo->bytes_stripe_claimable = 0;
else
-@@ -2207,22 +2213,19 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2217,22 +2223,19 @@ void btrfs_block_group_init_stripe_unusable(struct btrfs_block_group *bg)
return;
}
trapped = stripe_unusable_scan(bg, freep, nstripes);
}
/*
-@@ -2247,22 +2250,20 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2257,22 +2260,20 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
spin_unlock(&ctl->tree_lock);
return;
}
}
-@@ -2378,10 +2379,9 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2388,10 +2389,9 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
stripe_return_clusters(bg);
spin_lock(&ctl->tree_lock);
if (bg->stripe_unusable_ready) { /* skip if disarmed (read-only) */
/*
* The incremental rules may only under-count claimable
* supply; counting more than the scan finds means a missed
-@@ -2396,7 +2396,14 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2406,7 +2406,14 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
WARN_RATELIMIT(bg->stripe_claimable > scanned,
"bg %llu incremental stripe_claimable %llu above scanned %llu",
bg->start, bg->stripe_claimable, scanned);
-From 3b6b54b00a4ed9c96d123c335c93e3114923d4b4 Mon Sep 17 00:00:00 2001
+From f6c9504e560c3f3123ccbec6931639845e141109 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 00:58:45 -0400
Subject: [RFC PATCH 092/116] btrfs: stripe_alloc: do not delete an unused
2 files changed, 27 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index b5bcd68965463..6b876be5a0b55 100644
+index 50d8e6f9ad42e..f34181d7ce17a 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2278,6 +2278,18 @@ static bool stripe_range_run_free(struct btrfs_block_group *bg, u64 start,
/*
* Close every private LOG and NOCOW run owned by @inode: called at
* inode eviction so a persistent nocow run's claimed tail does not stay
-@@ -5221,6 +5233,20 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
+@@ -5223,6 +5235,20 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
goto next;
}
-From ca3101c29dcae3ba3d91ba482cf52ec293a12252 Mon Sep 17 00:00:00 2001
+From d800d45ed7969f1fbbd360e9db54a354ac4bc6e9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:00:24 -0400
Subject: [RFC PATCH 093/116] btrfs: stripe_meta: commit before waiting for
1 file changed, 49 insertions(+), 12 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 6b876be5a0b55..e4f95238c1501 100644
+index f34181d7ce17a..d5fa24cbf43d8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -547,20 +547,17 @@ struct btrfs_open_stripe_run {
-From e3dbeeb1a01086b92143ecb56f6c1725a08dbd44 Mon Sep 17 00:00:00 2001
+From 71c8da87174ad11a798adfaf05f2eb099169662d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:01:51 -0400
Subject: [RFC PATCH 094/116] btrfs: raid56: do not read tree blocks under the
atomic64_t congestion_short;
/* Frontier stripes pinned in the rbio cache (cache_rbio()). */
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index a6db24a9b3b60..bc6c11b2ad392 100644
+index caa30f222def7..802b0eb7ecc39 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3669,29 +3669,37 @@ static bool rmw_peek_eb_generation(struct btrfs_raid_bio *rbio, u32 i,
+@@ -3686,29 +3686,37 @@ static bool rmw_peek_eb_generation(struct btrfs_raid_bio *rbio, u32 i,
/*
* Is @bytenr a tree block the committed extent tree still references? Read
* the commit root without locking, as the caching thread does, so this is
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
if (ret > 0)
ret = btrfs_previous_extent_item(extent_root, path, bytenr);
-@@ -3716,10 +3724,12 @@ static bool rmw_block_referenced(struct btrfs_fs_info *fs_info, u64 bytenr,
+@@ -3733,10 +3741,12 @@ static bool rmw_block_referenced(struct btrfs_fs_info *fs_info, u64 bytenr,
*/
live = (*refs != 0 && *extent_gen == header_gen);
} else {
}
up_read(&fs_info->commit_root_sem);
btrfs_free_path(path);
-@@ -3820,9 +3830,15 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3837,9 +3847,15 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
(u64)sectornr * fs_info->sectorsize;
u64 refs;
u64 egen;
continue;
}
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 6bd07e15fe707..73bd1b7ad1c08 100644
+index baa3c4e780120..486af39185555 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1233,6 +1233,7 @@ static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
-From 35ac1b2bd14ce5778f590dbff49320ac7750f1fc Mon Sep 17 00:00:00 2001
+From 8b790906dd5d1c4486ad7852adb9545571cb05e4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:02:29 -0400
Subject: [RFC PATCH 095/116] btrfs: raid56: stop the park timer before
3 files changed, 24 insertions(+)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 419a3eb7527cb..8a2e1103e1f93 100644
+index 826341066b242..f54d82a6c7c6d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -3849,6 +3849,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
+@@ -3869,6 +3869,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
invalidate_and_check_btree_folios(fs_info);
fail_sb_buffer:
btrfs_stop_all_workers(fs_info);
btrfs_free_open_stripe_runs(fs_info);
btrfs_free_block_groups(fs_info);
-@@ -4613,6 +4614,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
+@@ -4633,6 +4634,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
* submit after we stop all workers.
*/
invalidate_and_check_btree_folios(fs_info);
/*
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index bc6c11b2ad392..f789836e5f424 100644
+index 802b0eb7ecc39..d90843bf98816 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -651,6 +651,27 @@ static void btrfs_clear_rbio_cache(struct btrfs_fs_info *info)
+@@ -655,6 +655,27 @@ static void btrfs_clear_rbio_cache(struct btrfs_fs_info *info)
spin_unlock(&table->cache_lock);
}
* remove all cached entries and free the hash table
* used by unmount
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 2fc1f05c6e66d..313c19591bf62 100644
+index bd3b73f040f9a..22687b6194f93 100644
--- a/fs/btrfs/raid56.h
+++ b/fs/btrfs/raid56.h
-@@ -317,6 +317,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
+@@ -312,6 +312,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
u64 num_bytes, bool force);
-From 3bdfa7627870621a7dff695e25079fb4d77f86ca Mon Sep 17 00:00:00 2001
+From 7fbce6419dfccaf276d7e2fe080e7e29fa6f24d0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:02:46 -0400
Subject: [RFC PATCH 096/116] btrfs: stripe_alloc: order the filesystem error
1 file changed, 7 insertions(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index e4f95238c1501..a2e4af531955b 100644
+index d5fa24cbf43d8..a924d6ff5cc47 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3323,6 +3323,13 @@ void btrfs_wake_open_stripe_waiters(struct btrfs_fs_info *fs_info)
-From 7ff9ffb31eedb49f8c241d91098520668eccd568 Mon Sep 17 00:00:00 2001
+From e7542b1e8cc8eb37a3ca07e3faf4cd3376cdd783 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:03:09 -0400
Subject: [RFC PATCH 097/116] btrfs: raid56: set a padded rbio's data bitmap
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index f789836e5f424..b4c9e419501a2 100644
+index d90843bf98816..9f3647a98f4e2 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3613,8 +3613,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3630,8 +3630,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
}
set_bit(RBIO_PADDED_BIT, &rbio->flags);
-From 135c4cb527ac0bc0111b37dba64144b2cb73338a Mon Sep 17 00:00:00 2001
+From b12511e299112bd2a3d0b1d758611ecfa3720ca4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:05:05 -0400
Subject: [RFC PATCH 098/116] btrfs: stripe_alloc: forget the failed-claim
1 file changed, 2 insertions(+)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index cb9d3e3bcc804..97f681773d7f2 100644
+index 0d006a25295a9..aa6103d3a79b6 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1859,6 +1859,8 @@ static void __btrfs_return_cluster_to_free_space(
+@@ -1869,6 +1869,8 @@ static void __btrfs_return_cluster_to_free_space(
cluster->block_group = NULL;
cluster->window_start = 0;
list_del_init(&cluster->block_group_list);
-From 298f642fc8d19cf79aa54bc8be36dfd0b9eafa43 Mon Sep 17 00:00:00 2001
+From 05511b2cb911cfb6aec742b3e271986f6c461985 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:05:32 -0400
Subject: [RFC PATCH 099/116] btrfs: stripe_alloc: do not let a remount revert
1 file changed, 10 insertions(+)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index d329181b98e9e..1f4833952ae6d 100644
+index 903bce51fb1fd..cc88140377e74 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1530,6 +1530,16 @@ static int btrfs_reconfigure(struct fs_context *fc)
-From 778a1ddcdd8631bd4727f83e0cb42c05db605b62 Mon Sep 17 00:00:00 2001
+From 04e92cdc7e5252ff18b6109cea7e2a49023a3c75 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:06:05 -0400
Subject: [RFC PATCH 100/116] btrfs: stripe_alloc: do not block a NOWAIT write
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index a2e4af531955b..eab4ecf54f01f 100644
+index a924d6ff5cc47..e1a1a65e6d62d 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1869,7 +1869,7 @@ static bool stripe_extents_owned_by(struct btrfs_fs_info *fs_info,
void btrfs_show_stripe_rmw(struct seq_file *seq, u32 mask);
void btrfs_log_settle_stripes(struct btrfs_inode *inode, u64 file_start,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 512d4c579b4e3..cb59591a9cda4 100644
+index d5732d8938f14..52ae8dd17457d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1888,7 +1888,8 @@ static int can_nocow_file_extent(struct btrfs_path *path,
-From 5b09cd9ba9aeeafe54ca703dbc86bf8d7631ac1c Mon Sep 17 00:00:00 2001
+From 713b3a800b3e6860fc833e693eab59e5ca13a38f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:06:45 -0400
Subject: [RFC PATCH 101/116] btrfs: stripe_alloc: keep the head of a claimed
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 97f681773d7f2..dde71181ba6e6 100644
+index aa6103d3a79b6..7026742de2adf 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2878,6 +2878,13 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2888,6 +2888,13 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
/* Claims are always whole stripes; tolerate an unaligned want_bytes. */
want_bytes = div64_u64(want_bytes, fsl) * fsl;
spin_lock(&ctl->tree_lock);
/*
-@@ -2908,11 +2915,14 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2918,11 +2925,14 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
* for the belt-and-braces case of a run strictly inside
* one extent entry, whose removal splits it in two.
*/
if (!find_free_stripe_run_slow(block_group, want_bytes,
&run_start, &run_len)) {
/*
-@@ -2957,6 +2967,15 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2967,6 +2977,15 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
} else {
kmem_cache_free(btrfs_free_space_cachep, entry);
}
-From c85af373e485e1318e807ed24e2637e2eeaff7a9 Mon Sep 17 00:00:00 2001
+From 18da8ca4c637ee9ad9385a5b3fecb78120d6727a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:06:59 -0400
Subject: [RFC PATCH 102/116] btrfs: stripe_meta: check the block group lookup
-From 5571f78278ce68eb576cb4699b3163c73ee669aa Mon Sep 17 00:00:00 2001
+From 7664407e70b855c087b2534e927da17385523de2 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:07:22 -0400
Subject: [RFC PATCH 103/116] btrfs: stripe_alloc: remove the unused
-From b10ebcd041372e1dcc2caf3f83d25d6507b9af56 Mon Sep 17 00:00:00 2001
+From 1f653944834fd224ccbb4c309f1290acd4b4bc49 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:16:09 -0400
Subject: [RFC PATCH 104/116] btrfs: stripe_alloc: correct and trim the block
2 files changed, 336 insertions(+), 521 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index eab4ecf54f01f..c9711ccd07c4a 100644
+index e1a1a65e6d62d..96f5daaafd4ec 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -449,44 +449,41 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group *bg)
*/
void btrfs_stripe_check_write(struct btrfs_fs_info *fs_info,
u64 full_stripe_start, bool sub_stripe)
-@@ -5526,13 +5354,11 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5528,13 +5356,11 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
/*
* A stripe_alloc / stripe_meta group's live extents can only move into
*/
if (btrfs_is_stripe_alloc_bg(bg) || btrfs_is_stripe_meta_bg(bg)) {
u64 elsewhere = READ_ONCE(space_info->bytes_stripe_claimable);
-@@ -5726,8 +5552,10 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -5728,8 +5554,10 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
LIST_HEAD(retry_list);
int reclaimed = 0;
-From 90f0201fde06e9443c9a760e358581ed631740a5 Mon Sep 17 00:00:00 2001
+From b2f629981ca637a71e9204ba74bc004d6a8a4629 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 01:17:49 -0400
Subject: [RFC PATCH 105/116] btrfs: stripe_alloc: correct and trim the
u64 log_run_hint;
diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
-index 947696e84353b..ef776116b8d46 100644
+index fd69a7d34f60c..79defb1cc0a1f 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
-@@ -1255,15 +1255,14 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
+@@ -1264,15 +1264,14 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
}
/*
*/
static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
u64 disk_bytenr)
-@@ -1373,11 +1372,11 @@ static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
+@@ -1382,11 +1381,11 @@ static int carry_one_range(struct btrfs_inode *inode, u64 start, u64 len,
/*
* Consume the inode's carry table (see struct btrfs_log_carry): re-dirty
* every recorded range so the caller's upcoming writeback carries them
if (flush == BTRFS_RESERVE_FLUSH_DATA &&
btrfs_test_opt(fs_info, STRIPE_ALLOC)) {
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 8a2e1103e1f93..4fdc6a083692f 100644
+index f54d82a6c7c6d..27faf262898f7 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
-@@ -2787,11 +2787,9 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
+@@ -2807,11 +2807,9 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
INIT_LIST_HEAD(&fs_info->open_stripe_bgs);
INIT_WORK(&fs_info->stripe_alloc_enable_work, btrfs_stripe_alloc_enable_work);
/*
*/
fs_info->stripe_log_run = true;
fs_info->stripe_log_data_shared = true;
-@@ -3765,14 +3763,9 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
+@@ -3785,14 +3783,9 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
/*
* Load the top-level root directory's properties (the stripe_alloc
btrfs_carry_log_tail(inode);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index dde71181ba6e6..6977160d6d38e 100644
+index 7026742de2adf..b7caca10cb10d 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1415,17 +1415,12 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1425,17 +1425,12 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
kmem_cache_free(btrfs_free_space_cachep, info);
out:
/*
*/
btrfs_discard_update_discardable(block_group);
spin_unlock(&ctl->tree_lock);
-@@ -1507,13 +1502,9 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
+@@ -1517,13 +1512,9 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
/*
*
* The group's value and the space_info total change in one sinfo->lock
* section, as everywhere else, so that btrfs_scan_stripe_unusable(), which
-@@ -1561,20 +1552,12 @@ static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
+@@ -1571,20 +1562,12 @@ static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
}
/*
*/
static void stripe_unusable_account_add(struct btrfs_block_group *bg,
u64 bytenr, u64 size)
-@@ -2090,14 +2073,12 @@ static u64 stripe_free_walk(struct btrfs_block_group *bg, u32 *freep)
+@@ -2100,14 +2083,12 @@ static u64 stripe_free_walk(struct btrfs_block_group *bg, u32 *freep)
}
/*
*/
static u64 stripe_unusable_scan(struct btrfs_block_group *bg, u32 *freep,
u64 nstripes)
-@@ -2270,21 +2251,14 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2280,21 +2261,14 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
/*
*/
enum stripe_reclaim_kind {
STRIPE_RECLAIM_NONE,
-@@ -2314,12 +2288,10 @@ static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group
+@@ -2324,12 +2298,10 @@ static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group
return STRIPE_RECLAIM_NONE;
if (used >= mult_perc(bg->length, thresh)) {
/*
*/
const u32 pct = READ_ONCE(bg->fs_info->stripe_compact);
-@@ -2386,14 +2358,10 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2396,14 +2368,10 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
/*
* The incremental rules may only under-count claimable
*/
WARN_RATELIMIT(bg->stripe_claimable > scanned,
"bg %llu incremental stripe_claimable %llu above scanned %llu",
-@@ -2423,11 +2391,9 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2433,11 +2401,9 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
kvfree(freep);
if (reclaim) {
/*
*/
spin_lock(&bg->lock);
if (btrfs_mark_bg_to_reclaim(bg))
-@@ -2505,29 +2471,6 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
+@@ -2515,29 +2481,6 @@ static bool find_stripe_run_in_bitmap(struct btrfs_free_space_ctl *ctl,
return false;
}
static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
u64 start, u64 len,
struct btrfs_free_space *spare);
-@@ -2836,8 +2779,10 @@ static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
+@@ -2846,8 +2789,10 @@ static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
ret2 = link_free_space(ctl, info);
ASSERT(!ret2); /* -EEXIST; Logic error */
} else {
ASSERT(!spare_used);
spare->offset = off + piece;
spare->bytes = e_end - spare->offset;
-@@ -2856,6 +2801,23 @@ static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
+@@ -2866,6 +2811,23 @@ static bool claim_stripe_run_pieces(struct btrfs_block_group *block_group,
return spare_used;
}
int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
u64 want_bytes, u64 *start, u64 *len)
{
-@@ -2888,16 +2850,11 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
+@@ -2898,16 +2860,11 @@ int btrfs_claim_free_stripe_run(struct btrfs_block_group *block_group,
spin_lock(&ctl->tree_lock);
/*
struct work_struct async_data_reclaim_work;
struct work_struct preempt_reclaim_work;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index cb59591a9cda4..9f5930298a625 100644
+index 52ae8dd17457d..bff140549c744 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1877,10 +1877,11 @@ static int can_nocow_file_extent(struct btrfs_path *path,
void btrfs_load_stripe_alloc_prop_early(struct btrfs_fs_info *fs_info)
{
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b4c9e419501a2..b584d8fa86e07 100644
+index 9f3647a98f4e2..60e636821c40a 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -49,11 +49,10 @@
/* Scan period of the park timer while anything is parked. */
#define BTRFS_RBIO_PARK_SCAN_MS 3
-@@ -688,25 +681,18 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
+@@ -692,25 +685,18 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
}
/*
*/
static bool rbio_needs_pin(const struct btrfs_raid_bio *rbio)
{
-@@ -841,8 +827,8 @@ static void rbio_pins_low(struct btrfs_stripe_hash_table *table)
+@@ -845,8 +831,8 @@ static void rbio_pins_low(struct btrfs_stripe_hash_table *table)
u64 gen;
/*
*/
if (!time_after(jiffies, table->pin_sweep_jiffies + RBIO_PIN_SWEEP_INTERVAL))
return;
-@@ -877,8 +863,8 @@ void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info)
+@@ -881,8 +867,8 @@ void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info)
/*
* Cached and pinned rbios now, for sysfs stripe_park_stats. @live re-checks
* each pin against its run, as the prune does: a pin whose run has finished
*/
void btrfs_rbio_cache_usage(struct btrfs_fs_info *fs_info, int *cached,
int *pinned, int *live, int *live_by_class)
-@@ -1118,11 +1104,9 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -1123,11 +1109,9 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
return false;
/*
*/
if (class == BTRFS_STRIPE_RUN_NOCOW &&
timeout_ms == sync_timeout_ms)
-@@ -1141,15 +1125,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -1146,15 +1130,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
return false;
/*
*/
{
unsigned int congestion =
-@@ -1172,18 +1152,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
+@@ -1177,18 +1157,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
rbio->park_stuck_deadline = jiffies +
msecs_to_jiffies(timeout_ms * 10);
/*
*/
refcount_inc(&rbio->refs);
list_add_tail(&rbio->parked_node, &table->parked);
-@@ -1650,7 +1623,7 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
+@@ -1655,7 +1628,7 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
rbio->csum_buf = NULL;
rbio->csum_bitmap = NULL;
if (rbio->operation == BTRFS_RBIO_WRITE && status == BLK_STS_OK)
rbio_mark_written(rbio);
-@@ -3500,12 +3473,11 @@ static void rbio_count_rmw_reason(struct btrfs_raid_bio *rbio)
+@@ -3517,12 +3490,11 @@ static void rbio_count_rmw_reason(struct btrfs_raid_bio *rbio)
}
/*
*/
static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
{
-@@ -3553,14 +3525,10 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3570,14 +3542,10 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
covered++;
/*
*/
for (i = 0; i < nsectors; i++) {
if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
-@@ -3764,28 +3732,21 @@ static int rmw_block_referenced(struct btrfs_fs_info *fs_info, u64 bytenr,
+@@ -3781,28 +3749,21 @@ static int rmw_block_referenced(struct btrfs_fs_info *fs_info, u64 bytenr,
}
/*
*/
static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
{
-@@ -3795,12 +3756,8 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3812,12 +3773,8 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
u64 write_gen = 0;
/*
*/
if (rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA)
return;
-@@ -3840,14 +3797,10 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3857,14 +3814,10 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
continue;
}
/*
*/
{
const int stripe_nr = i / rbio->stripe_nsectors;
-@@ -3879,20 +3832,9 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3896,20 +3849,9 @@ static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
}
/*
*/
static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
{
-@@ -3902,11 +3844,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3919,11 +3861,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
return;
if ((rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA) &&
!(rbio->bioc->map_type & BTRFS_BLOCK_GROUP_METADATA))
return;
-@@ -3914,12 +3852,11 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3931,12 +3869,11 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
audit_uncovered_rmw(rbio);
/*
*/
bg = btrfs_lookup_block_group(fs_info, rbio->bioc->full_stripe_logical);
if (bg) {
-@@ -3961,18 +3898,11 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3978,18 +3915,11 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
* Either full stripe write, or we have every data sector already
* cached, can go to write path immediately.
*
if (!rbio_is_full(rbio) && !rmw_try_pad_full(rbio) &&
need_read_stripe_sectors(rbio)) {
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index 289ba91be6ab2..d6d4bfffe3fe1 100644
+index 781abadf24362..061f94e4a65ff 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -400,10 +400,9 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
+@@ -399,10 +399,9 @@ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group)
factor = btrfs_bg_type_to_factor(block_group->flags);
/*
*/
if ((block_group->flags & BTRFS_BLOCK_GROUP_DATA) &&
(block_group->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
-@@ -439,23 +438,17 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
+@@ -437,23 +436,17 @@ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group)
/*
* stripe_alloc pessimistic reservation margin.
*
*/
void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
{
-@@ -476,7 +469,7 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
+@@ -474,7 +467,7 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
/* charges and releases both live */
} else if (mod > 0 || READ_ONCE(sinfo->bytes_stripe_margin) == 0) {
/*
* counter has drained (with no charges it only falls, so
* reading zero is stable).
*/
-@@ -495,25 +488,14 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
+@@ -493,25 +486,14 @@ void btrfs_stripe_margin_mod(struct btrfs_inode *inode, int mod)
}
/*
*/
static u64 stripe_hold_locked(struct btrfs_space_info *space_info)
{
-@@ -720,22 +702,15 @@ static void remove_ticket(struct btrfs_space_info *space_info,
+@@ -718,22 +700,15 @@ static void remove_ticket(struct btrfs_space_info *space_info,
}
/*
*/
static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 bytes,
bool reloc)
-@@ -757,49 +732,30 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
+@@ -755,49 +730,30 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
if (reloc) {
/*
*/
bytes += space_info->bytes_stripe_margin;
return space_info->bytes_may_use + bytes <= supply;
-@@ -1351,20 +1307,14 @@ static bool steal_from_global_rsv(struct btrfs_space_info *space_info,
+@@ -1349,20 +1305,14 @@ static bool steal_from_global_rsv(struct btrfs_space_info *space_info,
return false;
/*
*/
if (space_info->bytes_stripe_reserve && !ticket->mount_cleanup &&
space_info->bytes_stripe_claimable <
-@@ -2249,21 +2199,11 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
+@@ -2247,21 +2197,11 @@ int btrfs_reserve_metadata_bytes(struct btrfs_space_info *space_info,
return ret;
}
*/
static bool reloc_alloc_data_chunk(struct btrfs_space_info *space_info)
{
-@@ -2281,6 +2221,16 @@ static bool reloc_alloc_data_chunk(struct btrfs_space_info *space_info)
+@@ -2279,6 +2219,16 @@ static bool reloc_alloc_data_chunk(struct btrfs_space_info *space_info)
return ret > 0;
}
int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes,
enum btrfs_reserve_flush_enum flush)
{
-@@ -2313,17 +2263,12 @@ int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes
+@@ -2311,17 +2261,12 @@ int btrfs_reserve_data_bytes_held(struct btrfs_space_info *space_info, u64 bytes
*held = 0;
ret = __reserve_bytes(space_info, bytes, flush, held);
/*
while (ret == -ENOSPC && flush == BTRFS_RESERVE_FLUSH_DATA_RELOC &&
reloc_alloc_data_chunk(space_info))
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 9031719314ec2..ee585b723f0f1 100644
+index 61f942e0141d0..3667af16afb33 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -158,14 +158,12 @@ struct btrfs_space_info {
u64 max_extent_size; /* This will hold the maximum extent size of
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
-index 1f4833952ae6d..8e47d5e66c63e 100644
+index cc88140377e74..bce3a12032b6a 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -944,13 +944,8 @@ static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objec
static void btrfs_emit_stripe_alloc_state(struct btrfs_fs_info *info)
{
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 73bd1b7ad1c08..9589d4d7eb270 100644
+index 486af39185555..fe6bbffb1b3be 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -521,11 +521,6 @@ static const struct attribute *discard_attrs[] = {
-From bbc77261bfccfb82874222569e9b7f647e08ce5f Mon Sep 17 00:00:00 2001
+From 6fa8a30f00c91aba4e3779ea7fb30bc38546a73f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 10:20:03 -0400
Subject: [RFC PATCH 106/116] btrfs: stripe_meta: keep waiting for metadata
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index c9711ccd07c4a..38055b6748033 100644
+index 96f5daaafd4ec..b9206ccce5fb9 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3272,6 +3272,7 @@ void btrfs_retire_meta_stripes(struct btrfs_fs_info *fs_info, u64 transid)
-From 1fcae9e2ff2dfbc8b6f2514e9eb6b2fd4f8ef18f Mon Sep 17 00:00:00 2001
+From ea5b896d151b75329a16fb3d1019842f458ab0d7 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 11:19:42 -0400
Subject: [RFC PATCH 107/116] btrfs: stripe_alloc: remove pad refusal reasons
atomic64_t hole_reloc_only;
atomic64_t hole_reloc_sectors;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b584d8fa86e07..dc571489ea25b 100644
+index 60e636821c40a..601cb82895b57 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3124,6 +3124,8 @@ static void rbio_record_pad(struct btrfs_raid_bio *rbio,
+@@ -3141,6 +3141,8 @@ static void rbio_record_pad(struct btrfs_raid_bio *rbio,
static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
ARRAY_SIZE(((struct btrfs_fs_info *)0)->stripe_park_stats.data_rmw_by));
ARRAY_SIZE(((struct btrfs_fs_info *)0)->stripe_park_stats.data_rmw_norun));
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9589d4d7eb270..71573912bfc08 100644
+index fe6bbffb1b3be..512b556e36326 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -567,12 +567,10 @@ static ssize_t btrfs_stripe_rmw_audit_stats_show(struct kobject *kobj,
-From ddcc84d0004077983aec60e5e6cd948b25f58caf Mon Sep 17 00:00:00 2001
+From ba2e08f16cdea789a532d30c88646e3e4f409653 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 19:13:11 -0400
Subject: [RFC PATCH 108/116] btrfs: stripe_alloc: count and log ordered
5 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 38055b6748033..560197ef42362 100644
+index b9206ccce5fb9..8b1d9e34e6714 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2947,25 +2947,36 @@ struct btrfs_open_stripe_run *btrfs_get_open_stripe_run(
static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 71573912bfc08..9928527c7394c 100644
+index 512b556e36326..d3231cc95f6dc 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1318,7 +1318,9 @@ static ssize_t btrfs_stripe_run_stats_show(struct kobject *kobj,
-From 2c86e702355125e0779d667a08699cf34da557e9 Mon Sep 17 00:00:00 2001
+From 9254f34ffae08be338d71b0b1f244404eb5b99a6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 10 Oct 2026 00:19:18 -0400
Subject: [RFC PATCH 109/116] btrfs: stripe_alloc: skip RAID5/6 groups that are
5 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 560197ef42362..a4eb800c02806 100644
+index 8b1d9e34e6714..48c8d0869edcf 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -5966,6 +5966,8 @@ static struct btrfs_block_group *btrfs_create_block_group(
+@@ -5969,6 +5969,8 @@ static struct btrfs_block_group *btrfs_create_block_group(
cache->fs_info = fs_info;
cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start);
static int do_allocation_stripe(struct btrfs_block_group *block_group,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 422bd66239239..f8f493eac205f 100644
+index 6e7419b87ddcd..9f689c4c9d7f8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6604,6 +6604,27 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
+@@ -6617,6 +6617,27 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
return len;
}
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index e99caf4e36a1e..c2c8cabe4135f 100644
+index 982d88264ca5a..f57b73ae996bc 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -801,6 +801,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev,
+@@ -805,6 +805,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev,
void btrfs_free_device(struct btrfs_device *device);
unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
u64 logical);
+bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical);
- u64 btrfs_calc_stripe_length(const struct btrfs_chunk_map *map);
+ u64 btrfs_calc_dev_extent_size(const struct btrfs_chunk_map *map);
int btrfs_nr_parity_stripes(u64 type);
int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,
--
-From 3a14de399288d7d5aea4e241184b0be04e773a58 Mon Sep 17 00:00:00 2001
+From 116fcc38d534f50f53f3ae98ee8ee5e328e4b98f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 10 Oct 2026 14:29:22 -0400
Subject: [RFC PATCH 110/116] btrfs: stripe_alloc: count single-data-stripe
6 files changed, 104 insertions(+), 14 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index a4eb800c02806..592d2f9534013 100644
+index 48c8d0869edcf..f31bef3c7afd1 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -4799,17 +4799,26 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -4801,17 +4801,26 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
* the bytes already admitted would no longer be placeable:
* otherwise their writebacks fail and the data is dropped.
*/
if (sinfo->bytes_may_use + sinfo->bytes_stripe_margin >
supply - mine)
-@@ -4861,8 +4870,10 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
+@@ -4863,8 +4872,10 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, bool force)
* contribution so it is not subtracted twice. Idempotent, so repeated
* ro increments are harmless.
*/
if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) {
btrfs_info(cache->fs_info,
"unable to make block group %llu ro", cache->start);
-@@ -6830,8 +6841,10 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
+@@ -6833,8 +6844,10 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache)
* the current free space (it may have changed while read-only). The
* scan re-adds this group's trapped free space to the space_info total.
*/
{
lockdep_assert_held(&bg->lock);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 6977160d6d38e..b9f4f7c49ee44 100644
+index b7caca10cb10d..0d302853bf0a2 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -540,6 +540,19 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
+@@ -550,6 +550,19 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
return entry;
}
static inline void unlink_free_space(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *info,
bool update_stat)
-@@ -556,7 +569,7 @@ static inline void unlink_free_space(struct btrfs_free_space_ctl *ctl,
+@@ -566,7 +579,7 @@ static inline void unlink_free_space(struct btrfs_free_space_ctl *ctl,
}
if (update_stat)
}
static int link_free_space(struct btrfs_free_space_ctl *ctl,
-@@ -578,7 +591,7 @@ static int link_free_space(struct btrfs_free_space_ctl *ctl,
+@@ -588,7 +601,7 @@ static int link_free_space(struct btrfs_free_space_ctl *ctl,
ctl->discardable_bytes[BTRFS_STAT_CURR] += info->bytes;
}
ctl->free_extents++;
return ret;
}
-@@ -635,7 +648,7 @@ static inline void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
+@@ -645,7 +658,7 @@ static inline void bitmap_clear_bits(struct btrfs_free_space_ctl *ctl,
}
if (update_stat)
}
static void btrfs_bitmap_set_bits(struct btrfs_free_space_ctl *ctl,
-@@ -659,7 +672,7 @@ static void btrfs_bitmap_set_bits(struct btrfs_free_space_ctl *ctl,
+@@ -669,7 +682,7 @@ static void btrfs_bitmap_set_bits(struct btrfs_free_space_ctl *ctl,
*/
info->max_extent_size = 0;
info->bytes += bytes;
relink_bitmap_entry(ctl, info);
-@@ -1469,7 +1482,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
+@@ -1479,7 +1492,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
to_unusable = size - to_free;
spin_lock(&ctl->tree_lock);
spin_unlock(&ctl->tree_lock);
/*
* If the block group is read-only, we should account freed space into
-@@ -2166,6 +2179,32 @@ static void stripe_return_clusters(struct btrfs_block_group *bg)
+@@ -2176,6 +2189,32 @@ static void stripe_return_clusters(struct btrfs_block_group *bg)
spin_unlock(&cluster->refill_lock);
}
/*
* Compute a stripe_alloc block group's initial trapped free space once its
* free space cache is loaded, and enable incremental accounting from here on.
-@@ -3103,7 +3142,7 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group *block_group,
+@@ -3113,7 +3152,7 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group *block_group,
if (!btrfs_free_space_trimmed(entry))
atomic64_add(bytes, &discard_ctl->discard_bytes_saved);
bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg);
bool btrfs_stripe_bg_wants_compaction(struct btrfs_block_group *bg);
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
-index d6d4bfffe3fe1..d56683fa00879 100644
+index 061f94e4a65ff..7859713404ff1 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
-@@ -433,6 +433,8 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
+@@ -431,6 +431,8 @@ void btrfs_add_bg_to_space_info(struct btrfs_block_group *block_group)
down_write(&space_info->groups_sem);
list_add_tail(&block_group->list, &space_info->block_groups[index]);
up_write(&space_info->groups_sem);
}
/*
-@@ -727,7 +729,14 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
+@@ -725,7 +727,14 @@ static bool stripe_claimable_admit(struct btrfs_space_info *space_info, u64 byte
* runs can lose at the next commit.
*/
{
const u64 dedicated = space_info->bytes_stripe_claimable_reloc;
if (reloc) {
-@@ -845,14 +854,15 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
+@@ -843,14 +852,15 @@ static void __btrfs_dump_space_info(const struct btrfs_space_info *info)
(s64)(info->total_bytes - btrfs_space_info_used(info, true)),
info->full ? "" : "not ");
btrfs_info(fs_info,
void btrfs_dump_space_info(struct btrfs_space_info *info, u64 bytes,
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index ee585b723f0f1..4dea6081d5253 100644
+index 3667af16afb33..43124031e1926 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -178,6 +178,12 @@ struct btrfs_space_info {
-From a1ba776d84f34898257042e6cc7e8426938c3453 Mon Sep 17 00:00:00 2001
+From 57bd7060bee3be492177305469ddf52aec1cf364 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 11 Oct 2026 02:50:36 -0400
Subject: [RFC PATCH 111/116] btrfs: stripe_alloc: account claimable stripes
3 files changed, 146 insertions(+), 14 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 592d2f9534013..65340f18ae7a4 100644
+index f31bef3c7afd1..53602f27a36af 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1583,6 +1583,30 @@ u64 btrfs_stripe_run_stranded_stripes(struct btrfs_block_group *bg, u32 *freep,
u64 size);
bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index b9f4f7c49ee44..7a0f1efdeb6e9 100644
+index 0d302853bf0a2..c55d80da64924 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1366,10 +1366,12 @@ static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl,
+@@ -1376,10 +1376,12 @@ static void steal_from_bitmap(struct btrfs_free_space_ctl *ctl,
static void stripe_claimable_mod(struct btrfs_block_group *bg, s64 delta);
static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
u64 bytenr, u64 size);
{
struct btrfs_fs_info *fs_info = block_group->fs_info;
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
-@@ -1429,12 +1431,16 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1439,12 +1441,16 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
out:
/*
* Adding free space never credits stripe_claimable: some add paths
btrfs_discard_update_discardable(block_group);
spin_unlock(&ctl->tree_lock);
-@@ -1451,6 +1457,13 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
+@@ -1461,6 +1467,13 @@ static int __btrfs_add_free_space(struct btrfs_block_group *block_group,
return ret;
}
static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
u64 bytenr, u64 size, bool used)
{
-@@ -1516,8 +1529,9 @@ static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
+@@ -1526,8 +1539,9 @@ static void stripe_unusable_mark_dirty(struct btrfs_block_group *bg);
/*
* Debit the claimable whole-stripe supply for claims and removals. Returned
*
* The group's value and the space_info total change in one sinfo->lock
* section, as everywhere else, so that btrfs_scan_stripe_unusable(), which
-@@ -1564,6 +1578,97 @@ static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
+@@ -1574,6 +1588,97 @@ static u64 stripe_touched_bytes(const struct btrfs_block_group *bg,
return aend - astart;
}
/*
* Count the sub-stripe head and tail of a returning free range as trapped
* at once: reservations read bytes_stripe_unusable mid-transaction, and the
-@@ -3529,13 +3634,12 @@ static int do_trimming(struct btrfs_block_group *block_group,
+@@ -3539,13 +3644,12 @@ static int do_trimming(struct btrfs_block_group *block_group,
}
if (reserved_start < start)
if (!bg_ro) {
spin_lock(&space_info->lock);
-@@ -3633,6 +3737,8 @@ static int trim_no_bitmap(struct btrfs_block_group *block_group,
+@@ -3643,6 +3747,8 @@ static int trim_no_bitmap(struct btrfs_block_group *block_group,
unlink_free_space(ctl, entry, true);
kmem_cache_free(btrfs_free_space_cachep, entry);
}
spin_unlock(&ctl->tree_lock);
-@@ -3851,6 +3957,7 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,
+@@ -3861,6 +3967,7 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,
bitmap_clear_bits(ctl, entry, start, bytes, true);
if (entry->bytes == 0)
free_bitmap(ctl, entry);
-From 52074eb4d12ef3850757554d6533f24cd258c362 Mon Sep 17 00:00:00 2001
+From 7078a366742e3bbb8e50863428b096c3155e0fe3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 00:14:58 -0400
Subject: [RFC PATCH 112/116] btrfs: stripe_alloc: do not miss bitmap free
1 file changed, 9 insertions(+)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 7a0f1efdeb6e9..8303110638dcf 100644
+index c55d80da64924..7f5d17a727587 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -1601,6 +1601,15 @@ static bool stripe_range_free(struct btrfs_free_space_ctl *ctl,
+@@ -1611,6 +1611,15 @@ static bool stripe_range_free(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *e = tree_search_offset(ctl, pos, 0, 0);
unsigned long bit;
-From 0900c2bcd6b290ba88d4bdea5d4f68477ad74aee Mon Sep 17 00:00:00 2001
+From 780cc8af6fc1dd5d42f883ccbf06552a123bfc2e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:04:19 -0400
Subject: [RFC PATCH 113/116] btrfs: log block group reclaim at debug level
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 65340f18ae7a4..dde544f6b3bdd 100644
+index 53602f27a36af..41c717707a440 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -5400,8 +5400,10 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5402,8 +5402,10 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
u64 used;
u64 reserved;
u64 old_total;
/*
* A stripe_alloc / stripe_meta group's live extents can only move into
-@@ -5548,12 +5550,17 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5550,12 +5552,17 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
spin_lock(&bg->lock);
used = bg->used;
reserved = bg->reserved;
ret = btrfs_compact_chunk(fs_info, bg->start, &compacted);
/*
* Compacted, the group stays: drop our read-only hold. It
-@@ -5590,8 +5597,11 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5592,8 +5599,11 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
if (space_info->total_bytes < old_total)
btrfs_set_periodic_reclaim_ready(space_info, true);
spin_unlock(&space_info->lock);
-From bcadbfc8ac020ccc7fddf79e5530322e3fb98747 Mon Sep 17 00:00:00 2001
+From 301e2700905d9ada252870d02e543f9d7a31a1b0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 14:41:37 -0400
Subject: [RFC PATCH 114/116] btrfs: stripe_alloc: add stripe_reclaim_now to
5 files changed, 249 insertions(+), 15 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index dde544f6b3bdd..da9c005069b59 100644
+index 41c717707a440..bca4df2ab3cd4 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -5402,6 +5402,7 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5404,6 +5404,7 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
u64 old_total;
u64 trapped;
int ret = 0;
bool compact = false;
bool compacted = false;
-@@ -5418,7 +5419,8 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5420,7 +5421,8 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
u64 need = READ_ONCE(bg->used);
/* Compaction moves at most half of it. */
need /= 2;
elsewhere -= min(elsewhere, READ_ONCE(bg->stripe_claimable));
if (elsewhere < need) {
-@@ -5440,6 +5442,9 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5442,6 +5444,9 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
spin_lock(&space_info->lock);
spin_lock(&bg->lock);
if (bg->ro ||
((bg->reserved || bg->pinned) &&
!btrfs_is_stripe_alloc_bg(bg) &&
-@@ -5492,7 +5497,10 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5494,7 +5499,10 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
* check, which is more meaningful when adding to the list in
* the first place.
*/
/*
* Too full to relocate whole. A stripe_alloc / stripe_meta
* group whose free space is trapped in partially used stripes
-@@ -5765,6 +5773,160 @@ bool btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg)
+@@ -5767,6 +5775,160 @@ bool btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg)
return true;
}
struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans,
struct btrfs_space_info *space_info,
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index 8303110638dcf..f3a8381e05de5 100644
+index 7f5d17a727587..d41c672f176b5 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2413,19 +2413,15 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2423,19 +2423,15 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
* and queueing a group with nowhere to move it only costs writers read-only
* transitions. Counters are read unlocked; the worker re-checks.
*/
/*
* Stripes stranded behind live runs are trapped for admission but not
* for reclaim: they come back by themselves when the run is freed, and
-@@ -2437,9 +2433,19 @@ static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group
+@@ -2447,9 +2443,19 @@ static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group
u64 elsewhere;
u64 promised;
/*
* Too full to move whole: compact once trapped space reaches
* stripe_compact percent of the group's length. (A share of
-@@ -2463,7 +2469,15 @@ static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group
+@@ -2473,7 +2479,15 @@ static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group
READ_ONCE(sinfo->bytes_stripe_margin);
elsewhere -= min(elsewhere, READ_ONCE(bg->stripe_claimable));
elsewhere -= min(elsewhere, promised);
}
bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
-@@ -2471,6 +2485,19 @@ bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
+@@ -2481,6 +2495,19 @@ bool btrfs_stripe_bg_wants_reclaim(struct btrfs_block_group *bg)
return stripe_bg_reclaim_kind(bg, true) != STRIPE_RECLAIM_NONE;
}
u64 nstripes);
void btrfs_dump_free_space(struct btrfs_block_group *block_group,
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 9928527c7394c..32d751fe87161 100644
+index d3231cc95f6dc..c7885e00033a8 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1464,6 +1464,34 @@ static ssize_t btrfs_stripe_compact_store(struct kobject *kobj,
-From 43d8f35586e64dd7087aaa1c5979dcc993d05cf2 Mon Sep 17 00:00:00 2001
+From 1ebbdb45771f2de406763b7b1e9b0d0a11087a4e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 04:02:52 -0400
Subject: [RFC PATCH 115/116] btrfs: stripe_alloc: back off block group reclaim
5 files changed, 148 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index da9c005069b59..6368922e72c9d 100644
+index bca4df2ab3cd4..fbd603e5fa416 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -5614,6 +5614,79 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
+@@ -5616,6 +5616,79 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
return ret;
}
void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limit)
{
struct btrfs_block_group *bg;
-@@ -5653,6 +5726,7 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -5655,6 +5728,7 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
*/
list_sort(NULL, &fs_info->reclaim_bgs, reclaim_bgs_cmp);
while (!list_empty(&fs_info->reclaim_bgs)) {
int ret;
bg = list_first_entry(&fs_info->reclaim_bgs,
-@@ -5662,10 +5736,27 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -5664,10 +5738,27 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
space_info = bg->space_info;
spin_unlock(&fs_info->unused_bgs_lock);
btrfs_link_bg_list(bg, &retry_list);
btrfs_put_block_group(bg);
-@@ -5742,6 +5833,8 @@ static void btrfs_stripe_reclaim_tick(struct btrfs_fs_info *fs_info)
+@@ -5744,6 +5835,8 @@ static void btrfs_stripe_reclaim_tick(struct btrfs_fs_info *fs_info)
continue;
if (!btrfs_stripe_bg_wants_reclaim(bg))
continue;
int btrfs_read_block_groups(struct btrfs_fs_info *info);
struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
-index f3a8381e05de5..414df924fbf8b 100644
+index d41c672f176b5..33ba40faffe22 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
-@@ -2413,6 +2413,33 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2423,6 +2423,33 @@ void btrfs_block_group_disarm_stripe_unusable(struct btrfs_block_group *bg)
* and queueing a group with nowhere to move it only costs writers read-only
* transitions. Counters are read unlocked; the worker re-checks.
*/
static enum stripe_reclaim_kind __stripe_bg_reclaim_kind(struct btrfs_block_group *bg,
int thresh, bool force,
bool check_room,
-@@ -2469,7 +2496,9 @@ static enum stripe_reclaim_kind __stripe_bg_reclaim_kind(struct btrfs_block_grou
+@@ -2479,7 +2506,9 @@ static enum stripe_reclaim_kind __stripe_bg_reclaim_kind(struct btrfs_block_grou
READ_ONCE(sinfo->bytes_stripe_margin);
elsewhere -= min(elsewhere, READ_ONCE(bg->stripe_claimable));
elsewhere -= min(elsewhere, promised);
}
static enum stripe_reclaim_kind stripe_bg_reclaim_kind(struct btrfs_block_group *bg,
-@@ -2569,6 +2598,9 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
+@@ -2579,6 +2608,9 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg)
}
spin_unlock(&ctl->tree_lock);
kvfree(freep);
/*
* Stamp the hysteresis only if the mark lands: a group still on
diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
-index 4dea6081d5253..f959246fa007c 100644
+index 43124031e1926..65a92994e615c 100644
--- a/fs/btrfs/space-info.h
+++ b/fs/btrfs/space-info.h
@@ -282,6 +282,23 @@ struct btrfs_space_info {
* If true, use the dynamic relocation threshold, instead of the
* fixed bg_reclaim_threshold.
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 32d751fe87161..740eff72ee21e 100644
+index c7885e00033a8..c4cf426105afc 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -889,6 +889,7 @@ SPACE_INFO_ATTR(disk_total);
-From a23064467620f3d39e4cc8c71b5ae12a9bab7572 Mon Sep 17 00:00:00 2001
+From bc8cd9cac405fb573a08f798266215560f19b234 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 04:02:53 -0400
Subject: [RFC PATCH 116/116] btrfs: stripe_alloc: let queued exclusive
3 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
-index 6368922e72c9d..d596cf1b563ea 100644
+index fbd603e5fa416..71488e97f4adc 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
-@@ -5687,6 +5687,14 @@ static void reclaim_note_result(struct btrfs_block_group *bg, bool enospc, u64 n
+@@ -5689,6 +5689,14 @@ static void reclaim_note_result(struct btrfs_block_group *bg, bool enospc, u64 n
streak, bg->start, space_info->flags);
}
void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limit)
{
struct btrfs_block_group *bg;
-@@ -5704,9 +5712,12 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -5706,9 +5714,12 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
if (!btrfs_should_reclaim(fs_info))
return;
return;
/*
-@@ -5761,11 +5772,36 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -5763,11 +5774,36 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
btrfs_put_block_group(bg);
mutex_unlock(&fs_info->reclaim_bgs_lock);
/*
* If we are interrupted by a balance, we can just bail out. The
* cleaner thread restart again if necessary.
-@@ -5779,10 +5815,11 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
+@@ -5781,10 +5817,11 @@ void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limi
spin_unlock(&fs_info->unused_bgs_lock);
mutex_unlock(&fs_info->reclaim_bgs_lock);
end: