Skip to content

Commit

Permalink
Btrfs: reduce lock contention during extent insertion
Browse files Browse the repository at this point in the history
We're spending huge amounts of time on lock contention during
end_io processing because we unconditionally assume we are overwriting
an existing extent in the file for each IO.

This checks to see if we are outside i_size, and if so, it uses a
less expensive readonly search of the btree to look for existing
extents.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason committed Apr 27, 2012
1 parent fede766 commit dc7fdde
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
int extent_type;
int recow;
int ret;
int modify_tree = -1;

if (drop_cache)
btrfs_drop_extent_cache(inode, start, end - 1, 0);
Expand All @@ -575,10 +576,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
if (!path)
return -ENOMEM;

if (start >= BTRFS_I(inode)->disk_i_size)
modify_tree = 0;

while (1) {
recow = 0;
ret = btrfs_lookup_file_extent(trans, root, path, ino,
search_start, -1);
search_start, modify_tree);
if (ret < 0)
break;
if (ret > 0 && path->slots[0] > 0 && search_start == start) {
Expand Down Expand Up @@ -634,7 +638,8 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
}

search_start = max(key.offset, start);
if (recow) {
if (recow || !modify_tree) {
modify_tree = -1;
btrfs_release_path(path);
continue;
}
Expand Down

0 comments on commit dc7fdde

Please sign in to comment.