Commit 9085f425 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: avoid searching twice for previous node when merging free space entries

At try_merge_free_space(), avoid calling twice rb_prev() to find the
previous node, as that requires looping through the red black tree, so
store the result of the rb_prev() call and then use it.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent fbb2e654
...@@ -2449,6 +2449,7 @@ static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, ...@@ -2449,6 +2449,7 @@ static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl,
u64 offset = info->offset; u64 offset = info->offset;
u64 bytes = info->bytes; u64 bytes = info->bytes;
const bool is_trimmed = btrfs_free_space_trimmed(info); const bool is_trimmed = btrfs_free_space_trimmed(info);
struct rb_node *right_prev = NULL;
/* /*
* first we want to see if there is free space adjacent to the range we * first we want to see if there is free space adjacent to the range we
...@@ -2456,9 +2457,11 @@ static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, ...@@ -2456,9 +2457,11 @@ static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl,
* cover the entire range * cover the entire range
*/ */
right_info = tree_search_offset(ctl, offset + bytes, 0, 0); right_info = tree_search_offset(ctl, offset + bytes, 0, 0);
if (right_info && rb_prev(&right_info->offset_index)) if (right_info)
left_info = rb_entry(rb_prev(&right_info->offset_index), right_prev = rb_prev(&right_info->offset_index);
struct btrfs_free_space, offset_index);
if (right_prev)
left_info = rb_entry(right_prev, struct btrfs_free_space, offset_index);
else if (!right_info) else if (!right_info)
left_info = tree_search_offset(ctl, offset - 1, 0, 0); left_info = tree_search_offset(ctl, offset - 1, 0, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment