From: Qu Wenruo <wqu@suse.com>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 1/6] btrfs: qgroup: fix swapped blocks existence check when tracing after COW
Date: Sun, 4 Oct 2026 07:59:16 +1030 [thread overview]
Message-ID: <bc377417-8c26-4982-9668-94d5e4368cf7@suse.com> (raw)
In-Reply-To: <59dc69757209cf74399ee29786aee0f5392f1a47.1791046651.git.fdmanana@suse.com>
在 2026/10/4 03:30, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> In btrfs_qgroup_trace_subtree_after_cow(), after we erase the swapped
> block, iterate over all possible tree levels to check if we sill have
> other swapped blocks. However the check is wrong, it considers that there
> are other swapped blocks if any rbtree for any level is empty, instead of
> not empty. As a consequence we set blocks->swapped to true basically every
> time since we always find an empty rbtree at least at level 7, since in
> practice it's nearly impossible to find such a huge btree. This makes
> every future call to btrfs_qgroup_trace_subtree_after_cow() do an
> unnecessary rbtree search instead of returning immediately.
>
> Fix this by updating the condition to set swapped to true if we find an
> rbtree that is not empty.
>
> Fixes: f616f5cd9da7 ("btrfs: qgroup: Use delayed subtree rescan for balance")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/ctree.h | 2 +-
> fs/btrfs/qgroup.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 22ba2b4505b3..00d4c4184e76 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -160,7 +160,7 @@ enum {
> */
> struct btrfs_qgroup_swapped_blocks {
> spinlock_t lock;
> - /* RM_EMPTY_ROOT() of above blocks[] */
> + /* True if any of the rbtrees in the blocks array below is not empty. */
> bool swapped;
> struct rb_root blocks[BTRFS_MAX_LEVEL];
> };
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 46de0a5e80d5..798f21608de5 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -4913,7 +4913,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
> /* Found one, remove it from @blocks first and update blocks->swapped */
> rb_erase(&block->node, &blocks->blocks[level]);
> for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
> - if (RB_EMPTY_ROOT(&blocks->blocks[i])) {
> + if (!RB_EMPTY_ROOT(&blocks->blocks[i])) {
> swapped = true;
> break;
> }
next prev parent reply other threads:[~2026-10-03 21:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 18:55 [PATCH 0/6] btrfs: some qgroup fixes and cleanups fdmanana
2026-10-02 18:55 ` [PATCH] btrfs: qgroup: fix race between subvolume creation and adding/removing relations fdmanana
2026-10-02 18:58 ` Filipe Manana
2026-10-02 18:55 ` [PATCH 1/6] btrfs: qgroup: fix swapped blocks existence check when tracing after COW fdmanana
2026-10-03 0:18 ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 2/6] btrfs: qgroup: abort transaction on failure to add qgroup relation fdmanana
2026-10-03 0:19 ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 3/6] btrfs: qgroup: fix leak of qgroups in rb tree after failure to enable quotas fdmanana
2026-10-02 18:55 ` [PATCH 4/6] btrfs: qgroup: merge error labels in btrfs_quota_enable() fdmanana
2026-10-03 0:22 ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 5/6] btrfs: abort transaction on qgroup failures in create_pending_snapshot() fdmanana
2026-10-03 0:22 ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 6/6] btrfs: qgroup: fix off-by-one max level check in qgroup_trace_new_subtree_blocks() fdmanana
2026-10-03 16:59 ` [PATCH v2 0/6] btrfs: some qgroup fixes and cleanups fdmanana
2026-10-03 17:00 ` [PATCH v2 1/6] btrfs: qgroup: fix swapped blocks existence check when tracing after COW fdmanana
2026-10-03 21:29 ` Qu Wenruo [this message]
2026-10-03 17:00 ` [PATCH v2 2/6] btrfs: qgroup: abort transaction on failure to add qgroup relation fdmanana
2026-10-03 17:00 ` [PATCH v2 3/6] btrfs: qgroup: fix leak of qgroups in rb tree after failure to enable quotas fdmanana
2026-10-03 21:35 ` Qu Wenruo
2026-10-03 17:00 ` [PATCH v2 4/6] btrfs: qgroup: merge error labels in btrfs_quota_enable() fdmanana
2026-10-03 17:00 ` [PATCH v2 5/6] btrfs: abort transaction on qgroup failures in create_pending_snapshot() fdmanana
2026-10-03 17:00 ` [PATCH v2 6/6] btrfs: qgroup: fix off-by-one max level check in qgroup_trace_new_subtree_blocks() fdmanana
2026-10-03 21:36 ` 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=bc377417-8c26-4982-9668-94d5e4368cf7@suse.com \
--to=wqu@suse.com \
--cc=fdmanana@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/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