allocated (a 0..end range when the request had no vrange, or the end of
the vrange supplied by userspace, lowered to that address if it is
higher). Every block group that existed when the balance started stays
-selected until the balance relocates it.
+selected until the balance relocates it. A balance item recovered at
+mount is limited the same way (a vrange is added where it has none, as
+in items written by older kernels, and an end beyond the next chunk is
+lowered), and if that changes the item, it is written back once when
+the balance resumes, so a resume that is interrupted again keeps the
+same bound.
New chunks are normally allocated after the last chunk, but relocating the
highest chunk into free space lower down deletes it without allocating
filesystem needs an --enable-experimental btrfs-progs with a mkfs fix
for remap-tree to fix a NULL deref bug.
- - balance-resume-legacy-test.sh (patch 3 only): data balances paused
- by a stock 6.12 kernel, then resumed on the patched kernel. A plain
- item must resume with usage=90, a convert item with soft, neither
- with a vrange; an item with a user-given vrange, converting or not,
- must resume unchanged (no soft, no usage); a balance started on the
- patched kernel must get the vrange and no usage filter.
+ - balance-resume-legacy-test.sh: data balances paused by a stock 6.12
+ kernel, then resumed on the patched kernel. Every item must show,
+ already before the resume, a vrange ending at the end of the last
+ chunk: added to a plain or convert item, lowered from a user-given
+ end of 1 TiB or U64_MAX. With patch 3 a plain item also resumes with
+ usage=90 and a convert item with soft, and an item with a user-given
+ vrange, converting or not, with neither. The resumed balance is
+ paused again and the filesystem remounted: it must resume with the
+ same bound, and must not relocate the chunks the first resume
+ allocated. Every chunk the resumes allocate must start at or above
+ the end of the last chunk and stay near it; without the limit, the
+ resume of a 1 TiB item allocates its chunks from 1 TiB up. A balance
+ started on the patched kernel must get the vrange and no usage filter.
Zygo Blaxell (3):
btrfs: free queued remap chunks when balance bails out
including the >= 90% full ones that usage=90 would skip, and never a
chunk the interrupted run created; a legacy item must resume with
usage=90 (soft for a convert), a legacy item with a vrange must resume
-unchanged, and a paused convert must resume without soft and relocate
+with no other change, and since 2026-11-06 every recovered item must be
+bounded as a new balance would be (a vrange added or lowered to the end
+of the last chunk, written back once at resume); a paused convert must
+resume without soft and relocate
the target-profile chunks below the bound; a bail-out with queued remap
chunks must free every entry.
its chunks from 1 TiB up (highest chunk after the resume 1102732853248 /
1104880336896, and the next balance's bound 1105954078720). Harmless at
1 TiB; a user-given vrange end near U64_MAX would put the floor there.
+Fixed in the 2026-11-06 round below.
+
+## 2026-11-06 round (fl1106: recovered items bounded at mount)
+
+Zygo (2026-11-06): a recovered item "should be limited to the
+filesystem's current end (same as if a new balance had been started)",
+and "Items with no vrange get a vrange added, because that's how newer
+kernels resume the balance if it is interrupted again". Patch 2 now runs
+`limit_balance_to_existing_chunks()` in `btrfs_recover_balance()` before
+the floor is set (the floor is still 0, so the bound is the end of the
+last chunk): a type without a vrange gets 0..end, a vend above end is
+lowered. If that changed the arguments, `btrfs_balance()` writes them to
+the existing item once when the resume starts (`update_balance_item()`,
+one transaction, before any relocation); an item from a patched kernel
+whose vend is already <= end is not written, so a balance started on a
+patched kernel still writes its item only at insert and delete. Patch 3
+now decides the legacy filters at recovery, from the on-disk args, before
+the bound is added, and they are written back with it.
+
+A pause and resume without an unmount (ioctl resume) reuses the
+in-memory bctl, bounded at mount or at start, and the floor stays set
+through the pause (`reset_balance_state()` does not run for a paused
+balance), so no clamp is needed there; the ro->rw remount resume uses the
+bctl recovered at mount. Checked in the code; `balance-resume-test.sh`
+covers the ioctl resume.
+
+Kernels: 6.18 zb64 candidate 876b62099832 (#319, KASAN inline + lockdep
++ BTRFS_ASSERT, bzImage md5 776c478274227a504d1517e3c653835d) on bhive
+and ahive; misc-next zb64 candidate d411e967283c (#68, same options, md5
+2bd866e69d3020906566b9d5fdb52bf5) on dhive and ehive. Patch 2 alone:
+6.18 zb64 with patch 3 reverted (43931862c049, #6, md5
+d4add82f1212b4af056253e2031b7c54) on ahive. Negative controls on the
+previous kernels #318 and #67. Legacy items prepared by stock Debian
+6.12.115 on each rig (6.12 accepts vrange=0..U64_MAX). Evidence:
+`raid56-wh-harness/forensics/fl1106-618/`, `forensics/fl1106-mn/`.
+
+`balance-resume-legacy-test.sh` now checks, for each variant: `balance
+status -v` after the mount and before the resume shows vrange=0..E (E =
+the end of the last chunk); the resume line shows the same bound and the
+patch 3 filters (or none with LEGACY_P3=0); the resumed balance is paused
+after one block group, the filesystem unmounted and mounted again, and
+the bound must be unchanged (a new bound would be higher); the second
+resume must not relocate the chunks the first one allocated; every chunk
+the resumes allocate starts at or above E and below E + the bytes
+allocated + the image size; for the vrange variants every data chunk
+below E is relocated; a new balance gets a vrange. New variant
+`vrange-max` (vrange=0..18446744073709551615).
+
+| test | verifies | patch(es) | duration | result | kernel |
+|---|---|---|---|---|---|
+| `balance-resume-legacy-test.sh check plain` | legacy plain item: bounded at mount, usage=90, bound persisted across a second interruption | 2, 3 | 1 min | PASS on all four rigs, e.g. bhive "balance: resume -dusage=90,vrange=0..9685696512" | #319, #68 |
+| `... check convert` | legacy `-dconvert=dup` item: bounded, soft | 2, 3 | 1 min | PASS on all four ("-dconvert=dup,soft,vrange=0..7538212864" on bhive) | #319, #68 |
+| `... check vrange` | user-given vrange=0..1 TiB lowered to E; no usage, no soft; allocations near E | 2 | 1 min | PASS on all four (bhive "-dvrange=0..9685696512") | #319, #68 |
+| `... check convert-vrange` | `-dconvert=dup,vrange=0..1 TiB`: lowered, no soft | 2, 3 | 1 min | PASS on all four | #319, #68 |
+| `... check vrange-max` (new) | vrange end U64_MAX lowered to E | 2 | 2 min | PASS on all four (bhive "-dvrange=0..8611954688"; resume 2 relocated none of the 2 chunks resume 1 allocated) | #319, #68 |
+| same, all 5 variants, `LEGACY_P3=0` | patch 2 alone: bounded and persisted, args otherwise unchanged (no usage, no soft) | 2 | 6 min | PASS 5/5 | 6.18 #6 (patch 3 reverted), ahive |
+| legacy plain/convert/vrange/convert-vrange, negative control | the detector sees the unbounded resume | - | 1 min each | FAIL as expected on #318 (bhive, ahive) and #67 (dhive, ehive): no vrange added, 1 TiB kept, not persisted ("after the second interruption the bound is 'vrange=0..1099511627776'"), allocations reach 1105954078720; usage/soft assertions PASS. `vrange-max` was not run on the controls | #318, #67 |
+| `balance-resume-convert-test.sh` x2, `balance-resume-test.sh`, `balance-resume-reuse-test.sh` | as above; the bound after a remount is expected to be min(stored end, end of last chunk) | 2 | 1-2 min each | PASS on all four (ahive convert run 2 SKIPped on timing, no "balance: start" line within 5 s; rerun x2 PASS); also PASS on the controls #318 (bhive) and #67 (dhive) | #319, #68 |
+| `remap-balance-resume-test.sh`, `remap-balance-leak-test.sh` | as above | 1, 2 | 2 min each | PASS on #68 (dhive, ehive) and #67 (dhive); SKIP on 6.18 as expected | #68 |
+
+Not covered: in the new-kernel tests the interrupted run always
+allocated, so the bound was never lowered at mount for an item written
+by a patched kernel (the clamp was a no-op there and no write-back
+happened); the lowering and the write-back are exercised by the legacy
+vrange variants.
## Not covered / open
dev extents at the minimum size. With all three chunk sizes at 1 GiB
and device sizes a multiple of 1 GiB plus the reserved 1 MiB, every dev
extent and every hole is 1 GiB and the fragmentation cannot start. Only
-the system chunk size needs a kernel change; that is this patch.
+the system chunk size needs a kernel change; that is patch 1. Patch 2
+makes the chunk allocator prefer a dev extent hole that starts on the
+N GiB + 1 MiB grid over the first hole that fits, so the dev extents
+move onto that grid as they are balanced.
The system value must be a multiple of 32 MiB (rounded down) and at
least 32 MiB; data and metadata keep their 256 MiB granularity, and all
allocation, deletes most files, adds a device and balances, four rounds.
With all three chunk sizes at 1 GiB every dev_extent is 1 GiB long and
starts at N GiB + 1 MiB from the second or third round on (3 of 3 runs,
-with a separate patch that prefers aligned dev_extent holes when
-allocating chunks); with the system chunks left at 32 MiB the layout
+with patch 2); with the system chunks left at 32 MiB the layout
never gets there and the 32 MiB dev_extents multiply.
Zygo Blaxell (1):
system values, rejects bad ones, and that new SYSTEM chunks (and their dev
extents) are then allocated at the set size.
+Since 2026-11-06 the series has a second patch, "btrfs: prefer aligned
+dev_extent holes when allocating chunks" (until then a separate commit
+on the lanes): `find_free_dev_extent()` takes the first hole that is big
+enough and starts at N GiB + 1 MiB, else the first hole that fits as
+before. The `dev-extent-frag-test.sh` grid results below were all
+measured with it applied.
+
Kernel under test for the "Current" column: misc-next zb64 568c45b64012
(uname 7.3.0-rc7+ #5, KASAN + PROVE_LOCKING) unless a row says otherwise.
kept), delete 80% of the files, add a device, full balance including
system. The criterion is Zygo's grid: every device reserves its first
1 MiB, so a dev_extent is on the grid when it is 1 GiB long and starts at
-N GiB + 1 MiB -- the same rule as the lane's "prefer aligned dev_extent
-holes when allocating chunks" patch. Each measurement reports the on-grid
+N GiB + 1 MiB -- the same rule as patch 2. Each measurement reports the on-grid
fraction per device and per block group type, aligned holes, and lists
the off-grid extents. uniform PASSes when the last fully allocated round
is entirely on the grid.
Shown to fail without the patch: on the misc-next base 0c48d26d46bd
every system write is EPERM (FAIL 11), data and metadata unchanged.
+## 2026-11-06 round (fl1106: patch 2 moved into the series)
+
+The aligned-holes commit moved, unchanged in content, from the linear
+part of each lane above the testing merge into this topic, after the
+sysfs patch; only its subject and message are new. Both lanes' integrated
+trees are identical before and after the move (apart from an unrelated
+balance-resume change). Kernels: 6.18 #319 (bhive, ahive) and misc-next
+#68 (dhive, ehive), KASAN + lockdep + BTRFS_ASSERT; per-commit buildcheck
+of the topic on both lanes: no failures, no new warnings. Evidence:
+`raid56-wh-harness/forensics/fl1106-618/`, `forensics/fl1106-mn/`.
+
+| test | patch(es) | duration | result | kernel |
+|---|---|---|---|---|
+| `sys-chunk-size-test.sh` | 1 | 10 s | PASS on all four | #319, #68 |
+| `dev-extent-frag-test.sh` uniform x2 per rig | 1, 2 | 6-12 min each | PASS 8/8: every run entirely on the grid from round 2 or 3 on (96/96 in round 3 everywhere) | #319, #68 |
+| `dev-extent-frag-test.sh` nosys x1 per rig | (control) | 11 min | report only: round 3 on grid 40/110 (bhive), 29/120 (ahive), 26/110 (dhive), 51/106 (ehive); the SYSTEM extents are never on the grid | #319, #68 |
+
## Not covered / open
- Fragmentation with raid5/raid6/raid10 data, more rounds, and the vary