Skip to contentSkip to conversation

btrfs: cleanup node balancing condition for balance_level()

PATCH New Sun YangKai 1 participant 1 message Jan 15 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: cleanup node balancing condition for balance_level()

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(), which is the only caller of balance_level(). However, an undetected early return condition in balance_level() prevented this behavior and the change has never worked as expected.

Since we're fine with the 25% threshold for years, remove the early return and keep the old threshold.

No functional change intended.

---
 fs/btrfs/ctree.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/ctree.c +2 -5
index 7267b2502665..48e1ef594517 100644
@@ -960,9 +960,6 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
 
 		return promote_child_to_root(trans, root, path, level, mid);
 	}
-	if (btrfs_header_nritems(mid) >
-	    BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)
-		return 0;
 
 	if (pslot) {
 		left = btrfs_read_node_slot(parent, pslot - 1);
@@ -1646,8 +1643,8 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans,
 		ret = split_node(trans, root, p, level);
 
 		b = p->nodes[level];
-	} else if (ins_len < 0 && btrfs_header_nritems(b) <
-		   BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 2) {
+	} else if (ins_len < 0 && btrfs_header_nritems(b) <=
+		   BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4) {
 
 		if (*write_lock_level < level + 1) {
 			*write_lock_level = level + 1;
Signature · 1 line
2.52.0