Commit c2a128d2 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: cache extent state in find_delalloc_range

This patch makes us cache the extent state we find in find_delalloc_range since
we'll have to lock the extent later on in the function.  This will keep us from
re-searching for the rang when we try to lock the extent.
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 49958fd7
...@@ -1171,7 +1171,8 @@ struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree, ...@@ -1171,7 +1171,8 @@ struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
* 1 is returned if we find something, 0 if nothing was in the tree * 1 is returned if we find something, 0 if nothing was in the tree
*/ */
static noinline u64 find_delalloc_range(struct extent_io_tree *tree, static noinline u64 find_delalloc_range(struct extent_io_tree *tree,
u64 *start, u64 *end, u64 max_bytes) u64 *start, u64 *end, u64 max_bytes,
struct extent_state **cached_state)
{ {
struct rb_node *node; struct rb_node *node;
struct extent_state *state; struct extent_state *state;
...@@ -1203,8 +1204,11 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, ...@@ -1203,8 +1204,11 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree,
*end = state->end; *end = state->end;
goto out; goto out;
} }
if (!found) if (!found) {
*start = state->start; *start = state->start;
*cached_state = state;
atomic_inc(&state->refs);
}
found++; found++;
*end = state->end; *end = state->end;
cur_start = state->end + 1; cur_start = state->end + 1;
...@@ -1336,10 +1340,11 @@ static noinline u64 find_lock_delalloc_range(struct inode *inode, ...@@ -1336,10 +1340,11 @@ static noinline u64 find_lock_delalloc_range(struct inode *inode,
delalloc_start = *start; delalloc_start = *start;
delalloc_end = 0; delalloc_end = 0;
found = find_delalloc_range(tree, &delalloc_start, &delalloc_end, found = find_delalloc_range(tree, &delalloc_start, &delalloc_end,
max_bytes); max_bytes, &cached_state);
if (!found || delalloc_end <= *start) { if (!found || delalloc_end <= *start) {
*start = delalloc_start; *start = delalloc_start;
*end = delalloc_end; *end = delalloc_end;
free_extent_state(cached_state);
return found; return found;
} }
......
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