Btrfs: optimize read_block_for_search
This patch does two things, first it only does one call to btrfs_buffer_uptodate() with the gen specified instead of once with 0 and then again with gen specified. The other thing is to call btrfs_read_buffer() on the buffer we've found instead of dropping it and then calling read_tree_block(). This will keep us from doing yet another radix tree lookup for a buffer we've already found. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
This commit is contained in:
parent
fdf8e2ea3c
commit
bdf7c00e8f
|
@ -2359,28 +2359,22 @@ read_block_for_search(struct btrfs_trans_handle *trans,
|
||||||
tmp = btrfs_find_tree_block(root, blocknr, blocksize);
|
tmp = btrfs_find_tree_block(root, blocknr, blocksize);
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
/* first we do an atomic uptodate check */
|
/* first we do an atomic uptodate check */
|
||||||
if (btrfs_buffer_uptodate(tmp, 0, 1) > 0) {
|
|
||||||
if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
|
if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) {
|
||||||
/*
|
|
||||||
* we found an up to date block without
|
|
||||||
* sleeping, return
|
|
||||||
* right away
|
|
||||||
*/
|
|
||||||
*eb_ret = tmp;
|
*eb_ret = tmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the pages were up to date, but we failed
|
/* the pages were up to date, but we failed
|
||||||
* the generation number check. Do a full
|
* the generation number check. Do a full
|
||||||
* read for the generation number that is correct.
|
* read for the generation number that is correct.
|
||||||
* We must do this without dropping locks so
|
* We must do this without dropping locks so
|
||||||
* we can trust our generation number
|
* we can trust our generation number
|
||||||
*/
|
*/
|
||||||
free_extent_buffer(tmp);
|
|
||||||
btrfs_set_path_blocking(p);
|
btrfs_set_path_blocking(p);
|
||||||
|
|
||||||
/* now we're allowed to do a blocking uptodate check */
|
/* now we're allowed to do a blocking uptodate check */
|
||||||
tmp = read_tree_block(root, blocknr, blocksize, gen);
|
ret = btrfs_read_buffer(tmp, gen);
|
||||||
if (tmp && btrfs_buffer_uptodate(tmp, gen, 0) > 0) {
|
if (!ret) {
|
||||||
*eb_ret = tmp;
|
*eb_ret = tmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2388,7 +2382,6 @@ read_block_for_search(struct btrfs_trans_handle *trans,
|
||||||
btrfs_release_path(p);
|
btrfs_release_path(p);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reduce lock contention at high levels
|
* reduce lock contention at high levels
|
||||||
|
|
Loading…
Reference in New Issue