Btrfs: optimize csums insertion function
RFC PATCH 1/1 Btrfs: optimize csums insertion function
Before applying this patch, we search the csum item at first, and If the new csums is adjoining to the existed csum item, we call btrfs_search_slot() to grow this item. It is unnecessary because we can re-use the first search result, if so, we can reduce the time of the csum insertion.
And Without this patch, in order to avoid the overlap of the csum items, we had to search the tree to get the next csum item if it was in the next leaf. It was also inefficient, we can get the information of the next csum item while we look up the csum item.
This patch improved these problems.
Signed-off-by Miao Xie <[email protected]>
--- fs/btrfs/ctree.c | 25 ++++++ fs/btrfs/ctree.h | 2 + fs/btrfs/file-item.c | 249 ++++++++++++++++++++++----------------------------- 3 files changed, 133 insertions(+), 143 deletions(-)
fs/btrfs/ctree.c +25 -0
@@ -144,6 +144,9 @@ noinline void btrfs_release_path(struct btrfs_path *p)free_extent_buffer (p->nodes[i]); p->nodes[i] =NULL ; } + +if (p->search_next_key) +memset (&p->next_key,0 ,sizeof (struct btrfs_key )); }/*
@@ -2499,6 +2502,26 @@ done:return ret; } +static void __cache_next_key (struct btrfs_path *p,struct extent_buffer *eb, +int level,int slot,int bin_search_result) +{ +int nitems =btrfs_header_nritems (eb); + +if (!nitems) +return ; + +if (!bin_search_result) + slot++; + +if (slot >= nitems) +return ; + +if (level) +btrfs_node_key_to_cpu (eb, &p->next_key, slot); +else +btrfs_item_key_to_cpu (eb, &p->next_key, slot); +} +/* * look for key in the tree. path is filled in with nodes along the way * if key is found, we return zero and you can find the item in the leaf
@@ -2658,6 +2681,8 @@ cow_done:btrfs_unlock_up_safe (p, level +1 ); ret =bin_search (b, key, level, &slot); +if (p->search_next_key) +__cache_next_key (p, b, level, slot, ret);if (level !=0 ) {int dec =0 ;
fs/btrfs/ctree.h +2 -0
@@ -573,6 +573,7 @@ struct btrfs_path {int slots[BTRFS_MAX_LEVEL ];/* if there is real range locking, this locks field will change */ int locks[BTRFS_MAX_LEVEL ]; +struct btrfs_key next_key;int reada;/* keep some upper locks as we walk down */ int lowest_level;
@@ -586,6 +587,7 @@ struct btrfs_path { unsigned int skip_locking:1; unsigned int leave_spinning:1; unsigned int search_commit_root:1; + unsigned int search_next_key:1; };/*
fs/btrfs/file-item.c +106 -143
308 lines not on this page · raw message
Signature · 1 line
1.8.1.4