aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-12-31 09:09:05 -0500
committerDavid Sterba <dsterba@suse.com>2016-02-18 04:26:12 -0500
commit6e39dbe8b9e55280c396a19fb92e82f1b56f83d7 (patch)
tree29352ae8c63eaf8c567d231ca7252fff4ce98560
parentb257cf50060cada63a3fe11a932909b9badf4595 (diff)
btrfs: reada: Pass reada_extent into __readahead_hook directly
reada_start_machine_dev() already have reada_extent pointer, pass it into __readahead_hook() directly instead of search radix_tree will make code run faster. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/reada.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index f7642e569bd9..203bec4823e1 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -105,33 +105,21 @@ static int reada_add_block(struct reada_control *rc, u64 logical,
105 105
106/* recurses */ 106/* recurses */
107/* in case of err, eb might be NULL */ 107/* in case of err, eb might be NULL */
108static int __readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, 108static void __readahead_hook(struct btrfs_root *root, struct reada_extent *re,
109 u64 start, int err) 109 struct extent_buffer *eb, u64 start, int err)
110{ 110{
111 int level = 0; 111 int level = 0;
112 int nritems; 112 int nritems;
113 int i; 113 int i;
114 u64 bytenr; 114 u64 bytenr;
115 u64 generation; 115 u64 generation;
116 struct reada_extent *re;
117 struct btrfs_fs_info *fs_info = root->fs_info; 116 struct btrfs_fs_info *fs_info = root->fs_info;
118 struct list_head list; 117 struct list_head list;
119 unsigned long index = start >> PAGE_CACHE_SHIFT;
120 struct btrfs_device *for_dev; 118 struct btrfs_device *for_dev;
121 119
122 if (eb) 120 if (eb)
123 level = btrfs_header_level(eb); 121 level = btrfs_header_level(eb);
124 122
125 /* find extent */
126 spin_lock(&fs_info->reada_lock);
127 re = radix_tree_lookup(&fs_info->reada_tree, index);
128 if (re)
129 re->refcnt++;
130 spin_unlock(&fs_info->reada_lock);
131
132 if (!re)
133 return -1;
134
135 spin_lock(&re->lock); 123 spin_lock(&re->lock);
136 /* 124 /*
137 * just take the full list from the extent. afterwards we 125 * just take the full list from the extent. afterwards we
@@ -221,11 +209,11 @@ static int __readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,
221 209
222 reada_extent_put(fs_info, re); /* one ref for each entry */ 210 reada_extent_put(fs_info, re); /* one ref for each entry */
223 } 211 }
224 reada_extent_put(fs_info, re); /* our ref */ 212
225 if (for_dev) 213 if (for_dev)
226 atomic_dec(&for_dev->reada_in_flight); 214 atomic_dec(&for_dev->reada_in_flight);
227 215
228 return 0; 216 return;
229} 217}
230 218
231/* 219/*
@@ -235,12 +223,27 @@ static int __readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,
235int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, 223int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,
236 u64 start, int err) 224 u64 start, int err)
237{ 225{
238 int ret; 226 int ret = 0;
227 struct reada_extent *re;
228 struct btrfs_fs_info *fs_info = root->fs_info;
239 229
240 ret = __readahead_hook(root, eb, start, err); 230 /* find extent */
231 spin_lock(&fs_info->reada_lock);
232 re = radix_tree_lookup(&fs_info->reada_tree,
233 start >> PAGE_CACHE_SHIFT);
234 if (re)
235 re->refcnt++;
236 spin_unlock(&fs_info->reada_lock);
237 if (!re) {
238 ret = -1;
239 goto start_machine;
240 }
241 241
242 reada_start_machine(root->fs_info); 242 __readahead_hook(fs_info, re, eb, start, err);
243 reada_extent_put(fs_info, re); /* our ref */
243 244
245start_machine:
246 reada_start_machine(fs_info);
244 return ret; 247 return ret;
245} 248}
246 249
@@ -721,9 +724,9 @@ static int reada_start_machine_dev(struct btrfs_fs_info *fs_info,
721 ret = reada_tree_block_flagged(fs_info->extent_root, logical, 724 ret = reada_tree_block_flagged(fs_info->extent_root, logical,
722 mirror_num, &eb); 725 mirror_num, &eb);
723 if (ret) 726 if (ret)
724 __readahead_hook(fs_info->extent_root, NULL, logical, ret); 727 __readahead_hook(fs_info->extent_root, re, NULL, logical, ret);
725 else if (eb) 728 else if (eb)
726 __readahead_hook(fs_info->extent_root, eb, eb->start, ret); 729 __readahead_hook(fs_info->extent_root, re, eb, eb->start, ret);
727 730
728 if (eb) 731 if (eb)
729 free_extent_buffer(eb); 732 free_extent_buffer(eb);