From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH] btrfs: fix node balancing condition in balance_level()
Date: Tue, 5 Aug 2025 11:57:04 +0800 [thread overview]
Message-ID: <20250805035718.16313-1-sunk67188@gmail.com> (raw)
Commit cfbb9308463f ("Btrfs: balance btree more often") intended to
trigger node balancing when node utilization drops below 50% (capacity/2)
by modifying the condition in setup_nodes_for_search(). However, an
undetected early return condition in balance_level() prevented this
behavior from taking effect.
The early return condition:
if (btrfs_header_nritems(mid) > BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)
return 0;
caused balance_level() to abort when nodes were still more than 25% full,
effectively maintaining the original 25% threshold. This unintended
behavior persisted for over a decade. Since setup_nodes_for_search() is
the sole caller of balance_level(), remove the obsolete early return
condition to:
1. Align with the original intent of commit cfbb9308463f ("Btrfs: balance btree more often")
2. Allow proper node balancing at the 50% utilization threshold
3. Improve btree performance by more frequent node compaction
Fixes: cfbb9308463f ("Btrfs: balance btree more often")
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/ctree.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index acd85e317564..8cc52c8b38f3 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -939,9 +939,6 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
}
return 0;
}
- if (btrfs_header_nritems(mid) >
- BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)
- return 0;
if (pslot) {
left = btrfs_read_node_slot(parent, pslot - 1);
--
2.50.1
next reply other threads:[~2025-08-05 3:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 3:57 Sun YangKai [this message]
2025-08-05 18:46 ` [PATCH] btrfs: fix node balancing condition in balance_level() Boris Burkov
2025-08-06 6:07 ` Sun YangKai
2025-08-07 15:06 ` Sun YangKai
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=20250805035718.16313-1-sunk67188@gmail.com \
--to=sunk67188@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.