# Testing: balance-resume
-Patch 1 replaces the usage=90 filter that a resumed balance used to add
+Patch 1 (2026-11-10) fixes the limit_min check of a single `limit`,
+which read the low half of the limit itself (2026-11-10 round below).
+Patch 2 replaces the usage=90 filter that a resumed balance used to add
on its own with a vrange bound fixed at balance start (the next chunk
address), plus an in-memory chunk-allocation floor so that no chunk is
-allocated below the bound while a balance item exists. Patch 3
+allocated below the bound while a balance item exists. Patch 4
(optional) keeps the old resume filters (soft for a type being
converted, else usage=90) for chunk types without a vrange, which only
balance items written by older kernels lack; a type with a vrange is
resumed unchanged. Since 2026-11-05 (Zygo: "If vrange is present then
-we should not make any other changes") patch 1 removes
+we should not make any other changes") patch 2 removes
update_balance_args() entirely, so the soft filter a convert used to get
on resume is gone too: the bound already keeps every chunk the
interrupted run converted out of the range, and soft also skipped the
-chunks below the bound that had the target profile at start. Patch 2
+chunks below the bound that had the target profile at start. Patch 3
(2026-11-08) writes the remaining limit filters back to the item after
each processed chunk (2026-11-08 round below). To verify: a paused and resumed balance must relocate exactly
the block groups that existed below the bound at the pause, each once,
resume without soft and relocate
the target-profile chunks below the bound.
-Patch numbers are the series' current ones (since 2026-11-08): 1 the
-vrange bound, 2 the limit write-back, 3 the legacy filters. The rounds
-before 2026-11-08 are renumbered to match (their patch 2 is now 1, their
-patch 3 is still 3). Their patch 1, "btrfs: free queued remap chunks
-when balance bails out", is now its own series, `topics/remap-balance-leak`;
-its leak test and results are in that directory's TESTING.md.
+Patch numbers are the series' current ones (since 2026-11-10): 1 the
+limit_min fix, 2 the vrange bound, 3 the limit write-back, 4 the legacy
+filters. The rounds before 2026-11-10 number the series without the
+fix (1 vrange, 2 limit write-back, 3 legacy, the oldest rounds already
+renumbered to that): add one to their patch numbers. The remap leak fix
+that the rounds before 2026-11-08 also tested, "btrfs: free queued remap
+chunks when balance bails out", is now its own series,
+`topics/remap-balance-leak`; its leak test and results are in that
+directory's TESTING.md.
Kernel under test for the "Current" column: misc-next zb64 568c45b64012
(uname 7.3.0-rc7+ #5, KASAN) unless a row says otherwise. Test logs are
Open, for this round:
-- `__btrfs_balance()`'s `limit_min` check reads `bctl->data.limit_min`
+- (Closed 2026-11-10 by the new patch 1, see that round.)
+ `__btrfs_balance()`'s `limit_min` check reads `bctl->data.limit_min`
for every chunk type with no flag test ("limit_min is 0 by default"),
but `limit_min` is the low 32 bits of a single `limit`.
`should_balance_chunk()` has already counted `limit` down for the
fs error with no BUG; after the remount, R + L in {N, N+1} (arm 5's
invariant on a real abort).
+## 2026-11-10 round (lr1109: the limit_min fix, patch 1)
+
+Zygo (2026-11-09), on the limit/limit_min alias listed as open in the
+2026-11-08 round: "yes, add that to the balance-resume series". New
+patch 1, "btrfs: apply the balance limit_min filter only to a limit
+range" (Fixes: 12907fc79818, v4.4; no Cc stable, Zygo's call). In this
+section, patch numbers are the new ones (1 fix, 2 vrange, 3 limit
+write-back, 4 legacy).
+
+The bug, re-derived from the source: `limit` (u64) shares its bytes with
+`limit_min`/`limit_max` (u32 each) in `struct btrfs_balance_args`.
+`__btrfs_balance()` applied `count < limit_min` to every chunk with no
+flag test ("limit_min is 0 by default"). With a single `limit=L` on a
+little-endian machine `limit_min` is the low 32 bits of `limit`, and
+`should_balance_chunk()` has already counted `limit` down for the chunk,
+so the i-th match (from 1) sees `limit_min = L - i` and is skipped while
+M < L - i. The first L - M - 1 matches are skipped, each still using up
+one count, and 2M + 1 - L relocate (0 at L >= 2M + 1); L <= M is not
+affected. Big-endian machines read the high half (0) and never had the
+bug.
+
+The fix: `chunk_limit_min_filter(bargs, count)`, true only when
+LIMIT_RANGE is set and LIMIT is not (with both set,
+`should_balance_chunk()` applies the single limit, so the minimum does
+not apply either), replaces the three open-coded checks. Same diff on
+6.18, misc-next and 7.3.
+
+Position: first in the series. It fixes a bug that predates the series
+and does not depend on it. Patches 2-4 never touch the check block
+(patch 3 only adds the `limit_min--` of a LIMIT_RANGE in
+`count_limited_chunk()`), so they replay with identical content, author,
+date and message, and each commit builds on its own (per-commit build
+check below). Patch 3's semantics are unchanged by the fix: it never
+writes `limit_min` for a single limit, and a range's minimum check is
+the same before and after.
+
+New arms of `balance-resume-limit-test.sh` (M = 7 matching data chunks):
+
+| arm | checks | without patch 1 |
+|---|---|---|
+| `lm2` | `limit=M+2` relocates all M | M-1 (6) |
+| `l2m` | `limit=2M` relocates all M | 1 |
+| `l2m1` | `limit=2M+1` relocates all M | 0 |
+| `lres` | `limit=M+2` paused, unmounted, resumed: on-disk item and recovered balance show the limit minus the chunks relocated, total M | the skipped first match is counted: on disk `7 0` instead of `8 0`, recovered `limit=7` instead of 8 |
+| `rmin` | a range keeps its minimum: (M+1)..(M+3) relocates none, M..(M+2) relocates M | same (PASS) |
+
+The informational `alias` arm of 2026-11-08 is now the gating `lm2`.
+
+Kernels: KASAN inline + lockdep + BTRFS_ASSERT, bzImage only.
+
+| kernel | source | rig |
+|---|---|---|
+| 6.18.62+ #36, md5 52d8b941c88b5bbbb5d656371ae9438e | zygo-6.18.x-zb64 a2304e052b9e | ehive |
+| 7.3.0+ #71, md5 6f355e6b685de61483e8dd34dee0c876 | zygo-misc-next-zb64 d4cc0ed0de64 | dhive |
+| 7.3.3+ #5, md5 ef5db4ef50792a55bc991733a05cd458 | zygo-7.3.x-zb64 9e4d6ad5b1f0 | ehive |
+| control 7.3.3+ #3, md5 f9f7e205cd18c56efdeceb048423e178 | zygo-7.3.x-zb64 0a8cc448c33e (patches 2-4, no patch 1) | dhive |
+
+Build checks on all three lanes: per-commit build of base..patch 4
+(5 builds, 0 new warnings, tip links), BTRFS_DEBUG=n W=1 + bzImage at
+the base, the topic tip and the old and new zb64 (no new W=1 warning).
+
+| Test | 6.18 #36 | misc-next #71 | 7.3 #5 | control #3 |
+|---|---|---|---|---|
+| `balance-resume-limit-test.sh`, arms 1 2a 2b 3a 3b 4 5 6 lm2 l2m l2m1 lres rmin | PASS x2 | PASS x2 | PASS x2 | lm2, l2m, l2m1, lres FAIL as predicted (6, 1, 0 of 7 relocated); the other 9 PASS |
+| `balance-resume-convert-test.sh` | PASS x2 | PASS x2 | PASS x2 | - |
+| `balance-resume-test.sh` | PASS | PASS | PASS | - |
+| `balance-resume-reuse-test.sh` | PASS x2 (a first run SKIPped: layout not reached) | PASS x3 | PASS x2 (4 runs SKIPped: layout not reached, the known 7.3 fixture case) | - |
+| `remap-balance-resume-test.sh`, `remap-balance-leak-test.sh` | SKIP (no remap tree), as expected | PASS, PASS (4 allocated, 0 unfreed) | PASS, PASS (4 allocated, 0 unfreed) | - |
+| fl1106 `nounmount-check.sh` | PASS | PASS | PASS | - |
+| `balance-resume-legacy-test.sh check` plain, convert, vrange, convert-vrange, vrange-max (images written by stock Debian 6.12.115) | PASS | PASS | PASS | - |
+
+On 7.3 the same boot also ran `chattr-nodatasum-compress-test.sh` for a
+lane-only pick (PASS). Taint 0 and debug_locks 1 throughout; no KASAN/WARNING/BUG/lockdep lines;
+no NORESERVE or unwritten-on-end lines; the sampled unwritten_on_end*
+counters stayed 0 (truncated delta 0). The control ran only the limit
+test: patches 2-4 are unchanged, and their own controls are in the
+earlier rounds. On 6.18 and misc-next the unfixed check is the same
+upstream code, and the 2026-11-08 round measured the same model on 6.18
+(M=7, limit=9 relocated 6 on #9 and #10).
+
+Open, for this round:
+
+- METADATA_REMAP chunks are counted in `count_meta` but the minimum check
+ tests the METADATA bit only, so a range minimum never skips a remap
+ chunk (pre-existing; patch 1 keeps the existing type tests).
+ Not tested.
+- The 2026-11-08 round's first open item (the alias) is closed by patch 1.
+
## Not covered / open
- `balance-resume-test.sh` and `balance-resume-reuse-test.sh` were not run