Skip to content

Commit 064046d

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> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent cd333ea commit 064046d

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
@@ -1125,11 +1125,12 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
11251125
/* update the path */
11261126
if (left) {
11271127
if (btrfs_header_nritems(left) > orig_slot) {
1128-
refcount_inc(&left->refs);
11291128
/* left was locked after cow */
11301129
path->nodes[level] = left;
11311130
path->slots[level + 1] -= 1;
11321131
path->slots[level] = orig_slot;
1132+
/* Left is now owned by path. */
1133+
left = NULL;
11331134
if (mid) {
11341135
btrfs_tree_unlock(mid);
11351136
free_extent_buffer(mid);
@@ -1149,8 +1150,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
11491150
free_extent_buffer(right);
11501151
}
11511152
if (left) {
1152-
if (path->nodes[level] != left)
1153-
btrfs_tree_unlock(left);
1153+
btrfs_tree_unlock(left);
11541154
free_extent_buffer(left);
11551155
}
11561156
return ret;

0 commit comments

Comments
 (0)