From: Ismael Luceno <ismael@iodev.co.uk>
To: linux-btrfs@vger.kernel.org, David Sterba <dsterba@suse.com>,
Chris Mason <mason@kernel.org>
Cc: Ismael Luceno <ismael@iodev.co.uk>,
linux-kernel@vger.kernel.org, Qu Wenruo <wqu@suse.com>,
Anand Jain <asj@kernel.org>, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH 4/6] btrfs: scan the running transaction for data extent references
Date: Sun, 29 Nov 2026 14:31:17 +0100 [thread overview]
Message-ID: <20261129133125.3293-5-ismael@iodev.co.uk> (raw)
In-Reply-To: <20261129133125.3293-1-ismael@iodev.co.uk>
The reference scan of a data extent walks the trees without a transaction
handle, so the backref walk reads the commit root. A reference made by
the running transaction, such as a reflink made during balance, is not
in the commit root, so the scan misses it, while the extent item already
counts it.
Run the scan under a joined transaction, so the walk sees the running
transaction and its pending delayed refs. The transaction is not flushed:
the walk accounts for pending refs itself.
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
fs/btrfs/relocation.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index a9da7a6468fa5..75300c21fe06e 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3255,19 +3255,31 @@ static int collect_extent_segments(struct reloc_control *rc,
{
struct btrfs_fs_info *fs_info = rc->extent_root->fs_info;
struct btrfs_backref_walk_ctx ctx = { 0 };
+ struct btrfs_trans_handle *trans;
struct ulist_iterator leaf_uiter;
struct ulist_node *ref_node;
const u64 bytenr = extent_key->objectid;
const u64 num_bytes = extent_key->offset;
int ret;
+ /*
+ * Walk the running transaction, delayed refs included, so the scan sees
+ * the references made by it. They are not flushed.
+ */
+ trans = btrfs_join_transaction(rc->extent_root);
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
+
ctx.bytenr = bytenr;
ctx.skip_inode_ref_list = true;
ctx.fs_info = fs_info;
+ ctx.trans = trans;
ret = btrfs_find_all_leafs(&ctx);
- if (ret < 0)
+ if (ret < 0) {
+ btrfs_end_transaction(trans);
return ret;
+ }
ULIST_ITER_INIT(&leaf_uiter);
while ((ref_node = ulist_next(ctx.refs, &leaf_uiter))) {
@@ -3315,6 +3327,7 @@ static int collect_extent_segments(struct reloc_control *rc,
break;
}
ulist_free(ctx.refs);
+ btrfs_end_transaction(trans);
if (ret)
return ret;
--
2.56.0
next prev parent reply other threads:[~2026-11-29 13:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 13:31 [PATCH 0/6] btrfs: trim unused space when relocating data extents Ismael Luceno
2026-11-29 13:31 ` [PATCH 1/6] btrfs: add prealloc helper for sharing one allocation Ismael Luceno
2026-11-29 13:31 ` [PATCH 2/6] btrfs: allow NOCOW writeback into data relocation extents Ismael Luceno
2026-11-29 13:31 ` [PATCH 3/6] btrfs: relocate only referenced bytes of a data extent Ismael Luceno
2026-11-29 13:31 ` Ismael Luceno [this message]
2026-11-29 13:31 ` [PATCH 5/6] btrfs: retry a block group that references survive the update stage Ismael Luceno
2026-11-29 13:31 ` [PATCH 6/6] btrfs: derive relocation group length from its members Ismael Luceno
2026-11-29 21:00 ` [PATCH 0/6] btrfs: trim unused space when relocating data extents Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129133125.3293-5-ismael@iodev.co.uk \
--to=ismael@iodev.co.uk \
--cc=asj@kernel.org \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®