Skip to content

Commit 6d2ba15

Browse files
SaltyKitkatkdave
authored andcommitted
btrfs: optimize balance_level() path reference handling
Instead of incrementing refcount on left node when it's referenced by path, simply transfer ownership to path and set left to NULL. This eliminates: - Unnecessary refcount increment/decrement operations - Redundant conditional checks for left node cleanup The path now consistently owns the left node reference when used. Signed-off-by: Sun YangKai <sunk67188@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8bfb4e9 commit 6d2ba15

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/btrfs/ctree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,11 +1127,12 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
11271127
/* update the path */
11281128
if (left) {
11291129
if (btrfs_header_nritems(left) > orig_slot) {
1130-
refcount_inc(&left->refs);
11311130
/* left was locked after cow */
11321131
path->nodes[level] = left;
11331132
path->slots[level + 1] -= 1;
11341133
path->slots[level] = orig_slot;
1134+
/* left is now owned by path */
1135+
left = NULL;
11351136
if (mid) {
11361137
btrfs_tree_unlock(mid);
11371138
free_extent_buffer(mid);
@@ -1151,8 +1152,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
11511152
free_extent_buffer(right);
11521153
}
11531154
if (left) {
1154-
if (path->nodes[level] != left)
1155-
btrfs_tree_unlock(left);
1155+
btrfs_tree_unlock(left);
11561156
free_extent_buffer(left);
11571157
}
11581158
return ret;

0 commit comments

Comments
 (0)