]> git.hungrycats.org Git - linux/commitdiff
balance-resume: TESTING: 2026-11-08 round (limit writeback, bl1108), not run yet
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Nov 2026 02:33:58 +0000 (21:33 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Nov 2026 02:33:58 +0000 (21:33 -0500)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
topics/balance-resume/TESTING.md

index 22c119e8856b9b6ec18de5cdf3465bd9f179ead5..f8ed03be8d55585546c2f0fee081bbb7d2548a05 100644 (file)
@@ -241,6 +241,91 @@ 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.
 
+## 2026-11-08 round (bl1108: the limit filters survive an unmount or a crash)
+
+Zygo (2026-11-08): "To handle limit, we'd have to bring back an idea we
+previously rejected: decrement both ends of the limit range and write
+them back after each selected chunk is processed, in addition to vrange.
+That should be a separate commit between the "add vrange" and "restore
+old heuristic behavior" patches".  The series becomes vrange bound (1),
+"btrfs: write the remaining balance limits back to the balance item" (2),
+legacy heuristics (3); the remap leak fix leaves for its own topic.  In
+this section, patch numbers are the new ones.
+
+The bug, without patch 2: `should_balance_chunk()` counts `limit` (or
+`limit_max`) down in memory per selected chunk, and `__btrfs_balance()`
+undoes the counting pass's decrements; the item keeps the original
+values.  A resume after an unmount or a crash restarts at the original
+limit (up to N more chunks per resume, bounded by the vrange to what is
+left); the counting pass of such a resume sees only the remaining
+matches, which can be fewer than `limit_min`, and the resume relocates
+nothing.  `limit_min` is not decremented in memory either, so a range
+resumed by ioctl (no unmount) has the same undercount.
+
+Patch 2: `count_limited_chunk()` after the relocation result is handled
+in `__btrfs_balance()`: for LIMIT_RANGE decrement `limit_min` (clamped at
+0; `limit`/`limit_max` were decremented at selection, as before), then
+`update_balance_item(fs_info, bctl, false)`, which joins the running
+transaction and does not commit; chunk types without LIMIT/LIMIT_RANGE
+return before any write.  Decisions:
+
+- "processed" = relocated, ENOSPC, or active swapfile: what the in-memory
+  count already counted, so mount and ioctl resumes agree;
+- `limit_min` is decremented after the `limit_min` check passed, not at
+  selection (at selection the check would flip mid-pass);
+- pause lands between chunks (`balance_pause_req` is checked at the loop
+  top only, `btrfs_should_cancel_balance()` ignores it), so the chunk in
+  progress is written first; cancel or a fatal signal stops a relocation
+  mid-chunk but deletes the item;
+- an item write error ends the balance like any loop error;
+- crash: the chunk removal (`btrfs_relocate_chunk_finish()`) ends its
+  transaction without committing; the update starts after it, so it
+  commits with it or later.  Bound: at most one extra relocation per
+  crash, never fewer.  The window is the same as with a committing
+  update, without the commit.  Riding in the removal's transaction would
+  need the balance passed into `btrfs_relocate_chunk()` (shared with
+  shrink and device remove).
+
+Candidates (not promoted, not built): `refs/cand/bl1108/{misc-next,7.3,6.18}/balance-resume`;
+misc-next/7.3 without the remap commit (the vrange commits replay clean
+without it).  Oracles: patch 1/3 content lines unchanged (md5
+236bb8028b25 / efe8a0e1ef5a), patch 2 identical on all three lanes
+(fb07a40afc44).  Harness forensics/bl1108.
+
+| Test | Checks | Patch | Time | Current | Kernel |
+|---|---|---|---|---|---|
+| `balance-resume-limit-test.sh` arm 1 (new) | `limit=N` (N = M-1 data chunks), pause after k, unmount: on-disk item (dump-tree) shows N-k, skip_balance mount shows `limit=N-k`, resume: total N; bpftrace: one item update per chunk the resume relocated | 2 | - | not run | - |
+| arm 2a | `limit=M..M`: on disk (M-k)..(M-k), total M | 2 | - | not run | - |
+| arm 2b | `limit=1..M-2`: on disk max(1-k,0)..(M-2-k), total M-2 | 2 | - | not run | - |
+| arm 3a | `limit=N`, ioctl resume on the same mount: in-memory `limit=N-k`, total N | 2 (guard) | - | not run | - |
+| arm 3b | `limit=M..M`, ioctl resume: in-memory (M-k)..(M-k), total M | 2 | - | not run | - |
+| arm 4 | no limit: 0 item updates over pause + resume (bpftrace: `btrfs_search_slot()` on the balance key with ins_len 0, cow 1, robust to inlining); positive control `limit=2`: exactly 2 | 2 | - | not run | - |
+| arm 5 | dm-log-writes, `limit=N` to the end, every flush state replayed in order and read with dump-tree: with the item present, R + L in {N, N+1}; counts the N+1 states | 2 | - | not run | - |
+| arm `alias` (informational) | `limit=M+2` with M matches: how many relocate (see open items) | - | - | not run | - |
+
+Expected on a kernel without patch 2: arm 1 FAILs (on-disk N, total up
+to k+N), 2a FAILs (total k: the resume counts M-k < M), 2b FAILs
+(total > M-2), 3b FAILs (total k), arm 4's positive control FAILs (0
+updates), arm 5 FAILs (R + L grows past N+1); 3a PASSes.
+
+Open, for this 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`.  On paper,
+  `limit=L` with M <= L-2 matching chunks relocates nothing (count M <
+  limit_min = L-1 after the first selection).  Upstream since 12907fc79818
+  (2015), independent of this series; arm `alias` reports it.  The
+  limit tests use L <= M so they do not depend on it.
+- METADATA_REMAP chunks are counted at selection and queued;
+  `count_limited_chunk()` is not called for them, and a pause drops the
+  queue with the budget consumed (pre-existing; in memory and on disk
+  alike).  Not tested.
+- A fatal signal while a pause is pending keeps the item with the
+  interrupted chunk counted in memory but not on disk.  Not tested.
+- The cover's "The upper bound never moves, so there is no progress to
+  track or persist." is now only true of the bound; flagged, not edited.
+
 ## Not covered / open
 
 - Patch 1's other bail-outs (cancel, chunk search or relocation errors,