Skip to content

Commit 7b00dff

Browse files
fdmananakdave
authored andcommitted
btrfs: eliminate extra call when doing binary search on extent buffer
The function btrfs_bin_search() is just a wrapper around the function generic_bin_search(), which passes the same arguments plus a default low slot with a value of 0. This adds an unnecessary extra function call, since btrfs_bin_search() is not static. So improve on this by making btrfs_bin_search() an inline function that calls generic_bin_search(), renaming the later to btrfs_generic_bin_search() and exporting it. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 08241d3 commit 7b00dff

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

fs/btrfs/ctree.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
863863
* Slot may point to the total number of items (i.e. one position beyond the last
864864
* key) if the key is bigger than the last key in the extent buffer.
865865
*/
866-
static noinline int generic_bin_search(struct extent_buffer *eb, int low,
867-
const struct btrfs_key *key, int *slot)
866+
int btrfs_generic_bin_search(struct extent_buffer *eb, int low,
867+
const struct btrfs_key *key, int *slot)
868868
{
869869
unsigned long p;
870870
int item_size;
@@ -925,16 +925,6 @@ static noinline int generic_bin_search(struct extent_buffer *eb, int low,
925925
return 1;
926926
}
927927

928-
/*
929-
* Simple binary search on an extent buffer. Works for both leaves and nodes, and
930-
* always searches over the whole range of keys (slot 0 to slot 'nritems - 1').
931-
*/
932-
int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
933-
int *slot)
934-
{
935-
return generic_bin_search(eb, 0, key, slot);
936-
}
937-
938928
static void root_add_used(struct btrfs_root *root, u32 size)
939929
{
940930
spin_lock(&root->accounting_lock);
@@ -1869,7 +1859,7 @@ static inline int search_for_key_slot(struct extent_buffer *eb,
18691859
return 0;
18701860
}
18711861

1872-
return generic_bin_search(eb, search_low_slot, key, slot);
1862+
return btrfs_generic_bin_search(eb, search_low_slot, key, slot);
18731863
}
18741864

18751865
static int search_leaf(struct btrfs_trans_handle *trans,

fs/btrfs/ctree.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,21 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);
507507
/* ctree.c */
508508
int __init btrfs_ctree_init(void);
509509
void __cold btrfs_ctree_exit(void);
510+
511+
int btrfs_generic_bin_search(struct extent_buffer *eb, int low,
512+
const struct btrfs_key *key, int *slot);
513+
514+
/*
515+
* Simple binary search on an extent buffer. Works for both leaves and nodes, and
516+
* always searches over the whole range of keys (slot 0 to slot 'nritems - 1').
517+
*/
518+
static inline int btrfs_bin_search(struct extent_buffer *eb,
519+
const struct btrfs_key *key,
520+
int *slot)
521+
{
522+
return btrfs_generic_bin_search(eb, 0, key, slot);
523+
}
524+
510525
int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
511526
int *slot);
512527
int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);

0 commit comments

Comments
 (0)