]> git.hungrycats.org Git - linux/commitdiff
nocmtime, remap-balance-leak: re-export after the nc1108 misc-next promotion
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Nov 2026 13:42:32 +0000 (08:42 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Nov 2026 13:42:32 +0000 (08:42 -0500)
misc-next testing 5fa1c4f82174, zb64 fb7546be6023 (base 83cd81353093).

- Jeff Layton's FMODE_NOCMTIME series replaces dedupe-mtime in the lane
  (topics/nocmtime).  It is Jeff's, so exclude.txt drops its four
  subjects and topics/dedupe-mtime is removed.  Two of its reverts from
  testing need stored resolutions (scripts/revert-resolutions/, README);
  export.sh's verify step now reverts the dropped commits newest first.
- "btrfs: free queued remap chunks when balance bails out" leaves
  balance-resume for its own series, topics/remap-balance-leak (1 patch,
  no cover yet), merged right after balance-resume: README series table
  and ORDER.  Its leak test rows move to its TESTING.md, plus the
  2026-11-09 misc-next result.
- balance-resume is now vrange (1), limit write-back (2), legacy filters
  (3); TESTING.md's rounds before 2026-11-08 are renumbered to match.
  The cover changed only in its From/Date headers (patch count 3 -> 3,
  shortlog and diffstat already current).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 files changed:
README.md
fixups/post-merge.patch
scripts/exclude.txt
scripts/export.sh
scripts/revert-resolutions/ac5b3f57bce5c140a826e9e200fa7c35f04a2327.patch [new file with mode: 0644]
scripts/revert-resolutions/ae5c9f6ab97a8601795ff23277eb78ba379106f6.patch [new file with mode: 0644]
topics/allocator-hints/0000-cover-letter.patch
topics/balance-resume/0000-cover-letter.patch
topics/balance-resume/0001-btrfs-free-queued-remap-chunks-when-balance-bails-ou.patch [deleted file]
topics/balance-resume/0001-btrfs-replace-the-balance-resume-heuristics-with-a-v.patch [new file with mode: 0644]
topics/balance-resume/0002-btrfs-replace-the-balance-resume-heuristics-with-a-v.patch [deleted file]
topics/balance-resume/0002-btrfs-write-the-remaining-balance-limits-back-to-the.patch [new file with mode: 0644]
topics/balance-resume/0003-btrfs-keep-the-old-resume-filters-for-balance-items-.patch
topics/balance-resume/TESTING.md
topics/compress-fixes/0000-cover-letter.patch
topics/deadlock-fixes/0000-cover-letter.patch
topics/dedupe-fixes/0000-cover-letter.patch
topics/dedupe-mtime/0000-cover-letter.patch [deleted file]
topics/dedupe-mtime/0001-btrfs-don-t-update-mtime-and-ctime-when-deduping-a-r.patch [deleted file]
topics/dedupe-mtime/TESTING.md [deleted file]
topics/delalloc-fixes/0000-cover-letter.patch
topics/dev-extent-defrag/0000-cover-letter.patch
topics/dev-stats/0000-cover-letter.patch
topics/logical-ino-costs/0000-cover-letter.patch
topics/low-space/0000-cover-letter.patch
topics/prealloc-size/0000-cover-letter.patch
topics/raid56-fixes/0000-cover-letter.patch
topics/raid56-scrub-replace/0000-cover-letter.patch
topics/read-policies/0000-cover-letter.patch
topics/read-repair-fixes/0000-cover-letter.patch
topics/reclaim-fixes/0000-cover-letter.patch
topics/reflink-inline-fixes/0000-cover-letter.patch
topics/remap-balance-leak/0001-btrfs-free-queued-remap-chunks-when-balance-bails-ou.patch [new file with mode: 0644]
topics/remap-balance-leak/TESTING.md [new file with mode: 0644]
topics/replace-fixes/0000-cover-letter.patch
topics/resize-missing/0000-cover-letter.patch
topics/stripe-alloc/0000-cover-letter.patch

index fab093f1dd53564e4909adbde15da308515133a7..8cdbb8a96da2a42def78e227aa89df6d211f21ed 100644 (file)
--- a/README.md
+++ b/README.md
@@ -48,7 +48,7 @@ topics/<branch>/NNNN-<subject>.patch      the patches, in branch order
 fixups/post-merge.patch                   what integrating all series needs (below)
 scripts/export.sh                         re-export from ~/share/linux, keeping the cover letters
 scripts/exclude.txt                       what the export leaves out besides marked commits
-scripts/revert-resolutions/<sha>.patch    hand resolutions for reverting a left-out commit from testing (none now; below)
+scripts/revert-resolutions/<sha>.patch    hand resolutions for reverting a left-out commit from testing (two: nocmtime 3/4 and 4/4; below)
 ```
 
 Every series has a cover letter, single-patch ones included (0/1); the
@@ -88,8 +88,18 @@ As of misc-next `testing` `0dd345dcdb09` (2026-10-31):
 | `dm-stripfault` (2 commits) | test fixtures; `topic` entry, both commits marked |
 | `test-knobs` (2 commits: the reclaim exclusive-operation gap, Zygo 2026-10-29 "do-not-upstream"; the rbio cache size debug knob) | test-only; `topic` entry, both commits marked |
 
-No stored resolution is in use: both left-out topics revert cleanly
-from testing.  (Until 2026-10-31 the knob's declaration in testing's
+Since nc1108 (2026-11-08) the lane carries Jeff Layton's "btrfs: fix
+FMODE_NOCMTIME handling in btrfs" (2026-11-05, 4 patches) as
+`topics/nocmtime`, in place of Ivan Kozik's `dedupe-mtime` (Jeff's patch 2
+contains Ivan's fix).  It is Jeff's series, so `exclude.txt` drops its four
+subjects and nothing of it is exported; `topics/dedupe-mtime` was removed.
+Two of its reverts need stored resolutions, because testing's octopus
+merges Jeff's lines into lane code: `ae5c9f6ab97a…` (3/4, `file.c`: the
+`btrfs_prealloc_file_range()` call in `btrfs_zero_range()` that the lane
+follows with `btrfs_stripe_prealloc_release()`) and `ac5b3f57bce5…` (4/4,
+`reflink.c`: the `btrfs_clone()` call after the lane's delalloc recheck
+loop in `btrfs_clone_files()`).  The other left-out commits revert
+cleanly.  (Until 2026-10-31 the knob's declaration in testing's
 `raid56.h` sat right above raid56-fixes' `btrfs_raid56_uncache_range()`
 and needed one; the lane moved the declaration.)
 
@@ -103,6 +113,7 @@ series applies on top of; the others apply to the base.
 |---|---|---|---|---|
 | `logical-ino-costs` | 3 | | Zygo, Kai Krakow | patch 3 is Kai's, already posted by him |
 | `balance-resume` | 3 | | Zygo | patch 3 optional, offered for rejection |
+| `remap-balance-leak` | 1 | | Zygo | was balance-resume patch 1 until 2026-11-08; independent of it |
 | `compress-fixes` | 5 | | Zygo | |
 | `deadlock-fixes` | 3 | | Zygo | the relock fix is folded into patch 2 (2026-10-30) |
 | `dedupe-fixes` | 1 | | Zygo | |
@@ -115,7 +126,6 @@ series applies on top of; the others apply to the base.
 | `reclaim-fixes` | 3 | | Zygo | |
 | `stripe-alloc` | 85 | `reclaim-fixes` | Zygo | RFC; reordered by subtopic 2026-10-28; subtopic 6 (debug) not for merging; stripe_meta may be dropped |
 | `low-space` | 3 | `stripe-alloc` | Zygo | reserve off by default; patch 3 fixes an upstream relocation abort and stands alone |
-| `dedupe-mtime` | 1 | | Ivan Kozik | Ivan's patch |
 | `allocator-hints` | 12 | | Kai Krakow, KeinNiemand, Zygo | Kai's series plus follow-ups; the authors' postings are authoritative |
 | `read-policies` | 9 | | Kai Krakow | Kai's series; his postings are authoritative |
 | `replace-fixes` | 10 | | Zygo | patch 8 has a btrfs-progs counterpart |
@@ -158,9 +168,9 @@ hunks keep the side merged so far), then apply the fixup:
 cd ~/share/linux
 P=~/share/linux-upstream
 B=bf921b86bdf2
-ORDER="logical-ino-costs balance-resume compress-fixes deadlock-fixes dedupe-fixes
+ORDER="logical-ino-costs balance-resume remap-balance-leak compress-fixes deadlock-fixes dedupe-fixes
        delalloc-fixes dev-extent-defrag prealloc-size raid56-fixes read-repair-fixes
-       raid56-scrub-replace reclaim-fixes stripe-alloc low-space dedupe-mtime
+       raid56-scrub-replace reclaim-fixes stripe-alloc low-space
        allocator-hints read-policies replace-fixes dev-stats resize-missing
        reflink-inline-fixes"
 declare -A ON=([raid56-scrub-replace]=read-repair-fixes
index 1bc54150631babd956f53e84a9e4d335988d604d..d744a3399393fc17105b65cf1d1b66da3a9247af 100644 (file)
@@ -403,10 +403,10 @@ index 1644b1edfe15a6f98308e7377a40e9ebd520274d..90b62d7d59ffe1546cf1e27a5dd5cc87
   * Information about one device.
   *
 diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 068dd5d168b4e02b2e2fe136ea4a018d32ed95c0..a067b76455eef3cdb5004e7592c0efe02ae8c66e 100644
+index 6f481b00224e56dedd5b219117aad90bca24353f..68c890eedcefa9321408eab5542d06bd27188e89 100644
 --- a/fs/btrfs/volumes.c
 +++ b/fs/btrfs/volumes.c
-@@ -7055,7 +7055,293 @@ bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical)
+@@ -7113,7 +7113,293 @@ bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical)
        return ret;
  }
  
index d9cddef9a58771a7d9031a262f37bc11764c1041..7fce271c5a59b00f1a5df37bd22d614f6d619b49 100644 (file)
@@ -34,3 +34,13 @@ subject btrfs: remove devid kobject when deleting a missing device
 # stripe_meta section (km1107).  It drops if stripe_meta drops.  Resend
 # (Mark, or ours with credit to him) only once stripe_meta is accepted.
 subject btrfs: raid56: pass REQ_META to per-device bios
+
+# Lane-only (Zygo 2026-11-08): Jeff Layton's "btrfs: fix FMODE_NOCMTIME
+# handling in btrfs" (2026-11-05, 4 patches) is his series, his to send;
+# the lanes carry it as topics/nocmtime in place of topics/dedupe-mtime
+# (Ivan Kozik's dedupe fix, which its patch 2 contains; nc1108).  Drop
+# these when the series lands upstream.
+subject btrfs: honor FMODE_NOCMTIME in btrfs_write_check()
+subject btrfs: honor FMODE_NOCMTIME when punching holes
+subject btrfs: honor FMODE_NOCMTIME in fallocate
+subject btrfs: honor FMODE_NOCMTIME when cloning
index ec00004d0161a22e39b30c5c9451efce785414c6..97c0bc12dee3f92111912d3dc4d1e5ee916988cf 100755 (executable)
@@ -303,8 +303,10 @@ for t in "${exported[@]}"; do
        got=$(GIT_INDEX_FILE=$idx git write-tree)
        [ "$got" = "$(git rev-parse "${NEWTIP[$t]}^{tree}")" ] || die "verify: $t patches != exported tip"
        want=$(git rev-parse "$PFX$t")
-       for x in "${dropped[@]}"; do
-               IFS='   ' read -r u c why s <<< "$x"
+       # newest first, as for the fixup target: a dropped commit that a later
+       # dropped one builds on reverts only after it
+       for ((k=${#dropped[@]}-1; k>=0; k--)); do
+               IFS='   ' read -r u c why s <<< "${dropped[$k]}"
                git merge-base --is-ancestor "$c" "$PFX$t" || continue
                tree=$(git merge-tree --write-tree --name-only --merge-base="$c" "$want" "$c^" | head -1) || die "verify: $t minus $c does not revert cleanly"
                want=$(git commit-tree "$tree" -p "$want" -m "revert $c")
diff --git a/scripts/revert-resolutions/ac5b3f57bce5c140a826e9e200fa7c35f04a2327.patch b/scripts/revert-resolutions/ac5b3f57bce5c140a826e9e200fa7c35f04a2327.patch
new file mode 100644 (file)
index 0000000..182bee9
--- /dev/null
@@ -0,0 +1,12 @@
+--- a/fs/btrfs/reflink.c
++++ b/fs/btrfs/reflink.c
+@@ -835,8 +835,7 @@
+               if (ret)
+                       return ret;
+       }
+-      ret = btrfs_clone(src, inode, off, olen, len, destoff,
+-                        !btrfs_should_update_cmtime(file));
++      ret = btrfs_clone(src, inode, off, olen, len, destoff, false);
+       btrfs_unlock_extent(&inode->io_tree, destoff, end, &cached_state);
+       if (ret < 0)
+               return ret;
diff --git a/scripts/revert-resolutions/ae5c9f6ab97a8601795ff23277eb78ba379106f6.patch b/scripts/revert-resolutions/ae5c9f6ab97a8601795ff23277eb78ba379106f6.patch
new file mode 100644 (file)
index 0000000..ba053c9
--- /dev/null
@@ -0,0 +1,118 @@
+--- a/fs/btrfs/file.c
++++ b/fs/btrfs/file.c
+@@ -2934,8 +2934,7 @@
+ 
+ static int btrfs_fallocate_update_isize(struct inode *inode,
+                                       const u64 end,
+-                                      const int mode,
+-                                      bool update_times)
++                                      const int mode)
+ {
+       struct btrfs_trans_handle *trans;
+       struct btrfs_root *root = BTRFS_I(inode)->root;
+@@ -2959,9 +2958,7 @@
+       if (IS_ERR(trans))
+               return PTR_ERR(trans);
+ 
+-      inode_inc_iversion(inode);
+-      if (update_times)
+-              inode_set_ctime_current(inode);
++      inode_set_ctime_current(inode);
+       i_size_write(inode, end);
+       btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0);
+       ret = btrfs_update_inode(trans, BTRFS_I(inode));
+@@ -3002,8 +2999,7 @@
+ static int btrfs_zero_range(struct inode *inode,
+                           loff_t offset,
+                           loff_t len,
+-                          const int mode,
+-                          bool update_times)
++                          const int mode)
+ {
+       struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
+       struct extent_map *em;
+@@ -3045,7 +3041,7 @@
+                        */
+                       btrfs_free_extent_map(em);
+                       ret = btrfs_fallocate_update_isize(inode, offset + len,
+-                                                         mode, update_times);
++                                                         mode);
+                       goto out;
+               }
+               /*
+@@ -3071,7 +3067,7 @@
+               if (em->flags & EXTENT_FLAG_PREALLOC) {
+                       btrfs_free_extent_map(em);
+                       ret = btrfs_fallocate_update_isize(inode, offset + len,
+-                                                         mode, update_times);
++                                                         mode);
+                       goto out;
+               }
+               if (len < sectorsize && em->disk_bytenr != EXTENT_MAP_HOLE) {
+@@ -3081,8 +3077,7 @@
+                       if (!ret)
+                               ret = btrfs_fallocate_update_isize(inode,
+                                                                  offset + len,
+-                                                                 mode,
+-                                                                 update_times);
++                                                                 mode);
+                       return ret;
+               }
+               btrfs_free_extent_map(em);
+@@ -3161,8 +3156,7 @@
+               ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
+                                               alloc_end - alloc_start,
+                                               fs_info->sectorsize,
+-                                              offset + len, &alloc_hint,
+-                                              update_times);
++                                              offset + len, &alloc_hint);
+               btrfs_stripe_prealloc_release(fs_info, stripe_held);
+               stripe_held = 0;
+               btrfs_unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
+@@ -3173,8 +3167,7 @@
+                       goto out;
+               }
+       }
+-      ret = btrfs_fallocate_update_isize(inode, offset + len, mode,
+-                                         update_times);
++      ret = btrfs_fallocate_update_isize(inode, offset + len, mode);
+  out:
+       btrfs_stripe_prealloc_release(fs_info, stripe_held);
+       if (ret && space_reserved)
+@@ -3207,7 +3200,6 @@
+       u64 qgroup_reserved = 0;
+       struct extent_map *em;
+       int blocksize = BTRFS_I(inode)->root->fs_info->sectorsize;
+-      const bool update_times = btrfs_should_update_cmtime(file);
+       int ret;
+ 
+       if (btrfs_is_shutdown(inode_to_fs_info(inode)))
+@@ -3279,7 +3271,7 @@
+               goto out;
+ 
+       if (mode & FALLOC_FL_ZERO_RANGE) {
+-              ret = btrfs_zero_range(inode, offset, len, mode, update_times);
++              ret = btrfs_zero_range(inode, offset, len, mode);
+               btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
+               return ret;
+       }
+@@ -3345,8 +3337,7 @@
+                       ret = btrfs_prealloc_file_range(inode, mode,
+                                       range->start,
+                                       range->len, blocksize,
+-                                      offset + len, &alloc_hint,
+-                                      update_times);
++                                      offset + len, &alloc_hint);
+                       /*
+                        * btrfs_prealloc_file_range() releases space even
+                        * if it returns an error.
+@@ -3375,8 +3366,7 @@
+        * We didn't need to allocate any more space, but we still extended the
+        * size of the file so we need to update i_size and the inode item.
+        */
+-      ret = btrfs_fallocate_update_isize(inode, actual_end, mode,
+-                                         update_times);
++      ret = btrfs_fallocate_update_isize(inode, actual_end, mode);
+ out_unlock:
+       btrfs_unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
+                           &cached_state);
index cd07f9d3d68c78ba1f1a574eaa59c042855ddc88..105a35728fd772a9d7dde99a6c9855121f423cae 100644 (file)
@@ -1,6 +1,6 @@
 From df0e45e0fe79ddc8c332cba8ab8678b37e55c160 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:23 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 00/12] btrfs: allocator hints (Kai Krakow's series)
 To: linux-btrfs@vger.kernel.org
 
index 35c2e72145a4b08c2d6bb49dac04e8540349a518..881502adce327b946c9d787c89a92f7da87e4aea 100644 (file)
@@ -1,6 +1,6 @@
-From e38f7c20705d1ff55bd3ed96b2e3c83650037984 Mon Sep 17 00:00:00 2001
+From 968195f996534fe154954da3246b2b2a3920a653 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:19 -0500
+Date: Mon, 9 Nov 2026 08:41:05 -0500
 Subject: [PATCH 0/3] btrfs: balance resume selects what the original request selected
 To: linux-btrfs@vger.kernel.org
 
diff --git a/topics/balance-resume/0001-btrfs-free-queued-remap-chunks-when-balance-bails-ou.patch b/topics/balance-resume/0001-btrfs-free-queued-remap-chunks-when-balance-bails-ou.patch
deleted file mode 100644 (file)
index 0f1f4db..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-From d0136e6493082d001aa33ed4174dae6062abb49a 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
-To: linux-btrfs@vger.kernel.org
-
-__btrfs_balance() queues METADATA_REMAP chunks on a local list and
-balances them only after the main loop, in balance_remap_chunks(), which
-also frees the entries.  Every path that leaves the loop through the
-error label skips that call: a pause or cancel request, a chunk tree
-search error, should_balance_chunk() failing, btrfs_may_alloc_data_chunk()
-or relocation errors, or the allocation of a later entry failing.  The
-entries queued so far are leaked.
-
-Free the leftover entries at the error label.  Nothing else needs undoing:
-the block group lookup, the reference and the read-only count are all
-taken inside balance_remap_chunks(), so a queued entry holds no block
-group and none is left read-only.
-
-Fixes: 81e5a4551c32 ("btrfs: allow balancing remap tree")
----
- fs/btrfs/volumes.c | 8 ++++++++
- 1 file changed, 8 insertions(+)
-
-diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 3d4ef6725de0e..788f60910acf5 100644
---- a/fs/btrfs/volumes.c
-+++ b/fs/btrfs/volumes.c
-@@ -4756,6 +4756,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
-               }
-       }
- error:
-+      /* Entries left over when the loop bailed out before balancing them. */
-+      while (!list_empty(&remap_chunks)) {
-+              rci = list_first_entry(&remap_chunks, struct remap_chunk_info,
-+                                     list);
-+              list_del(&rci->list);
-+              kfree(rci);
-+      }
-+
-       if (enospc_errors) {
-               btrfs_info(fs_info, "%d enospc errors during balance",
-                          enospc_errors);
--- 
-2.47.3
-
diff --git a/topics/balance-resume/0001-btrfs-replace-the-balance-resume-heuristics-with-a-v.patch b/topics/balance-resume/0001-btrfs-replace-the-balance-resume-heuristics-with-a-v.patch
new file mode 100644 (file)
index 0000000..f3298ec
--- /dev/null
@@ -0,0 +1,392 @@
+From 26550289a0ae301b3e2e933d1b8a11fe70150786 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 1/3] btrfs: replace the balance resume heuristics with a
+ vrange bound
+To: linux-btrfs@vger.kernel.org
+
+When a balance is resumed after a pause or an unmount,
+update_balance_args() adds a usage=90 filter to every chunk type that is
+not being converted.  That changes the set of block groups the original
+request selected.  It skips full block groups the interrupted balance had
+not reached yet, so the resumed balance can finish without having done
+what was asked, and it selects again any block group the interrupted
+balance created that is less than 90% full, relocating the same data a
+second time.  For the chunk types that are being converted it adds the
+soft filter instead, so the resume does not convert again the block
+groups the interrupted balance converted, but it also skips the ones
+that already had the target profile when the balance started, which the
+original request selected.
+
+Replace it with a bound fixed when the balance starts.  Before the
+balance item is written, limit the vrange filter of each chunk type to
+the addresses below the next chunk to be allocated: add a 0..end range
+when the request had no vrange filter, or lower the end of the one it
+had.  Every block group that existed when the balance started stays
+selected until the balance relocates it.
+
+New chunks are allocated after the last chunk, but relocation can remove
+the highest chunks without allocating any (their data fits in free space
+lower down), and the next chunk would then reuse their addresses, below
+the bound.  A resumed balance would select it again, although the
+interrupted one, walking downward, never would have.  So while a balance
+item exists, find_next_chunk() never returns an address below the bound:
+an in-memory floor, set when the balance starts and when the balance
+item is recovered at mount, and cleared when the item is deleted.  Every
+chunk allocated in that time, relocation targets included, stays outside
+the range, on the first run and after a resume.  The gap the floor can
+leave in the logical address space is harmless.
+
+A resume now uses the arguments exactly as they were stored: the bound
+already keeps out every block group the interrupted balance created,
+converted ones included, so neither the usage filter nor the soft filter
+is needed, and update_balance_args() goes away.
+
+The bound does not move as the balance progresses.  Block groups the
+balance has relocated are gone, so on resume the walk only revisits the
+chunks it left in place above the point where it stopped (filtered out,
+ENOSPC, active swapfile) and checks them against the filters again.
+Nothing is skipped.
+
+Because the bound is written with the balance item and never changes,
+there is no progress to persist: a resume after an unmount or a crash
+needs no extra writes.
+
+A balance item recovered at mount is limited in the same way before the
+floor is set from it: a vrange 0..end is added to each chunk type that
+has none, and a vrange that ends above the next chunk is lowered to it.
+That covers items written by older kernels, which have no vrange or a
+vrange the user gave, which can end anywhere (a 1 TiB end would put
+every new chunk at 1 TiB and above).  A bound written by this kernel
+changes only when relocation removed the highest chunks and allocated
+none above it; no chunk exists between the next chunk and the old end,
+so lowering it drops nothing.  When the recovered arguments change,
+they are written back to the balance item once, when the balance
+resumes, so a resume that is interrupted again resumes with the same
+bound and not with a new one that includes the chunks the first resume
+allocated.  If that write fails, the balance is not resumed: as for the
+other errors at that point, it ends with the error logged, and its item
+is deleted.  Nothing has been relocated yet, so if the item survives (the
+delete fails too, or the system crashes first), the next mount bounds it
+again to the same chunks.
+
+A balance item written by an older kernel therefore resumes with the
+bound and without the usage or soft filter: the resumed balance restarts
+from the beginning, relocating again every block group the request
+selects, including the ones the interrupted run created or converted,
+but it skips none.
+
+The bound is visible: `btrfs balance status -v`, the
+BTRFS_IOC_BALANCE_PROGRESS ioctl and the "balance: start" and "balance:
+resume" log lines show a vrange the user did not give.
+
+---
+ fs/btrfs/fs.h      |   6 ++
+ fs/btrfs/volumes.c | 188 +++++++++++++++++++++++++++++++++------------
+ fs/btrfs/volumes.h |   6 ++
+ 3 files changed, 150 insertions(+), 50 deletions(-)
+
+diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
+index 2dd167c32d612..a42aa4de2bcc6 100644
+--- a/fs/btrfs/fs.h
++++ b/fs/btrfs/fs.h
+@@ -785,6 +785,12 @@ struct btrfs_fs_info {
+       atomic_t balance_cancel_req;
+       struct btrfs_balance_control *balance_ctl;
+       wait_queue_head_t balance_wait_q;
++      /*
++       * 0, or the end of the balance's vrange bound: while a balance item
++       * exists (running or paused) find_next_chunk() allocates at or above
++       * it, so the balance never selects a chunk it allocated.
++       */
++      u64 balance_chunk_floor;
+ 
+       /* Cancellation requests for chunk relocation */
+       atomic_t reloc_cancel_req;
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index 3d4ef6725de0e..74f7e96ceb9e0 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)
+       }
+       read_unlock(&fs_info->mapping_tree_lock);
+ 
+-      return ret;
++      return max(ret, READ_ONCE(fs_info->balance_chunk_floor));
+ }
+ 
+ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
+@@ -3970,13 +3970,27 @@ static void btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
+       disk->stripes_max = cpu_to_le32(cpu->stripes_max);
+ }
+ 
++static void set_balance_item(struct extent_buffer *leaf,
++                           struct btrfs_balance_item *item,
++                           const struct btrfs_balance_control *bctl)
++{
++      struct btrfs_disk_balance_args disk_bargs;
++
++      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
++      btrfs_set_balance_data(leaf, item, &disk_bargs);
++      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
++      btrfs_set_balance_meta(leaf, item, &disk_bargs);
++      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
++      btrfs_set_balance_sys(leaf, item, &disk_bargs);
++      btrfs_set_balance_flags(leaf, item, bctl->flags & ~BTRFS_BALANCE_RESUME);
++}
++
+ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+                              struct btrfs_balance_control *bctl)
+ {
+       struct btrfs_root *root = fs_info->tree_root;
+       struct btrfs_trans_handle *trans;
+       struct btrfs_balance_item *item;
+-      struct btrfs_disk_balance_args disk_bargs;
+       struct btrfs_path *path;
+       struct extent_buffer *leaf;
+       struct btrfs_key key;
+@@ -4005,14 +4019,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+       item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
+ 
+       memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item));
+-
+-      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
+-      btrfs_set_balance_data(leaf, item, &disk_bargs);
+-      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
+-      btrfs_set_balance_meta(leaf, item, &disk_bargs);
+-      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
+-      btrfs_set_balance_sys(leaf, item, &disk_bargs);
+-      btrfs_set_balance_flags(leaf, item, bctl->flags);
++      set_balance_item(leaf, item, bctl);
+ out:
+       btrfs_free_path(path);
+       if (ret == 0)
+@@ -4023,6 +4030,43 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+       return ret;
+ }
+ 
++/* Write the arguments of a resumed balance to its existing item. */
++static int update_balance_item(struct btrfs_fs_info *fs_info,
++                             const struct btrfs_balance_control *bctl)
++{
++      struct btrfs_root *root = fs_info->tree_root;
++      struct btrfs_trans_handle *trans;
++      BTRFS_PATH_AUTO_FREE(path);
++      struct btrfs_key key;
++      int ret;
++
++      path = btrfs_alloc_path();
++      if (!path)
++              return -ENOMEM;
++
++      trans = btrfs_start_transaction(root, 0);
++      if (IS_ERR(trans))
++              return PTR_ERR(trans);
++
++      key.objectid = BTRFS_BALANCE_OBJECTID;
++      key.type = BTRFS_TEMPORARY_ITEM_KEY;
++      key.offset = 0;
++
++      ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
++      if (ret > 0)
++              ret = -ENOENT;
++      if (ret < 0) {
++              btrfs_end_transaction(trans);
++              return ret;
++      }
++
++      set_balance_item(path->nodes[0],
++                       btrfs_item_ptr(path->nodes[0], path->slots[0],
++                                      struct btrfs_balance_item), bctl);
++      btrfs_release_path(path);
++      return btrfs_commit_transaction(trans);
++}
++
+ static int del_balance_item(struct btrfs_fs_info *fs_info)
+ {
+       struct btrfs_root *root = fs_info->tree_root;
+@@ -4064,47 +4108,61 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
+       return ret;
+ }
+ 
++static bool limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
++{
++      if (!(bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)) {
++              bargs->flags |= BTRFS_BALANCE_ARGS_VRANGE;
++              bargs->vstart = 0;
++              bargs->vend = end;
++              return true;
++      }
++      if (bargs->vend <= end)
++              return false;
++      bargs->vend = end;
++      return true;
++}
++
+ /*
+- * This is a heuristic used to reduce the number of chunks balanced on
+- * resume after balance was interrupted.
++ * Limit the request to the chunks that exist now.  The bound is written with
++ * the balance item and never moves, so there is no progress to persist.  New
++ * chunks are allocated after the last chunk, but once relocation has removed
++ * the highest chunks the last chunk is lower than the bound, so while the
++ * balance item exists find_next_chunk() also observes balance_chunk_floor:
++ * every chunk allocated in that time, relocation targets included, stays
++ * outside the range, on this run and after a resume.
++ *
++ * Return true if any of the arguments changed.
+  */
+-static void update_balance_args(struct btrfs_balance_control *bctl)
++static bool limit_balance_to_existing_chunks(struct btrfs_fs_info *fs_info,
++                                           struct btrfs_balance_control *bctl)
+ {
+-      /*
+-       * Turn on soft mode for chunk types that were being converted.
+-       */
+-      if (bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)
+-              bctl->data.flags |= BTRFS_BALANCE_ARGS_SOFT;
+-      if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)
+-              bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
+-      if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
+-              bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
++      const u64 end = find_next_chunk(fs_info);
++      bool changed = false;
+ 
+-      /*
+-       * Turn on usage filter if is not already used.  The idea is
+-       * that chunks that we have already balanced should be
+-       * reasonably full.  Don't do it for chunks that are being
+-       * converted - that will keep us from relocating unconverted
+-       * (albeit full) chunks.
+-       */
+-      if (!(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE) &&
+-          !(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
+-          !(bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
+-              bctl->data.flags |= BTRFS_BALANCE_ARGS_USAGE;
+-              bctl->data.usage = 90;
+-      }
+-      if (!(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE) &&
+-          !(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
+-          !(bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
+-              bctl->sys.flags |= BTRFS_BALANCE_ARGS_USAGE;
+-              bctl->sys.usage = 90;
+-      }
+-      if (!(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE) &&
+-          !(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
+-          !(bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
+-              bctl->meta.flags |= BTRFS_BALANCE_ARGS_USAGE;
+-              bctl->meta.usage = 90;
+-      }
++      if (bctl->flags & BTRFS_BALANCE_DATA)
++              changed |= limit_balance_vrange(&bctl->data, end);
++      if (bctl->flags & BTRFS_BALANCE_METADATA)
++              changed |= limit_balance_vrange(&bctl->meta, end);
++      if (bctl->flags & BTRFS_BALANCE_SYSTEM)
++              changed |= limit_balance_vrange(&bctl->sys, end);
++      return changed;
++}
++
++/* The highest vrange end of the selected chunk types, 0 if none has one. */
++static u64 balance_chunk_floor(const struct btrfs_balance_control *bctl)
++{
++      u64 floor = 0;
++
++      if ((bctl->flags & BTRFS_BALANCE_DATA) &&
++          (bctl->data.flags & BTRFS_BALANCE_ARGS_VRANGE))
++              floor = max(floor, bctl->data.vend);
++      if ((bctl->flags & BTRFS_BALANCE_METADATA) &&
++          (bctl->meta.flags & BTRFS_BALANCE_ARGS_VRANGE))
++              floor = max(floor, bctl->meta.vend);
++      if ((bctl->flags & BTRFS_BALANCE_SYSTEM) &&
++          (bctl->sys.flags & BTRFS_BALANCE_ARGS_VRANGE))
++              floor = max(floor, bctl->sys.vend);
++      return floor;
+ }
+ 
+ /*
+@@ -4123,6 +4181,7 @@ static void reset_balance_state(struct btrfs_fs_info *fs_info)
+ 
+       kfree(bctl);
+       ret = del_balance_item(fs_info);
++      WRITE_ONCE(fs_info->balance_chunk_floor, 0);
+       if (ret)
+               btrfs_handle_fs_error(fs_info, ret, NULL);
+ }
+@@ -5080,6 +5139,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
+                               btrfs_bg_type_to_raid_name(data_target));
+       }
+ 
++      if (!(bctl->flags & BTRFS_BALANCE_RESUME))
++              limit_balance_to_existing_chunks(fs_info, bctl);
++
+       ret = insert_balance_item(fs_info, bctl);
+       if (ret && ret != -EEXIST)
+               goto out;
+@@ -5090,11 +5152,26 @@ 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);
++              WRITE_ONCE(fs_info->balance_chunk_floor,
++                         balance_chunk_floor(bctl));
+       } else {
+               BUG_ON(ret != -EEXIST);
+-              spin_lock(&fs_info->balance_lock);
+-              update_balance_args(bctl);
+-              spin_unlock(&fs_info->balance_lock);
++              if (bctl->update_item) {
++                      /*
++                       * Nothing has been relocated yet, so the item on disk,
++                       * bounded again at the next mount, is still right.  As
++                       * for the other errors here, the balance ends and its
++                       * item is deleted.
++                       */
++                      ret = update_balance_item(fs_info, bctl);
++                      if (ret) {
++                              btrfs_err(fs_info,
++                      "balance: failed to write the bounded balance item: %d",
++                                        ret);
++                              goto out;
++                      }
++                      bctl->update_item = false;
++              }
+       }
+ 
+       ASSERT(!test_bit(BTRFS_FS_BALANCE_RUNNING, &fs_info->flags));
+@@ -5247,6 +5324,17 @@ 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);
+ 
++      /*
++       * Bound the request as a new balance would be: an item written by an
++       * older kernel has no vrange, and one a user gave to such a kernel can
++       * end anywhere.  The floor is still 0, so find_next_chunk() returns the
++       * end of the last chunk, and lowering a vend above it drops no block
++       * group from the range.  The bound is written back to the item when
++       * the balance resumes, so a resume that is interrupted again keeps it.
++       */
++      bctl->update_item = limit_balance_to_existing_chunks(fs_info, bctl);
++      WRITE_ONCE(fs_info->balance_chunk_floor, balance_chunk_floor(bctl));
++
+       /*
+        * This should never happen, as the paused balance state is recovered
+        * during mount without any chance of other exclusive ops to collide.
+diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
+index 891bc2432870a..e7112257014e8 100644
+--- a/fs/btrfs/volumes.h
++++ b/fs/btrfs/volumes.h
+@@ -665,6 +665,12 @@ struct btrfs_balance_control {
+ 
+       u64 flags;
+ 
++      /*
++       * The arguments recovered at mount were bounded and differ from the
++       * balance item: write them back when the balance resumes.
++       */
++      bool update_item;
++
+       struct btrfs_balance_progress stat;
+ };
+ 
+-- 
+2.47.3
+
diff --git a/topics/balance-resume/0002-btrfs-replace-the-balance-resume-heuristics-with-a-v.patch b/topics/balance-resume/0002-btrfs-replace-the-balance-resume-heuristics-with-a-v.patch
deleted file mode 100644 (file)
index bd61bc2..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-From d406ea315d237d2860e238c0cccdf9dc2c94b3c0 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 balance resume heuristics with a
- vrange bound
-To: linux-btrfs@vger.kernel.org
-
-When a balance is resumed after a pause or an unmount,
-update_balance_args() adds a usage=90 filter to every chunk type that is
-not being converted.  That changes the set of block groups the original
-request selected.  It skips full block groups the interrupted balance had
-not reached yet, so the resumed balance can finish without having done
-what was asked, and it selects again any block group the interrupted
-balance created that is less than 90% full, relocating the same data a
-second time.  For the chunk types that are being converted it adds the
-soft filter instead, so the resume does not convert again the block
-groups the interrupted balance converted, but it also skips the ones
-that already had the target profile when the balance started, which the
-original request selected.
-
-Replace it with a bound fixed when the balance starts.  Before the
-balance item is written, limit the vrange filter of each chunk type to
-the addresses below the next chunk to be allocated: add a 0..end range
-when the request had no vrange filter, or lower the end of the one it
-had.  Every block group that existed when the balance started stays
-selected until the balance relocates it.
-
-New chunks are allocated after the last chunk, but relocation can remove
-the highest chunks without allocating any (their data fits in free space
-lower down), and the next chunk would then reuse their addresses, below
-the bound.  A resumed balance would select it again, although the
-interrupted one, walking downward, never would have.  So while a balance
-item exists, find_next_chunk() never returns an address below the bound:
-an in-memory floor, set when the balance starts and when the balance
-item is recovered at mount, and cleared when the item is deleted.  Every
-chunk allocated in that time, relocation targets included, stays outside
-the range, on the first run and after a resume.  The gap the floor can
-leave in the logical address space is harmless.
-
-A resume now uses the arguments exactly as they were stored: the bound
-already keeps out every block group the interrupted balance created,
-converted ones included, so neither the usage filter nor the soft filter
-is needed, and update_balance_args() goes away.
-
-The bound does not move as the balance progresses.  Block groups the
-balance has relocated are gone, so on resume the walk only revisits the
-chunks it left in place above the point where it stopped (filtered out,
-ENOSPC, active swapfile) and checks them against the filters again.
-Nothing is skipped.
-
-Because the bound is written with the balance item and never changes,
-there is no progress to persist: a resume after an unmount or a crash
-needs no extra writes.
-
-A balance item recovered at mount is limited in the same way before the
-floor is set from it: a vrange 0..end is added to each chunk type that
-has none, and a vrange that ends above the next chunk is lowered to it.
-That covers items written by older kernels, which have no vrange or a
-vrange the user gave, which can end anywhere (a 1 TiB end would put
-every new chunk at 1 TiB and above).  A bound written by this kernel
-changes only when relocation removed the highest chunks and allocated
-none above it; no chunk exists between the next chunk and the old end,
-so lowering it drops nothing.  When the recovered arguments change,
-they are written back to the balance item once, when the balance
-resumes, so a resume that is interrupted again resumes with the same
-bound and not with a new one that includes the chunks the first resume
-allocated.
-
-A balance item written by an older kernel therefore resumes with the
-bound and without the usage or soft filter: the resumed balance restarts
-from the beginning, relocating again every block group the request
-selects, including the ones the interrupted run created or converted,
-but it skips none.
-
-The bound is visible: `btrfs balance status -v`, the
-BTRFS_IOC_BALANCE_PROGRESS ioctl and the "balance: start" and "balance:
-resume" log lines show a vrange the user did not give.
-
----
- fs/btrfs/fs.h      |   6 ++
- fs/btrfs/volumes.c | 178 ++++++++++++++++++++++++++++++++-------------
- fs/btrfs/volumes.h |   6 ++
- 3 files changed, 140 insertions(+), 50 deletions(-)
-
-diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
-index 2dd167c32d612..a42aa4de2bcc6 100644
---- a/fs/btrfs/fs.h
-+++ b/fs/btrfs/fs.h
-@@ -785,6 +785,12 @@ struct btrfs_fs_info {
-       atomic_t balance_cancel_req;
-       struct btrfs_balance_control *balance_ctl;
-       wait_queue_head_t balance_wait_q;
-+      /*
-+       * 0, or the end of the balance's vrange bound: while a balance item
-+       * exists (running or paused) find_next_chunk() allocates at or above
-+       * it, so the balance never selects a chunk it allocated.
-+       */
-+      u64 balance_chunk_floor;
- 
-       /* Cancellation requests for chunk relocation */
-       atomic_t reloc_cancel_req;
-diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 788f60910acf5..9251087396828 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)
-       }
-       read_unlock(&fs_info->mapping_tree_lock);
- 
--      return ret;
-+      return max(ret, READ_ONCE(fs_info->balance_chunk_floor));
- }
- 
- static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
-@@ -3970,13 +3970,27 @@ static void btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
-       disk->stripes_max = cpu_to_le32(cpu->stripes_max);
- }
- 
-+static void set_balance_item(struct extent_buffer *leaf,
-+                           struct btrfs_balance_item *item,
-+                           const struct btrfs_balance_control *bctl)
-+{
-+      struct btrfs_disk_balance_args disk_bargs;
-+
-+      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
-+      btrfs_set_balance_data(leaf, item, &disk_bargs);
-+      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
-+      btrfs_set_balance_meta(leaf, item, &disk_bargs);
-+      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
-+      btrfs_set_balance_sys(leaf, item, &disk_bargs);
-+      btrfs_set_balance_flags(leaf, item, bctl->flags & ~BTRFS_BALANCE_RESUME);
-+}
-+
- static int insert_balance_item(struct btrfs_fs_info *fs_info,
-                              struct btrfs_balance_control *bctl)
- {
-       struct btrfs_root *root = fs_info->tree_root;
-       struct btrfs_trans_handle *trans;
-       struct btrfs_balance_item *item;
--      struct btrfs_disk_balance_args disk_bargs;
-       struct btrfs_path *path;
-       struct extent_buffer *leaf;
-       struct btrfs_key key;
-@@ -4005,14 +4019,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
-       item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
- 
-       memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item));
--
--      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
--      btrfs_set_balance_data(leaf, item, &disk_bargs);
--      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
--      btrfs_set_balance_meta(leaf, item, &disk_bargs);
--      btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
--      btrfs_set_balance_sys(leaf, item, &disk_bargs);
--      btrfs_set_balance_flags(leaf, item, bctl->flags);
-+      set_balance_item(leaf, item, bctl);
- out:
-       btrfs_free_path(path);
-       if (ret == 0)
-@@ -4023,6 +4030,43 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
-       return ret;
- }
- 
-+/* Write the arguments of a resumed balance to its existing item. */
-+static int update_balance_item(struct btrfs_fs_info *fs_info,
-+                             const struct btrfs_balance_control *bctl)
-+{
-+      struct btrfs_root *root = fs_info->tree_root;
-+      struct btrfs_trans_handle *trans;
-+      BTRFS_PATH_AUTO_FREE(path);
-+      struct btrfs_key key;
-+      int ret;
-+
-+      path = btrfs_alloc_path();
-+      if (!path)
-+              return -ENOMEM;
-+
-+      trans = btrfs_start_transaction(root, 0);
-+      if (IS_ERR(trans))
-+              return PTR_ERR(trans);
-+
-+      key.objectid = BTRFS_BALANCE_OBJECTID;
-+      key.type = BTRFS_TEMPORARY_ITEM_KEY;
-+      key.offset = 0;
-+
-+      ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
-+      if (ret > 0)
-+              ret = -ENOENT;
-+      if (ret < 0) {
-+              btrfs_end_transaction(trans);
-+              return ret;
-+      }
-+
-+      set_balance_item(path->nodes[0],
-+                       btrfs_item_ptr(path->nodes[0], path->slots[0],
-+                                      struct btrfs_balance_item), bctl);
-+      btrfs_release_path(path);
-+      return btrfs_commit_transaction(trans);
-+}
-+
- static int del_balance_item(struct btrfs_fs_info *fs_info)
- {
-       struct btrfs_root *root = fs_info->tree_root;
-@@ -4064,47 +4108,61 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
-       return ret;
- }
- 
-+static bool limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
-+{
-+      if (!(bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)) {
-+              bargs->flags |= BTRFS_BALANCE_ARGS_VRANGE;
-+              bargs->vstart = 0;
-+              bargs->vend = end;
-+              return true;
-+      }
-+      if (bargs->vend <= end)
-+              return false;
-+      bargs->vend = end;
-+      return true;
-+}
-+
- /*
-- * This is a heuristic used to reduce the number of chunks balanced on
-- * resume after balance was interrupted.
-+ * Limit the request to the chunks that exist now.  The bound is written with
-+ * the balance item and never moves, so there is no progress to persist.  New
-+ * chunks are allocated after the last chunk, but once relocation has removed
-+ * the highest chunks the last chunk is lower than the bound, so while the
-+ * balance item exists find_next_chunk() also observes balance_chunk_floor:
-+ * every chunk allocated in that time, relocation targets included, stays
-+ * outside the range, on this run and after a resume.
-+ *
-+ * Return true if any of the arguments changed.
-  */
--static void update_balance_args(struct btrfs_balance_control *bctl)
-+static bool limit_balance_to_existing_chunks(struct btrfs_fs_info *fs_info,
-+                                           struct btrfs_balance_control *bctl)
- {
--      /*
--       * Turn on soft mode for chunk types that were being converted.
--       */
--      if (bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)
--              bctl->data.flags |= BTRFS_BALANCE_ARGS_SOFT;
--      if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)
--              bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
--      if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
--              bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
-+      const u64 end = find_next_chunk(fs_info);
-+      bool changed = false;
- 
--      /*
--       * Turn on usage filter if is not already used.  The idea is
--       * that chunks that we have already balanced should be
--       * reasonably full.  Don't do it for chunks that are being
--       * converted - that will keep us from relocating unconverted
--       * (albeit full) chunks.
--       */
--      if (!(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE) &&
--          !(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
--          !(bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
--              bctl->data.flags |= BTRFS_BALANCE_ARGS_USAGE;
--              bctl->data.usage = 90;
--      }
--      if (!(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE) &&
--          !(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
--          !(bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
--              bctl->sys.flags |= BTRFS_BALANCE_ARGS_USAGE;
--              bctl->sys.usage = 90;
--      }
--      if (!(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE) &&
--          !(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
--          !(bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
--              bctl->meta.flags |= BTRFS_BALANCE_ARGS_USAGE;
--              bctl->meta.usage = 90;
--      }
-+      if (bctl->flags & BTRFS_BALANCE_DATA)
-+              changed |= limit_balance_vrange(&bctl->data, end);
-+      if (bctl->flags & BTRFS_BALANCE_METADATA)
-+              changed |= limit_balance_vrange(&bctl->meta, end);
-+      if (bctl->flags & BTRFS_BALANCE_SYSTEM)
-+              changed |= limit_balance_vrange(&bctl->sys, end);
-+      return changed;
-+}
-+
-+/* The highest vrange end of the selected chunk types, 0 if none has one. */
-+static u64 balance_chunk_floor(const struct btrfs_balance_control *bctl)
-+{
-+      u64 floor = 0;
-+
-+      if ((bctl->flags & BTRFS_BALANCE_DATA) &&
-+          (bctl->data.flags & BTRFS_BALANCE_ARGS_VRANGE))
-+              floor = max(floor, bctl->data.vend);
-+      if ((bctl->flags & BTRFS_BALANCE_METADATA) &&
-+          (bctl->meta.flags & BTRFS_BALANCE_ARGS_VRANGE))
-+              floor = max(floor, bctl->meta.vend);
-+      if ((bctl->flags & BTRFS_BALANCE_SYSTEM) &&
-+          (bctl->sys.flags & BTRFS_BALANCE_ARGS_VRANGE))
-+              floor = max(floor, bctl->sys.vend);
-+      return floor;
- }
- 
- /*
-@@ -4123,6 +4181,7 @@ static void reset_balance_state(struct btrfs_fs_info *fs_info)
- 
-       kfree(bctl);
-       ret = del_balance_item(fs_info);
-+      WRITE_ONCE(fs_info->balance_chunk_floor, 0);
-       if (ret)
-               btrfs_handle_fs_error(fs_info, ret, NULL);
- }
-@@ -5088,6 +5147,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
-                               btrfs_bg_type_to_raid_name(data_target));
-       }
- 
-+      if (!(bctl->flags & BTRFS_BALANCE_RESUME))
-+              limit_balance_to_existing_chunks(fs_info, bctl);
-+
-       ret = insert_balance_item(fs_info, bctl);
-       if (ret && ret != -EEXIST)
-               goto out;
-@@ -5098,11 +5160,16 @@ 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);
-+              WRITE_ONCE(fs_info->balance_chunk_floor,
-+                         balance_chunk_floor(bctl));
-       } else {
-               BUG_ON(ret != -EEXIST);
--              spin_lock(&fs_info->balance_lock);
--              update_balance_args(bctl);
--              spin_unlock(&fs_info->balance_lock);
-+              if (bctl->update_item) {
-+                      ret = update_balance_item(fs_info, bctl);
-+                      if (ret)
-+                              goto out;
-+                      bctl->update_item = false;
-+              }
-       }
- 
-       ASSERT(!test_bit(BTRFS_FS_BALANCE_RUNNING, &fs_info->flags));
-@@ -5255,6 +5322,17 @@ 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);
- 
-+      /*
-+       * Bound the request as a new balance would be: an item written by an
-+       * older kernel has no vrange, and one a user gave to such a kernel can
-+       * end anywhere.  The floor is still 0, so find_next_chunk() returns the
-+       * end of the last chunk, and lowering a vend above it drops no block
-+       * group from the range.  The bound is written back to the item when
-+       * the balance resumes, so a resume that is interrupted again keeps it.
-+       */
-+      bctl->update_item = limit_balance_to_existing_chunks(fs_info, bctl);
-+      WRITE_ONCE(fs_info->balance_chunk_floor, balance_chunk_floor(bctl));
-+
-       /*
-        * This should never happen, as the paused balance state is recovered
-        * during mount without any chance of other exclusive ops to collide.
-diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 891bc2432870a..e7112257014e8 100644
---- a/fs/btrfs/volumes.h
-+++ b/fs/btrfs/volumes.h
-@@ -665,6 +665,12 @@ struct btrfs_balance_control {
- 
-       u64 flags;
- 
-+      /*
-+       * The arguments recovered at mount were bounded and differ from the
-+       * balance item: write them back when the balance resumes.
-+       */
-+      bool update_item;
-+
-       struct btrfs_balance_progress stat;
- };
- 
--- 
-2.47.3
-
diff --git a/topics/balance-resume/0002-btrfs-write-the-remaining-balance-limits-back-to-the.patch b/topics/balance-resume/0002-btrfs-write-the-remaining-balance-limits-back-to-the.patch
new file mode 100644 (file)
index 0000000..1df0714
--- /dev/null
@@ -0,0 +1,158 @@
+From b7304f376da97b2bfd6b0b9646226e9926eba81f Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Sun, 8 Nov 2026 22:24:56 -0500
+Subject: [PATCH 2/3] btrfs: write the remaining balance limits back to the
+ balance item
+To: linux-btrfs@vger.kernel.org
+
+The limit filters are counted down in memory: should_balance_chunk()
+decrements limit, or limit_max of a limit_min..limit_max range, for every
+chunk that passes the other filters, and __btrfs_balance() restores them
+after its counting pass.  A balance resumed after a pause continues with
+what is left.  The balance item is never updated, so a balance resumed
+after an unmount or a crash starts again from the limits that were given:
+every resume can relocate up to limit more chunks.  The minimum shifts
+too: the counting pass of the resume sees only the chunks that are left,
+which can be fewer than limit_min, and the resume then relocates nothing.
+
+Count a chunk against both ends of the range, and write the remaining
+limits to the balance item, once the chunk has been processed.  limit and
+limit_max are still decremented when the chunk is selected, as before,
+and limit_min is now decremented (down to 0) when it has been processed,
+after the limit_min check has let it through, so limit_min means the
+remaining minimum, on disk and in memory.  A resume after an unmount or a
+crash then continues from the remaining limits, like a resume after a
+pause, and its limit_min check compares the chunks that are left with the
+minimum that is left.  The values written are those of the real pass:
+the counting pass returns to the loop before any chunk is processed, and
+its decrements are undone before the real pass starts.
+
+A chunk counts as processed when its relocation has returned for that
+chunk: relocated, or left in place by ENOSPC or an active swapfile.  This
+is what the in-memory limit has always counted, so a resume after an
+unmount or a crash now behaves exactly like a resume after a pause.  A
+pause cannot stop a chunk halfway: the pause request is checked between
+chunks, so the chunk being relocated is processed and written first.  A
+cancel or a fatal signal can stop a relocation, but it also ends the
+balance and deletes the item.  If the item cannot be written, the balance
+stops with the error, like any other error in the loop, and its item is
+deleted; if the item survives that (an aborted transaction), it holds
+the last committed limits, within the bound below.
+
+The update takes its own handle on the running transaction once the
+relocation has returned, and ends it without committing.  The
+transaction that removed the relocated chunk has ended by then, and is
+usually still the running one, so both changes usually commit together,
+and the update can never commit before the removal.  A crash in between
+loses the count of that one chunk, and the resumed balance can relocate
+one chunk more than requested, never one fewer.  Making the update part
+of the removal's transaction would mean passing the balance into
+btrfs_relocate_chunk(), which device shrink and removal also use.
+
+Only chunk types with a limit filter write the item, once per processed
+chunk; a balance without limits makes no more writes than before.  The
+remaining limits are visible: the BTRFS_IOC_BALANCE_PROGRESS ioctl
+already returned them during the balance and now returns the same values
+after a remount, and the "balance: resume" log line shows them.
+
+---
+ fs/btrfs/volumes.c | 54 +++++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 51 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index 74f7e96ceb9e0..7878a8b926266 100644
+--- a/fs/btrfs/volumes.c
++++ b/fs/btrfs/volumes.c
+@@ -4030,9 +4030,13 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+       return ret;
+ }
+ 
+-/* Write the arguments of a resumed balance to its existing item. */
++/*
++ * Write the arguments of a balance to its existing item.  With @commit false
++ * the update joins the running transaction and is committed with it.
++ */
+ static int update_balance_item(struct btrfs_fs_info *fs_info,
+-                             const struct btrfs_balance_control *bctl)
++                             const struct btrfs_balance_control *bctl,
++                             bool commit)
+ {
+       struct btrfs_root *root = fs_info->tree_root;
+       struct btrfs_trans_handle *trans;
+@@ -4064,6 +4068,8 @@ static int update_balance_item(struct btrfs_fs_info *fs_info,
+                        btrfs_item_ptr(path->nodes[0], path->slots[0],
+                                       struct btrfs_balance_item), bctl);
+       btrfs_release_path(path);
++      if (!commit)
++              return btrfs_end_transaction(trans);
+       return btrfs_commit_transaction(trans);
+ }
+ 
+@@ -4470,6 +4476,44 @@ static int should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *
+       return true;
+ }
+ 
++/*
++ * The limit filters count a chunk when should_balance_chunk() selects it, so
++ * it counts whether its relocation succeeds or leaves it in place (ENOSPC, an
++ * active swapfile).  Once the chunk has been processed, count it against
++ * limit_min as well, and write the remaining limits to the balance item, so a
++ * balance resumed after an unmount or a crash processes only what is left of
++ * the request, as one resumed after a pause does.  Chunk types without a limit
++ * filter write nothing.
++ */
++static int count_limited_chunk(struct btrfs_fs_info *fs_info, u64 chunk_type)
++{
++      struct btrfs_balance_control *bctl = fs_info->balance_ctl;
++      struct btrfs_balance_args *bargs;
++
++      if (chunk_type & BTRFS_BLOCK_GROUP_DATA)
++              bargs = &bctl->data;
++      else if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM)
++              bargs = &bctl->sys;
++      else
++              bargs = &bctl->meta;
++
++      if (!(bargs->flags & BTRFS_BALANCE_ARGS_LIMIT)) {
++              if (!(bargs->flags & BTRFS_BALANCE_ARGS_LIMIT_RANGE))
++                      return 0;
++              if (bargs->limit_min > 0)
++                      bargs->limit_min--;
++      }
++
++      /*
++       * A relocated chunk was removed in a transaction that has ended but
++       * may not have committed.  The update usually joins that transaction
++       * and never lands in an earlier one, so a crash can lose the count of
++       * the last relocated chunk, and the resumed balance can then relocate
++       * one chunk more than requested, but never one fewer.
++       */
++      return update_balance_item(fs_info, bctl, false);
++}
++
+ struct remap_chunk_info {
+       struct list_head list;
+       u64 offset;
+@@ -4790,6 +4834,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
+                       bctl->stat.completed++;
+                       spin_unlock(&fs_info->balance_lock);
+               }
++
++              ret = count_limited_chunk(fs_info, chunk_type);
++              if (ret)
++                      goto error;
+ loop:
+               if (found_key.offset == 0)
+                       break;
+@@ -5163,7 +5211,7 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
+                        * for the other errors here, the balance ends and its
+                        * item is deleted.
+                        */
+-                      ret = update_balance_item(fs_info, bctl);
++                      ret = update_balance_item(fs_info, bctl, true);
+                       if (ret) {
+                               btrfs_err(fs_info,
+                       "balance: failed to write the bounded balance item: %d",
+-- 
+2.47.3
+
index 45f317457b8e576ad4611d39236d107bf79e7b6d..803da8665574c09299cc68549f5a396211448ec1 100644 (file)
@@ -1,4 +1,4 @@
-From e38f7c20705d1ff55bd3ed96b2e3c83650037984 Mon Sep 17 00:00:00 2001
+From 968195f996534fe154954da3246b2b2a3920a653 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 old resume filters for balance items
@@ -38,10 +38,10 @@ work but skips nothing.
  1 file changed, 37 insertions(+)
 
 diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 9251087396828..baf824b1d72a3 100644
+index 7878a8b926266..4f8b780992e22 100644
 --- a/fs/btrfs/volumes.c
 +++ b/fs/btrfs/volumes.c
-@@ -4108,6 +4108,41 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
+@@ -4114,6 +4114,41 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
        return ret;
  }
  
@@ -83,7 +83,7 @@ index 9251087396828..baf824b1d72a3 100644
  static bool limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
  {
        if (!(bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)) {
-@@ -5329,7 +5364,9 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
+@@ -5379,7 +5414,9 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
         * end of the last chunk, and lowering a vend above it drops no block
         * group from the range.  The bound is written back to the item when
         * the balance resumes, so a resume that is interrupted again keeps it.
index 47b092205a8b7e8b73c45072c97658bc1b4b645d..360bf6d6833e792b9c54950ebab2444187b9cd9b 100644 (file)
@@ -1,6 +1,6 @@
 # Testing: balance-resume
 
-Patch 2 replaces the usage=90 filter that a resumed balance used to add
+Patch 1 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
@@ -8,13 +8,13 @@ allocated below the bound while a balance item exists.  Patch 3
 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 2 removes
+we should not make any other changes") patch 1 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 1 frees the METADATA_REMAP chunks queued on
-`__btrfs_balance()`'s local list when the walk bails out (pause, cancel,
-errors).  To verify: a paused and resumed balance must relocate exactly
+chunks below the bound that had the target profile at start.  Patch 2
+(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,
 including the >= 90% full ones that usage=90 would skip, and never a
 chunk the interrupted run created; a legacy item must resume with
@@ -23,8 +23,14 @@ 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.
+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.
 
 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
@@ -44,9 +50,9 @@ is that vmlinux's GNU build ID, not a commit.
 
 | test | verifies | patch(es) | duration | last result | date | kernel | harness | evidence |
 |---|---|---|---|---|---|---|---|---|
-| `balance-resume-test.sh` | resume relocates exactly the chunks below the bound, full ones included, each once; bound persists across unmount | 2 | 75 s | PASS: bound 0..6464471040 read from status and from the on-disk item; resume relocated 5 data bgs (2 of them full), none twice, nothing at or above the bound | 2026-10-18 | misc-next zb64 568c45b64012 (#5) | 1e003fbac1ba | dhive `logs/balance-resume-test-20261018-041806` |
-| `balance-resume-reuse-test.sh` | the chunk-allocation floor: chunks allocated after the top chunk is emptied start at or above the bound and are not relocated again | 2 | 81 s | PASS: C (12% full) at 4316987392, bound 5390729216; both chunks the interrupted run allocated start at or above the bound and were not relocated on resume; the 3 pre-existing chunks below the bound relocated once each | 2026-10-18 | misc-next zb64 568c45b64012 (#5) | 1e003fbac1ba | dhive `logs/balance-resume-reuse-test-20261018-041921` |
-| `remap-balance-resume-test.sh` | a METADATA_REMAP chunk queued above slow data chunks stays inside the resumed range and is emptied | 2 (and the remap path patch 1 touches) | 121 s | PASS: R' at 6472859648 below D_top 6506414080, 7 data chunks below R'; metadata bound 0..7580155904 stays above R' across the pause and unmount; R' emptied by the resumed run (exp progs `/usr/local/btrfs-progs-exp/bin`) | 2026-10-18 | misc-next #5 | 1e003fbac1ba | dhive `logs/remap-balance-resume-test-20261018-042042` |
+| `balance-resume-test.sh` | resume relocates exactly the chunks below the bound, full ones included, each once; bound persists across unmount | 1 | 75 s | PASS: bound 0..6464471040 read from status and from the on-disk item; resume relocated 5 data bgs (2 of them full), none twice, nothing at or above the bound | 2026-10-18 | misc-next zb64 568c45b64012 (#5) | 1e003fbac1ba | dhive `logs/balance-resume-test-20261018-041806` |
+| `balance-resume-reuse-test.sh` | the chunk-allocation floor: chunks allocated after the top chunk is emptied start at or above the bound and are not relocated again | 1 | 81 s | PASS: C (12% full) at 4316987392, bound 5390729216; both chunks the interrupted run allocated start at or above the bound and were not relocated on resume; the 3 pre-existing chunks below the bound relocated once each | 2026-10-18 | misc-next zb64 568c45b64012 (#5) | 1e003fbac1ba | dhive `logs/balance-resume-reuse-test-20261018-041921` |
+| `remap-balance-resume-test.sh` | a METADATA_REMAP chunk queued above slow data chunks stays inside the resumed range and is emptied | 1 (and the remap-chunk queue that `remap-balance-leak` frees) | 121 s | PASS: R' at 6472859648 below D_top 6506414080, 7 data chunks below R'; metadata bound 0..7580155904 stays above R' across the pause and unmount; R' emptied by the resumed run (exp progs `/usr/local/btrfs-progs-exp/bin`) | 2026-10-18 | misc-next #5 | 1e003fbac1ba | dhive `logs/remap-balance-resume-test-20261018-042042` |
 | `balance-resume-legacy-test.sh prepare\|check` | an item written by a pre-vrange kernel resumes with usage=90 and no vrange; a new balance gets the vrange | 3 | prepare 1 min on stock 6.12, check 60 s on #5, plus two reboots | PASS: item paused by stock Debian 6.12.90 (2 of ~7 chunks done); on #5 "balance: resume -dusage=90" with no vrange, and a new balance logged "balance: start -dvrange=0..11833180160" | 2026-10-18 | prepare: Debian 6.12.90+deb13.1; check: misc-next #5 | 1e003fbac1ba + later (test unchanged since 61c23a8) | dhive `logs/legacy-prepare-6.12-20261018-055706`, `logs/legacy-check-mn5-20261018-061525` |
 
 Previous results recorded before this round:
@@ -76,7 +82,7 @@ bound read back from `btrfs balance status -v` and again from the on-disk
 balance item after an unmount and a `skip_balance` mount; then resume.  The
 set of block groups relocated on resume must be exactly the data chunks
 below the bound at the pause, each once, the full ones included, with no
-usage= filter in the args.  It covers the core claim of patch 2 (nothing
+usage= filter in the args.  It covers the core claim of patch 1 (nothing
 skipped, nothing redone).  Limits: whether a full chunk lands below the
 bound depends on the allocator's layout; when none does, the test says the
 coverage was not reached instead of failing.  It does not exercise
@@ -100,7 +106,7 @@ METADATA_REMAP chunk is placed above slow data chunks, a full -d -m balance
 is paused after the walk has passed it, the fs is unmounted and the balance
 resumed; the remap chunk must be inside the resumed range and emptied.
 This was review finding 1 of the bound design.  It runs the remap-chunk
-queue that patch 1 frees, but it does not check for the leak: nothing in
+queue that `remap-balance-leak` frees, but it does not check for the leak: nothing in
 it can see an unfreed `remap_chunk_info`.
 
 **balance-resume-legacy-test.sh.**  `prepare` runs on a kernel without
@@ -112,36 +118,8 @@ the old kernel and back, so it is not in the directed list.
 
 ## New tests
 
-| test | verifies | patch(es) | duration | last result | date | kernel | harness | evidence |
-|---|---|---|---|---|---|---|---|---|
-| `remap-balance-leak-test.sh` | every queued `remap_chunk_info` is freed, including when the walk bails out at a pause | 1 | 171 s | PASS: 4 entries allocated in btrfs_balance, 4 freed; the paused walk's entry was freed from its own call site (btrfs_balance+0x1a26), the completed walks' from balance_remap_chunks (+0x4119) | 2026-10-18 | misc-next #5 | 0a72db0 | dhive `logs/remap-balance-leak-test-20261018-042918`, trace in `ev/remap-leak-1/trace.txt` |
-| `remap-balance-leak-test.sh` (negative control, `LEAK_ONLY=1`) | the same, on the base without the series | 1 | 172 s | FAIL as expected: 3 allocated, 1 unfreed (the paused walk's) | 2026-10-18 | misc-next base 0c48d26d46bd, dhive KASAN build 1 | 27b253a | dhive `logs/neg-remap-balance-leak-test-20261018-055959` |
-
-**remap-balance-leak-test.sh.**  The test kernels have no kmemleak, so the
-test watches the allocations: a private tracefs instance records
-kmem:kmalloc events of 40 bytes (sizeof(struct remap_chunk_info)) whose
-call site is in btrfs_balance (`__btrfs_balance()` and
-`balance_remap_chunks()` are inlined into it) and every kmem:kfree called
-from btrfs_balance, while `remap-balance-resume-test.sh` runs.  That test
-pauses a full balance after the walk has queued a METADATA_REMAP chunk --
-the bail-out that leaked -- then remounts and resumes.  PASS needs the remap
-test to PASS (so the paused walk did queue the chunk), at least two
-allocations (the remap chunk move before the balance, and the paused walk),
-and a matching kfree for every allocation.  Unfixed, the paused walk's entry
-is never freed.  On #5 the paused walk's entry was freed from a different
-offset in btrfs_balance than the entries of the completed walks, which is
-the new free at the error label.  **Shown to fail without the patch**: on
-the misc-next base 0c48d26d46bd (no topics; KASAN build of #5's config,
-dhive build 1, 2026-10-18), with `LEAK_ONLY=1` (the remap test is told to
-pause even without the vrange bound and its resume verdict is ignored), 3
-entries were allocated and 1 was never freed (allocated at
-btrfs_balance+0x2345, the paused walk's queue), and the remap chunk survived
-the resume, as expected without patch 2
-(`logs/neg-remap-balance-leak-test-20261018-055959`).  Limits: only the pause bail-out is driven, not
-cancel or the error exits (they share the error label); it depends on the
-inlining of both functions into btrfs_balance (a different inlining
-changes the call-site filter and the test then fails as blind with fewer
-than 2 allocations).
+`remap-balance-leak-test.sh`, the leak test of the former patch 1, and its
+negative control moved to `topics/remap-balance-leak/TESTING.md`.
 
 ## 2026-11-05 round (br1105: no resume changes when a vrange is present)
 
@@ -158,14 +136,14 @@ served the control and the candidate.  Evidence:
 
 | test | verifies | patch(es) | duration | result | kernel |
 |---|---|---|---|---|---|
-| `balance-resume-convert-test.sh` (new) | a paused `-dconvert=dup` resumes with convert + the stored bound and no soft; every chunk below the bound is relocated once, including the one that already had the dup profile at start; none of the chunks the interrupted run converted (at or above the bound) is relocated again; all data dup at the end | 2 (and 3: the vrange check gates soft) | 2 min | PASS x2 each on 6.18 #318 bhive, #318 ahive, misc-next #67 dhive, #67 ehive: "balance: resume -dconvert=dup,vrange=0..12110004224", 4 chunks below the bound relocated (dup 298844160 among them), the 2 converted chunks at 12110004224 and 13183746048 untouched | #318, #67 |
+| `balance-resume-convert-test.sh` (new) | a paused `-dconvert=dup` resumes with convert + the stored bound and no soft; every chunk below the bound is relocated once, including the one that already had the dup profile at start; none of the chunks the interrupted run converted (at or above the bound) is relocated again; all data dup at the end | 1 (and 3: the vrange check gates soft) | 2 min | PASS x2 each on 6.18 #318 bhive, #318 ahive, misc-next #67 dhive, #67 ehive: "balance: resume -dconvert=dup,vrange=0..12110004224", 4 chunks below the bound relocated (dup 298844160 among them), the 2 converted chunks at 12110004224 and 13183746048 untouched | #318, #67 |
 | same, negative control | the detector sees the old behavior | - | 2 min | FAIL as expected on 6.18 #317 (bhive), #316 (ahive) and misc-next #66 (dhive): "balance: resume -dconvert=dup,soft,vrange=0..12110004224", and the dup chunk 298844160 below the bound was not relocated; every other assertion PASS | #317, #316, #66 |
 | `balance-resume-legacy-test.sh check plain` | legacy item: usage=90, no soft, no vrange | 3 | 1 min | PASS on #318 (ahive) and #67 (ehive); also PASS on #316 and #66 | #318, #67 |
 | `... check convert` (new variant) | legacy `-dconvert=dup` item: soft, no usage, no vrange | 3 | 1 min | PASS on #318 and #67 ("-dconvert=dup,soft"); also PASS on #316 and #66 | #318, #67 |
 | `... check vrange` (new variant) | legacy item with a user-given vrange=0..1099511627776: resumed unchanged (no usage, no soft) | 3 | 1 min | PASS on #318 and #67; also PASS on #316 and #66 (the old patch 3 already gated usage=90 on the vrange) | #318, #67 |
 | `... check convert-vrange` (new variant) | legacy `-dconvert=dup,vrange=0..1099511627776` item: no soft, no usage | 3 | 1 min | PASS on #318 and #67 ("-dconvert=dup,vrange=0..1099511627776"); **FAIL as expected on #316 and #66** ("-dconvert=dup,soft,vrange=...") | #318, #67 |
-| `balance-resume-test.sh`, `balance-resume-reuse-test.sh` | as above | 2 | 1 min each | PASS on #318 (bhive, ahive) and #67 (dhive, ehive) | #318, #67 |
-| `remap-balance-resume-test.sh`, `remap-balance-leak-test.sh` | as above | 1, 2 | 2 min each | PASS on #67 (dhive, ehive); SKIP on 6.18 (no remap tree: the kernel cannot mount the fs), as expected | #67 |
+| `balance-resume-test.sh`, `balance-resume-reuse-test.sh` | as above | 1 | 1 min each | PASS on #318 (bhive, ahive) and #67 (dhive, ehive) | #318, #67 |
+| `remap-balance-resume-test.sh` (`remap-balance-leak-test.sh`: see `topics/remap-balance-leak`) | as above | 1 | 2 min each | PASS on #67 (dhive, ehive); SKIP on 6.18 (no remap tree: the kernel cannot mount the fs), as expected | #67 |
 
 Observation (not gated): the legacy vrange items resume with the
 chunk-allocation floor at the stored vend, so the resumed run allocates
@@ -179,7 +157,7 @@ Fixed in the 2026-11-06 round below.
 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
+kernels resume the balance if it is interrupted again".  Patch 1 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
@@ -203,7 +181,7 @@ pause and the 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:
+2bd866e69d3020906566b9d5fdb52bf5) on dhive and ehive.  Patch 1 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
@@ -224,16 +202,16 @@ below E is relocated; a new balance gets a vrange.  New variant
 
 | 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 |
+| `balance-resume-legacy-test.sh check plain` | legacy plain item: bounded at mount, usage=90, bound persisted across a second interruption | 1, 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 | 1, 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 | 1 | 1 min | PASS on all four (bhive "-dvrange=0..9685696512") | #319, #68 |
+| `... check convert-vrange` | `-dconvert=dup,vrange=0..1 TiB`: lowered, no soft | 1, 3 | 1 min | PASS on all four | #319, #68 |
+| `... check vrange-max` (new) | vrange end U64_MAX lowered to E | 1 | 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 1 alone: bounded and persisted, args otherwise unchanged (no usage, no soft) | 1 | 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 |
-| `vm-scripts/fl1106/nounmount-check.sh` (new, not in the harness) | pause after 3 block groups, `btrfs balance resume` on the same mount: the resume line shows the bound set at start, no chunk the first run allocated (3, at and above the bound) is relocated, every chunk allocated during the balance is at or above the bound, every data chunk below it relocated once | 2 | 1 min | PASS on #319 (bhive) and #68 (dhive): "balance: resume -dvrange=0..11036262400", 11/11 relocated.  Not run on the controls (the floor was already in #318/#67) | #319, #68 |
+| `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) | 1 | 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`: see `topics/remap-balance-leak`) | as above | 1 | 2 min each | PASS on #68 (dhive, ehive) and #67 (dhive); SKIP on 6.18 as expected | #68 |
+| `vm-scripts/fl1106/nounmount-check.sh` (new, not in the harness) | pause after 3 block groups, `btrfs balance resume` on the same mount: the resume line shows the bound set at start, no chunk the first run allocated (3, at and above the bound) is relocated, every chunk allocated during the balance is at or above the bound, every data chunk below it relocated once | 1 | 1 min | PASS on #319 (bhive) and #68 (dhive): "balance: resume -dvrange=0..11036262400", 11/11 relocated.  Not run on the controls (the floor was already in #318/#67) | #319, #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
@@ -458,13 +436,6 @@ FUNCTION_ERROR_INJECTION=y, FAULT_INJECTION not set):
 
 ## Not covered / open
 
-- Patch 1's other bail-outs (cancel, chunk search or relocation errors,
-  a failed allocation of a later entry) share the error label but are not
-  driven.
-- The negative control ran on the base kernel without any topic, not on #5
-  with only patch 1 reverted; the test targets patch 1's code path, but the
-  base differs in more than that patch (it also lacks patch 2, which is why
-  its remap chunk survived the resume).
 - `balance-resume-test.sh` and `balance-resume-reuse-test.sh` were not run
   on the base this round (their earlier negative controls are listed
   above).
index fbebd3177a4f4f8d6bb82738f881baa3824391fc..2b44d840de248129fceebedb62abe8ada96fa3d6 100644 (file)
@@ -1,6 +1,6 @@
 From 464a17c7110ff10889f59c0230001ef8fde4ca92 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:19 -0500
+Date: Mon, 9 Nov 2026 08:41:05 -0500
 Subject: [PATCH 00/11] btrfs: fix and simplify inode flag vs compression interactions
 To: linux-btrfs@vger.kernel.org
 
index f8d665384069ebc6501f5da2c047a6bd43261890..db8fabdaa636ce4bd51243552ef293e93dcbdb47 100644 (file)
@@ -1,6 +1,6 @@
 From a4a830eb6b96cfcf9bc52dc145cf41f4dc927b7a Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:19 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 0/3] btrfs: deadlocks between reflink, relocation and space reservation
 To: linux-btrfs@vger.kernel.org
 
index 56caf04debf2c45ada24d5f6dc3ff544a0b00166..0986f18dc03b2db524c4fd51c24cf67ba7cd5e4f 100644 (file)
@@ -1,6 +1,6 @@
 From 1bfce31eb38de064ba209595df90676627d9d621 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 0/1] btrfs: one dedupe request, one extent reference
 To: linux-btrfs@vger.kernel.org
 
diff --git a/topics/dedupe-mtime/0000-cover-letter.patch b/topics/dedupe-mtime/0000-cover-letter.patch
deleted file mode 100644 (file)
index 705d37d..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-From 5093b6bc045bef47c57792653482019b952e2cce Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:23 -0500
-Subject: [PATCH 0/1] btrfs: keep mtime and ctime when a dedupe ends in a hole
-To: linux-btrfs@vger.kernel.org
-
-This is Ivan Kozik's patch; Ivan's own posting is authoritative.  This
-note only summarizes it and how this copy was tested.
-
-A dedupe whose source range ends in an implicit hole (NO_HOLES, or a
-hole left by mixed buffered and direct IO) drops the destination's file
-extent items under the hole through btrfs_replace_file_extents() with a
-NULL extent_info.  When the destination has its items spread over more
-leaves than the function's temporary reserve covers,
-btrfs_drop_extents() returns -ENOSPC, the function switches transaction
-handles, and since 983d8209c680 it updates mtime and ctime at that point
-unless extent_info says not to, which a NULL extent_info cannot.  The
-result is a deduplication that changes no data but changes the
-destination's mtime and ctime.  The patch passes update_times to
-btrfs_replace_file_extents() as an argument, so the hole case in
-btrfs_clone() honours no_time_update like the extent case.
-
-Testing (KASAN + lockdep): dedupe-mtime-test.sh dedupes a 16 MiB and a
-64 MiB implicit hole over 4096 and 16384 4 KiB extents (21 and 80
-leaves) and a partly written source; mtime and ctime are unchanged,
-while a clone and a hole punch of the same shape still change them, the
-data stays zero and the hole part has no items left.  On the base
-without the patch the 16 MiB, 64 MiB and partly written cases change
-both times.
-
-Ivan Kozik (1):
-  btrfs: don't update mtime and ctime when deduping a range ending in a
-    hole
-
- fs/btrfs/ctree.h   |  2 --
- fs/btrfs/file.c    | 13 ++++++++-----
- fs/btrfs/file.h    |  2 +-
- fs/btrfs/inode.c   |  3 +--
- fs/btrfs/reflink.c |  6 +++---
- 5 files changed, 13 insertions(+), 13 deletions(-)
-
-
--- 
-2.47.3
-
diff --git a/topics/dedupe-mtime/0001-btrfs-don-t-update-mtime-and-ctime-when-deduping-a-r.patch b/topics/dedupe-mtime/0001-btrfs-don-t-update-mtime-and-ctime-when-deduping-a-r.patch
deleted file mode 100644 (file)
index f0f5945..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-From 5093b6bc045bef47c57792653482019b952e2cce 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
- ending in a hole
-To: linux-btrfs@vger.kernel.org
-
-When deduplicating a range whose end is covered by an implicit hole in
-the source file (the NO_HOLES feature is enabled, or the hole resulted
-from mixing buffered and direct IO writes), btrfs_clone() drops the file
-extent items in the corresponding part of the destination range by
-calling btrfs_replace_file_extents() with a NULL extent_info argument.
-
-btrfs_replace_file_extents() uses a temporary block reserve with failfast
-set, sized for a single item insertion. With the default 16K node size
-that covers COWing 16 tree blocks. If the destination range has file
-extent items spread over more leaves than that, for example thousands of
-4K extents within one 16M deduplication chunk, btrfs_drop_extents()
-returns -ENOSPC. btrfs_replace_file_extents() then updates the inode
-item, ends the transaction handle and gets a new one to continue. Since
-commit 983d8209c680 ("btrfs: add missing inode updates on each iteration
-when replacing extents") it also updates mtime and ctime at that point
-unless extent_info->update_times is false, which a caller passing a NULL
-extent_info cannot express. So a deduplication operation changes the
-destination's mtime and ctime, even though it does not change file data
-and btrfs_clone() was called with no_time_update set.
-
-Fix this by removing the update_times field from struct
-btrfs_replace_extent_info and passing it as an argument to
-btrfs_replace_file_extents() instead, so that the implicit hole case in
-btrfs_clone() can pass !no_time_update like the other case does. Also
-update the function's comment, which only mentioned fallocate's hole
-punching as a user of a NULL extent_info.
-
-Fixes: 983d8209c680 ("btrfs: add missing inode updates on each iteration when replacing extents")
-CC: stable@vger.kernel.org # 6.1+
-Assisted-by: Codex:gpt-6-astra
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/ctree.h   |  2 --
- fs/btrfs/file.c    | 13 ++++++++-----
- fs/btrfs/file.h    |  2 +-
- fs/btrfs/inode.c   |  3 +--
- fs/btrfs/reflink.c |  6 +++---
- 5 files changed, 13 insertions(+), 13 deletions(-)
-
-diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
-index 00d4c4184e76a..56d8e36a54fff 100644
---- a/fs/btrfs/ctree.h
-+++ b/fs/btrfs/ctree.h
-@@ -402,8 +402,6 @@ struct btrfs_replace_extent_info {
-        * existing extent into a file range.
-        */
-       bool is_new_extent;
--      /* Indicate if we should update the inode's mtime and ctime. */
--      bool update_times;
-       /* Meaningful only if is_new_extent is true. */
-       int qgroup_reserved;
-       /*
-diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
-index f978c6524aa03..ffe43706248f0 100644
---- a/fs/btrfs/file.c
-+++ b/fs/btrfs/file.c
-@@ -2354,15 +2354,18 @@ static int btrfs_insert_replace_extent(struct btrfs_trans_handle *trans,
- /*
-  * The respective range must have been previously locked, as well as the inode.
-  * The end offset is inclusive (last byte of the range).
-- * @extent_info is NULL for fallocate's hole punching and non-NULL when replacing
-- * the file range with an extent.
-+ * @extent_info is NULL when punching a hole, which happens for fallocate's hole
-+ * punching and when cloning or deduplicating a range that ends in an implicit
-+ * hole, and non-NULL when replacing the file range with an extent.
-  * When not punching a hole, we don't want to end up in a state where we dropped
-  * extents without inserting a new one, so we must abort the transaction to avoid
-  * a corruption.
-+ * @update_times is false when deduplicating, in which case we must not update
-+ * the inode's mtime and ctime if we need to use more than one transaction handle.
-  */
- int btrfs_replace_file_extents(struct btrfs_inode *inode,
-                              struct btrfs_path *path, const u64 start,
--                             const u64 end,
-+                             const u64 end, bool update_times,
-                              struct btrfs_replace_extent_info *extent_info,
-                              struct btrfs_trans_handle **trans_out)
- {
-@@ -2504,7 +2507,7 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,
-                */
-               inode_inc_iversion(&inode->vfs_inode);
- 
--              if (!extent_info || extent_info->update_times)
-+              if (update_times)
-                       inode_set_mtime_to_ts(&inode->vfs_inode,
-                                             inode_set_ctime_current(&inode->vfs_inode));
- 
-@@ -2738,7 +2741,7 @@ static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len)
-       }
- 
-       ret = btrfs_replace_file_extents(BTRFS_I(inode), path, lockstart,
--                                       lockend, NULL, &trans);
-+                                       lockend, true, NULL, &trans);
-       btrfs_free_path(path);
-       if (ret)
-               goto out;
-diff --git a/fs/btrfs/file.h b/fs/btrfs/file.h
-index d7df81388cbee..8fbbae07bc713 100644
---- a/fs/btrfs/file.h
-+++ b/fs/btrfs/file.h
-@@ -28,7 +28,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
-                      struct btrfs_drop_extents_args *args);
- int btrfs_replace_file_extents(struct btrfs_inode *inode,
-                          struct btrfs_path *path, const u64 start,
--                         const u64 end,
-+                         const u64 end, bool update_times,
-                          struct btrfs_replace_extent_info *extent_info,
-                          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 abaa334714566..c8d068a3a858b 100644
---- a/fs/btrfs/inode.c
-+++ b/fs/btrfs/inode.c
-@@ -9132,7 +9132,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.update_times = true;
-       extent_info.qgroup_reserved = qgroup_released;
-       extent_info.insertions = 0;
- 
-@@ -9143,7 +9142,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
-       }
- 
-       ret = btrfs_replace_file_extents(inode, path, file_offset,
--                                   file_offset + len - 1, &extent_info,
-+                                   file_offset + len - 1, true, &extent_info,
-                                    &trans);
-       btrfs_free_path(path);
-       if (ret)
-diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
-index b5d2c094941df..c4f4dfea3fa5b 100644
---- a/fs/btrfs/reflink.c
-+++ b/fs/btrfs/reflink.c
-@@ -556,10 +556,9 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
-                       clone_info.file_offset = new_key.offset;
-                       clone_info.extent_buf = buf;
-                       clone_info.is_new_extent = false;
--                      clone_info.update_times = !no_time_update;
-                       ret = btrfs_replace_file_extents(inode, path,
-                                       drop_start, new_key.offset + datal - 1,
--                                      &clone_info, &trans);
-+                                      !no_time_update, &clone_info, &trans);
-                       if (ret)
-                               goto out;
-               } else {
-@@ -656,7 +655,8 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
-                       btrfs_set_inode_full_sync(inode);
- 
-               ret = btrfs_replace_file_extents(inode, path,
--                              last_dest_end, destoff + len - 1, NULL, &trans);
-+                              last_dest_end, destoff + len - 1,
-+                              !no_time_update, NULL, &trans);
-               if (ret)
-                       goto out;
- 
--- 
-2.47.3
-
diff --git a/topics/dedupe-mtime/TESTING.md b/topics/dedupe-mtime/TESTING.md
deleted file mode 100644 (file)
index 03b00e1..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-# Testing: dedupe-mtime
-
-Ivan Kozik's patch "btrfs: don't update mtime and ctime when deduping a range
-ending in a hole".  Ivan's own posting is authoritative; this file records
-how the misc-next lane's copy was tested.  When the source range of a
-dedupe ends in an implicit hole (NO_HOLES), btrfs_clone() drops the
-destination's file extent items there with btrfs_replace_file_extents(...,
-NULL extent_info).  If that takes more than one transaction handle
-(more destination leaves than its 16-block temporary reserve covers), the
-function set mtime and ctime at every handle switch, because a NULL
-extent_info could not say "keep the times".  A test must dedupe such a range
-over a destination with thousands of small extents and show that mtime and
-ctime are unchanged afterwards (before the fix: both change), while a clone
-and a hole punch of the same shape still change them.
-
-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.
-
-## Existing tests
-
-| test | verifies | patch(es) | duration | last result | date | kernel | harness | evidence |
-|---|---|---|---|---|---|---|---|---|
-| vm-scripts `dhive/dedupe-mtime-repro.sh` (arms few, many, clone) | dedupe of a 16 MiB implicit hole over 4096 x 4K extents keeps mtime/ctime | 1 | < 1 min | PASS x3 on the fix kernel; on the unfixed kernel the "many" arm changed mtime/ctime | 2026-09-30 | proof build dhive #17 = misc-next zb64 + topics/dedupe-mtime (tree == lane `ffe846182612`); 6.18 dhive #100 | vm-scripts 2ffc36f | memory note dedupe-mtime-topic; the repro prints its verdict, no exit status |
-| fstests `-g dedupe` via `fstests-group-test.sh` (single device, default mkfs, fstests b76e57b9) | generic FIDEDUPERANGE / FICLONERANGE regressions (not this symptom) | 1 | 75 min (btrfs/187 47 min on KASAN) | PASS: 18 of 22 ran and passed (btrfs/187, 191, generic/121 122 136 137 158 160 162 163 182 304 374 408 493 516 517 630); not run: generic/559-561 (no duperemove), 674 (no fsgqa user); taint 0 | 2026-10-18 | misc-next zb64 568c45b64012 (bhive #5, fresh boot) | ac9b1c2 | harness `forensics/bhive-topics-testing-20261018/fstests-dedupe.log` |
-
-**dedupe-mtime-repro.sh** (2026-09-30, the import session's proof): a
-NO_HOLES filesystem, the destination written as N x 4 KiB O_DIRECT writes
-(one file extent item each), the source a sparse file of the same size,
-one dedupe call; prints the times before and after.  It was the reproducer
-for the patch, run x3 on each lane's fix build.  Limits: it only prints
-"TIMES CHANGED/UNCHANGED" and does not check the data or the items left; it
-has been superseded by `dedupe-mtime-test.sh` below, which keeps its arms.
-
-**fstests dedupe group.**  Regression check of the dedupe/clone paths on
-plain single-device btrfs (default mkfs, no mount options): every test that
-ran passed, including btrfs/187 (send racing dedupe and balance) and the
-generic dedupe/reflink correctness tests.  None of them checks the item
-count or the times, so they show the patch breaks nothing they cover, not
-that it works.  A first run the same day was contaminated (fstests'
-dmesg check caught aborts from a concurrent test on another loop device,
-and systemd's SIGPIPE handling broke two tests' pipelines); it was rerun
-alone after a reboot.
-
-## New tests
-
-| test | verifies | patch(es) | duration | last result | date | kernel | harness | evidence |
-|---|---|---|---|---|---|---|---|---|
-| `dedupe-mtime-test.sh` (arms few, many, big, mixed, clone, punch) | dedupe keeps mtime/ctime when the source ends in an implicit hole and the drop takes many handles; clone and punch still update | 1 | 1 min | PASS: many (4096 extents, 21 leaves), big (16384 extents, 80 leaves) and mixed keep both times; clone and punch change them; data all zeros, hole part has no items left, btrfs check clean | 2026-10-18 | misc-next zb64 568c45b64012 (bhive #5) | f8199a1 | harness `forensics/bhive-topics-testing-20261018/` |
-| `dedupe-mtime-test.sh`, negative control | the same on a kernel without the patch | - | 1 min | FAIL as expected: many, big and mixed change mtime and ctime (TIMES CHANGED); few unchanged; clone and punch change; data and items as on #5 | 2026-10-18 | misc-next base 0c48d26d46bd (t-bhive build, #5 config; bhive #1) | f8199a1 | harness `forensics/bhive-topics-testing-20261018/base1.log` |
-
-**dedupe-mtime-test.sh.**  Each arm on a fresh 4 GiB NO_HOLES filesystem:
-dst = N x 4 KiB zero extents written O_DIRECT (one item each; the test
-prints how many leaves hold them), src = zeros of the same length (sparse,
-or 1 MiB written then a hole for "mixed").  One FIDEDUPERANGE call; mtime
-and ctime are compared 1.1 s apart.  Oracles: dedupe reports the full
-length; dst size and content (all zeros) unchanged; the hole part has no
-file extent items left (proves the NULL-extent_info path ran); times
-unchanged for few/many/big/mixed, changed for the clone and punch controls
-(the controls show the time comparison detects a change, and that the hole
-punch path, which still passes update_times=true, was not broken).
-Ends with btrfs check and a kernel log scan.  Limits: the >16-leaf regime is
-inferred from the leaf count (21 / 80 leaves), not observed directly (no
-trace of the handle switch); a 16 KiB nodesize only.  Shown to fail without the
-fix: on the misc-next base 0c48d26d46bd the many, big and mixed arms report
-TIMES CHANGED (FAIL 3), the controls behave as on #5.
-
-## Not covered / open
-
-- Other nodesizes (4 KiB nodes reach the multi-handle path with far fewer
-  extents) and the "mixed buffered/direct IO" implicit-hole case mentioned in
-  the commit message (holes without NO_HOLES): not tested.
-- fallocate's preallocation path (insert_prealloc_file_extent, passes true)
-  is exercised by other tests only indirectly.
-
-No questions for Zygo on this topic.
index 59eb0abec69e23859a4280ef90b88c5117a6c259..8a3a1bc1a39170ec6bb468fefdd40386e462d258 100644 (file)
@@ -1,6 +1,6 @@
 From 928af994881cc3904fc6572ec9be509e84d6acab Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 0/1] btrfs: drain pending NOCOW writes before a block group goes read-only
 To: linux-btrfs@vger.kernel.org
 
index d2de8596ba0212452a4af27e65ff23dadac65666..9251aed49904821167a7b8af427ffae631f6860b 100644 (file)
@@ -1,6 +1,6 @@
 From ba3c140a9b37784b18760540abbdf9e6d7a392b0 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 0/2] btrfs: allow setting the system chunk size through sysfs
 To: linux-btrfs@vger.kernel.org
 
index dd548c8fe3e9ef31f5f08a255cbdbf972c7674aa..b1f49b62f0a4c2b05b04ae60338f9dae7261d1b2 100644 (file)
@@ -1,6 +1,6 @@
 From 8b54332c3af675c544b8744e56c02a236319f7a9 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:24 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 0/1] btrfs: persist device stats counted without a transaction
 To: linux-btrfs@vger.kernel.org
 
index b4b608af548fa0c307af773e2512a5153923dc7f..fab6474f89a2ce81726cf017e7244b8ddc79aff7 100644 (file)
@@ -1,6 +1,6 @@
 From 46393acd1f98b9b78a4ca490c822bd4922b38216 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:18 -0500
+Date: Mon, 9 Nov 2026 08:41:04 -0500
 Subject: [PATCH 0/3] btrfs: reducing LOGICAL_INO costs
 To: linux-btrfs@vger.kernel.org
 
index 0b2202073233d4a4bce509f421dc63d73680a791..27f32fdf3313b7e1be614aabbe89c067fb7493e3 100644 (file)
@@ -1,6 +1,6 @@
 From 24ed123c7b4907ccdeb778caa956ea6a5e021bb8 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:23 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 0/3] btrfs: keep room to relocate on a full filesystem
 To: linux-btrfs@vger.kernel.org
 
index 3855a641a1a5eaae50706e7501ca9fa64a91501a..917a573871083de358ac85998931af69357cc10c 100644 (file)
@@ -1,6 +1,6 @@
 From 67df719ccdefbcc38d0f9167a1e42b9318f0ef98 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 0/1] btrfs: limit preallocated extents to 128 MiB
 To: linux-btrfs@vger.kernel.org
 
index 54cac9559c8f8f76d3b4d6c43be99a41e0605ce6..ff13d38ad2bc3860f48caff5911f5baf240bdac2 100644 (file)
@@ -1,6 +1,6 @@
 From 3b022e96c7a88a5ad5c389f756b75ff8d3dcafa5 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 00/10] btrfs: raid56: rbio lifetime and cache fixes, error reporting
 To: linux-btrfs@vger.kernel.org
 
index 9fcd5925524409b167265347e454ab9f79e85fba..006ca587eb0237d11ea5a52612e6c2ca8a9767a9 100644 (file)
@@ -1,6 +1,6 @@
 From 83d98c04f4708f23ff40246812a81a879839b181 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 00/12] btrfs: raid56 scrub and device replace with unrepairable data
 To: linux-btrfs@vger.kernel.org
 
index 370767e20a985a19faf9158410911316610bfb9d..507c1cc8de82b2f0994b50b904a59ef24a39b49d 100644 (file)
@@ -1,6 +1,6 @@
 From fb0dade563cf4400faf384e6478eb40305e775e3 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:23 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 0/9] btrfs: read policies and per-device read stats (Kai Krakow's series)
 To: linux-btrfs@vger.kernel.org
 
index f9a8dbcf85aa1306d879b3538d942405be60dad5..59f371c016031daeb9886f4550cff35637643710 100644 (file)
@@ -1,6 +1,6 @@
 From eed1056fffd707affeac38415f2abe5f8d9f8e12 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:06 -0500
 Subject: [PATCH 0/4] btrfs: read repair and scrub after a transaction abort
 To: linux-btrfs@vger.kernel.org
 
index 85e4a56683cb21b349432debe4376a75d7bd5c7d..52b40af59623e5cd09385ace349d58a575cdbd5f 100644 (file)
@@ -1,6 +1,6 @@
 From 28c07811477669dff1d815cb59e1e1b56f3baa68 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:07 -0500
 Subject: [PATCH 0/3] btrfs: block group reclaim fixes for a full filesystem
 To: linux-btrfs@vger.kernel.org
 
index 16fdd7dddaf455fc5b637d8df1cae0dd7c179fa5..05d70301adca0d616f06b0efe177e30661117238 100644 (file)
@@ -1,6 +1,6 @@
 From 0d75f39b65f3fa3ba0eadd5ff1dedaa2d5948c67 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:24 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 0/2] btrfs: reflink: two fixes for copying inline extents into the page cache
 To: linux-btrfs@vger.kernel.org
 
diff --git a/topics/remap-balance-leak/0001-btrfs-free-queued-remap-chunks-when-balance-bails-ou.patch b/topics/remap-balance-leak/0001-btrfs-free-queued-remap-chunks-when-balance-bails-ou.patch
new file mode 100644 (file)
index 0000000..05ad794
--- /dev/null
@@ -0,0 +1,47 @@
+From d0136e6493082d001aa33ed4174dae6062abb49a 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] btrfs: free queued remap chunks when balance bails out
+To: linux-btrfs@vger.kernel.org
+
+__btrfs_balance() queues METADATA_REMAP chunks on a local list and
+balances them only after the main loop, in balance_remap_chunks(), which
+also frees the entries.  Every path that leaves the loop through the
+error label skips that call: a pause or cancel request, a chunk tree
+search error, should_balance_chunk() failing, btrfs_may_alloc_data_chunk()
+or relocation errors, or the allocation of a later entry failing.  The
+entries queued so far are leaked.
+
+Free the leftover entries at the error label.  Nothing else needs undoing:
+the block group lookup, the reference and the read-only count are all
+taken inside balance_remap_chunks(), so a queued entry holds no block
+group and none is left read-only.
+
+Fixes: 81e5a4551c32 ("btrfs: allow balancing remap tree")
+---
+ fs/btrfs/volumes.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index 3d4ef6725de0e..788f60910acf5 100644
+--- a/fs/btrfs/volumes.c
++++ b/fs/btrfs/volumes.c
+@@ -4756,6 +4756,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
+               }
+       }
+ error:
++      /* Entries left over when the loop bailed out before balancing them. */
++      while (!list_empty(&remap_chunks)) {
++              rci = list_first_entry(&remap_chunks, struct remap_chunk_info,
++                                     list);
++              list_del(&rci->list);
++              kfree(rci);
++      }
++
+       if (enospc_errors) {
+               btrfs_info(fs_info, "%d enospc errors during balance",
+                          enospc_errors);
+
+-- 
+2.47.3
+
diff --git a/topics/remap-balance-leak/TESTING.md b/topics/remap-balance-leak/TESTING.md
new file mode 100644 (file)
index 0000000..bffcacd
--- /dev/null
@@ -0,0 +1,76 @@
+# Testing: remap-balance-leak
+
+The one patch frees the METADATA_REMAP chunks that `__btrfs_balance()`
+queues on a local list when the walk leaves the loop through the error
+label (pause, cancel, chunk search or relocation errors, a failed
+allocation of a later entry).  Before it, only `balance_remap_chunks()`
+freed the entries, and the error label skipped it.  To verify: a balance
+that bails out with remap chunks queued must free every entry, and a
+completed walk must still free its entries in `balance_remap_chunks()`.
+
+Until 2026-11-08 the patch was patch 1 of `balance-resume`; the results
+below are from that time.  It does not depend on that series, textually
+or in behavior: it applies to the base on its own, and the lanes merge it
+right after `balance-resume`.  The test drives the bail-out with
+`remap-balance-resume-test.sh`, whose pause and resume use the balance
+item; the test kernels had `balance-resume` too.
+
+Kernel under test, unless a row says otherwise: misc-next zb64
+568c45b64012 (uname 7.3.0-rc7+ #5, KASAN), dhive; logs under
+`/mnt/wh/t-dhive/logs/<test>-<stamp>/` while recent, copied to
+`raid56-wh-harness/forensics/t-dhive-topics-20261018/`.  The negative
+control ran on the misc-next base 0c48d26d46bd without any topic (dhive
+KASAN build 1 of #5's config, bzImage md5
+83a4d5325c9a195746cf230032929c76).
+
+## Tests
+
+| test | verifies | patch(es) | duration | last result | date | kernel | harness | evidence |
+|---|---|---|---|---|---|---|---|---|
+| `remap-balance-leak-test.sh` | every queued `remap_chunk_info` is freed, including when the walk bails out at a pause | 1 | 171 s | PASS: 4 entries allocated in btrfs_balance, 4 freed; the paused walk's entry was freed from its own call site (btrfs_balance+0x1a26), the completed walks' from balance_remap_chunks (+0x4119) | 2026-10-18 | misc-next #5 | 0a72db0 | dhive `logs/remap-balance-leak-test-20261018-042918`, trace in `ev/remap-leak-1/trace.txt` |
+| `remap-balance-leak-test.sh` (negative control, `LEAK_ONLY=1`) | the same, on the base without the series | 1 | 172 s | FAIL as expected: 3 allocated, 1 unfreed (the paused walk's) | 2026-10-18 | misc-next base 0c48d26d46bd, dhive KASAN build 1 | 27b253a | dhive `logs/neg-remap-balance-leak-test-20261018-055959` |
+
+**remap-balance-leak-test.sh.**  The test kernels have no kmemleak, so the
+test watches the allocations: a private tracefs instance records
+kmem:kmalloc events of 40 bytes (sizeof(struct remap_chunk_info)) whose
+call site is in btrfs_balance (`__btrfs_balance()` and
+`balance_remap_chunks()` are inlined into it) and every kmem:kfree called
+from btrfs_balance, while `remap-balance-resume-test.sh` runs.  That test
+pauses a full balance after the walk has queued a METADATA_REMAP chunk --
+the bail-out that leaked -- then remounts and resumes.  PASS needs the remap
+test to PASS (so the paused walk did queue the chunk), at least two
+allocations (the remap chunk move before the balance, and the paused walk),
+and a matching kfree for every allocation.  Unfixed, the paused walk's entry
+is never freed.  On #5 the paused walk's entry was freed from a different
+offset in btrfs_balance than the entries of the completed walks, which is
+the new free at the error label.  **Shown to fail without the patch**: on
+the misc-next base 0c48d26d46bd (no topics; KASAN build of #5's config,
+dhive build 1, 2026-10-18), with `LEAK_ONLY=1` (the remap test is told to
+pause even without the vrange bound and its resume verdict is ignored), 3
+entries were allocated and 1 was never freed (allocated at
+btrfs_balance+0x2345, the paused walk's queue), and the remap chunk survived
+the resume, as expected without balance-resume's vrange bound
+(`logs/neg-remap-balance-leak-test-20261018-055959`).  Limits: only the pause bail-out is driven, not
+cancel or the error exits (they share the error label); it depends on the
+inlining of both functions into btrfs_balance (a different inlining
+changes the call-site filter and the test then fails as blind with fewer
+than 2 allocations).
+
+Later results (the patch unchanged):
+
+| run | result | kernel |
+|---|---|---|
+| 2026-11-05 (br1105) | PASS on dhive and ehive; SKIP on 6.18 (no remap tree: the kernel cannot mount the fs), as expected | misc-next #67 |
+| 2026-11-06 (fl1106) | PASS on dhive and ehive, and on #67 (dhive); SKIP on 6.18 as expected | misc-next #68 |
+| 2026-11-09 (nc1108, as its own series merged after `balance-resume`) | PASS: 4 entries allocated in btrfs_balance, 0 unfreed; `remap-balance-resume-test.sh` PASS (the remap chunk at 6472859648 emptied by the resumed run); no KASAN, taint 0 | misc-next zb64 fb7546be6023 (7.3.0+ #8, KASAN + lockdep + BTRFS_ASSERT, md5 87693553da3b79a8991c445f42888365), ahive |
+
+## Not covered / open
+
+- The other bail-outs (cancel, chunk search or relocation errors, a
+  failed allocation of a later entry) share the error label but are not
+  driven.
+- The negative control ran on the base kernel without any topic, not on
+  #5 with only this patch reverted; the test targets this patch's code
+  path, but the base differs in more than that patch (it also lacks
+  balance-resume's vrange bound, which is why its remap chunk survived the
+  resume).
index df54dfe6a9c48eb2c1bf04d249ff617b3370445a..2907d3fd78cf6a07f8609d06a0d4ee78916eb6c7 100644 (file)
@@ -1,6 +1,6 @@
 From 480444bfe90d6ebb487cc5533719d4ef95c34132 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:23 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 00/10] btrfs: dev-replace error accounting, resume and failure handling, and an abort option
 To: linux-btrfs@vger.kernel.org
 
index 945fa9cc39dca860e729fde7834d4bc0431e5839..fb7244e12b555280afdb186e8ad2b2a83065fe2c 100644 (file)
@@ -1,6 +1,6 @@
 From 3865255228933287e3a8da2aaa0357822864c342 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:24 -0500
+Date: Mon, 9 Nov 2026 08:41:09 -0500
 Subject: [PATCH 0/1] btrfs: resize: allow shrinking a missing device
 To: linux-btrfs@vger.kernel.org
 
index 05ec82409a70e2d26529ce271b2dab4e77cb7cb5..0a2b628373d69e50d7f4df3e7dd08691c387ebd3 100644 (file)
@@ -1,6 +1,6 @@
 From 253389241150fda20abe4af6b71772ba75e22267 Mon Sep 17 00:00:00 2001
 From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Fri, 6 Nov 2026 15:43:20 -0500
+Date: Mon, 9 Nov 2026 08:41:07 -0500
 Subject: [RFC PATCH 00/85] btrfs: close the raid56 write hole for datacow with stripe-exclusive allocation
 To: linux-btrfs@vger.kernel.org