diff options
author | Filipe Manana <fdmanana@gmail.com> | 2014-03-11 09:56:15 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-03-20 20:15:27 -0400 |
commit | 308d9800b2c4f1fb344dbf055912d3140438bac0 (patch) | |
tree | 24c94bc9e5d7aa3394a35d767f78f245e2922a58 /fs/btrfs | |
parent | 3bbb24b20a8800158c33eca8564f432dd14d0bf3 (diff) |
Btrfs: cache extent states in defrag code path
When locking file ranges in the inode's io_tree, cache the first
extent state that belongs to the target range, so that when unlocking
the range we don't need to search in the io_tree again, reducing cpu
time and making and therefore holding the io_tree's lock for a shorter
period.
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ioctl.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index e1747701f520..3ad5c10d3704 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -986,10 +986,13 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start) | |||
986 | read_unlock(&em_tree->lock); | 986 | read_unlock(&em_tree->lock); |
987 | 987 | ||
988 | if (!em) { | 988 | if (!em) { |
989 | struct extent_state *cached = NULL; | ||
990 | u64 end = start + len - 1; | ||
991 | |||
989 | /* get the big lock and read metadata off disk */ | 992 | /* get the big lock and read metadata off disk */ |
990 | lock_extent(io_tree, start, start + len - 1); | 993 | lock_extent_bits(io_tree, start, end, 0, &cached); |
991 | em = btrfs_get_extent(inode, NULL, 0, start, len, 0); | 994 | em = btrfs_get_extent(inode, NULL, 0, start, len, 0); |
992 | unlock_extent(io_tree, start, start + len - 1); | 995 | unlock_extent_cached(io_tree, start, end, &cached, GFP_NOFS); |
993 | 996 | ||
994 | if (IS_ERR(em)) | 997 | if (IS_ERR(em)) |
995 | return NULL; | 998 | return NULL; |
@@ -1128,10 +1131,12 @@ again: | |||
1128 | page_start = page_offset(page); | 1131 | page_start = page_offset(page); |
1129 | page_end = page_start + PAGE_CACHE_SIZE - 1; | 1132 | page_end = page_start + PAGE_CACHE_SIZE - 1; |
1130 | while (1) { | 1133 | while (1) { |
1131 | lock_extent(tree, page_start, page_end); | 1134 | lock_extent_bits(tree, page_start, page_end, |
1135 | 0, &cached_state); | ||
1132 | ordered = btrfs_lookup_ordered_extent(inode, | 1136 | ordered = btrfs_lookup_ordered_extent(inode, |
1133 | page_start); | 1137 | page_start); |
1134 | unlock_extent(tree, page_start, page_end); | 1138 | unlock_extent_cached(tree, page_start, page_end, |
1139 | &cached_state, GFP_NOFS); | ||
1135 | if (!ordered) | 1140 | if (!ordered) |
1136 | break; | 1141 | break; |
1137 | 1142 | ||