Commit dc7fdde3 authored by Chris Mason's avatar Chris Mason

Btrfs: reduce lock contention during extent insertion

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: default avatarChris Mason <chris.mason@oracle.com>
parent fede766f
...@@ -567,6 +567,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -567,6 +567,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
int extent_type; int extent_type;
int recow; int recow;
int ret; int ret;
int modify_tree = -1;
if (drop_cache) if (drop_cache)
btrfs_drop_extent_cache(inode, start, end - 1, 0); btrfs_drop_extent_cache(inode, start, end - 1, 0);
...@@ -575,10 +576,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -575,10 +576,13 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
if (start >= BTRFS_I(inode)->disk_i_size)
modify_tree = 0;
while (1) { while (1) {
recow = 0; recow = 0;
ret = btrfs_lookup_file_extent(trans, root, path, ino, ret = btrfs_lookup_file_extent(trans, root, path, ino,
search_start, -1); search_start, modify_tree);
if (ret < 0) if (ret < 0)
break; break;
if (ret > 0 && path->slots[0] > 0 && search_start == start) { if (ret > 0 && path->slots[0] > 0 && search_start == start) {
...@@ -634,7 +638,8 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -634,7 +638,8 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
} }
search_start = max(key.offset, start); search_start = max(key.offset, start);
if (recow) { if (recow || !modify_tree) {
modify_tree = -1;
btrfs_release_path(path); btrfs_release_path(path);
continue; continue;
} }
......
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