diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-10-15 16:22:39 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:03:57 -0400 |
commit | a6b6e75e096f436f0cc56edf5bca96301e194491 (patch) | |
tree | 03751594c29a7d70d317689fd6b5e44ee023633e /fs/btrfs/ctree.c | |
parent | ff79f8190b6e955ff7a71faf804a3017d526e657 (diff) |
Btrfs: Defrag only leaves, and only when the parent node has a single objectid
This allows us to defrag huge directories, but skip the expensive defrag
case in more common usage, where it does not help as much.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 984f4745440e..74fec6b83a8b 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -16,6 +16,7 @@ | |||
16 | * Boston, MA 021110-1307, USA. | 16 | * Boston, MA 021110-1307, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/sched.h> | ||
19 | #include "ctree.h" | 20 | #include "ctree.h" |
20 | #include "disk-io.h" | 21 | #include "disk-io.h" |
21 | #include "transaction.h" | 22 | #include "transaction.h" |
@@ -190,7 +191,8 @@ static int should_defrag_leaf(struct extent_buffer *leaf) | |||
190 | 191 | ||
191 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, | 192 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
192 | struct btrfs_root *root, struct extent_buffer *parent, | 193 | struct btrfs_root *root, struct extent_buffer *parent, |
193 | int cache_only, u64 *last_ret) | 194 | int start_slot, int cache_only, u64 *last_ret, |
195 | struct btrfs_key *progress) | ||
194 | { | 196 | { |
195 | struct extent_buffer *cur; | 197 | struct extent_buffer *cur; |
196 | struct extent_buffer *tmp; | 198 | struct extent_buffer *tmp; |
@@ -199,7 +201,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
199 | u64 last_block = 0; | 201 | u64 last_block = 0; |
200 | u64 other; | 202 | u64 other; |
201 | u32 parent_nritems; | 203 | u32 parent_nritems; |
202 | int start_slot; | ||
203 | int end_slot; | 204 | int end_slot; |
204 | int i; | 205 | int i; |
205 | int err = 0; | 206 | int err = 0; |
@@ -221,15 +222,24 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
221 | 222 | ||
222 | parent_nritems = btrfs_header_nritems(parent); | 223 | parent_nritems = btrfs_header_nritems(parent); |
223 | blocksize = btrfs_level_size(root, parent_level - 1); | 224 | blocksize = btrfs_level_size(root, parent_level - 1); |
224 | |||
225 | start_slot = 0; | ||
226 | end_slot = parent_nritems; | 225 | end_slot = parent_nritems; |
227 | 226 | ||
228 | if (parent_nritems == 1) | 227 | if (parent_nritems == 1) |
229 | return 0; | 228 | return 0; |
230 | 229 | ||
230 | if (root != root->fs_info->extent_root) { | ||
231 | struct btrfs_key first_key; | ||
232 | struct btrfs_key last_key; | ||
233 | |||
234 | btrfs_node_key_to_cpu(parent, &first_key, 0); | ||
235 | btrfs_node_key_to_cpu(parent, &last_key, parent_nritems - 1); | ||
236 | if (first_key.objectid != last_key.objectid) | ||
237 | return 0; | ||
238 | } | ||
239 | |||
231 | for (i = start_slot; i < end_slot; i++) { | 240 | for (i = start_slot; i < end_slot; i++) { |
232 | int close = 1; | 241 | int close = 1; |
242 | |||
233 | blocknr = btrfs_node_blockptr(parent, i); | 243 | blocknr = btrfs_node_blockptr(parent, i); |
234 | if (last_block == 0) | 244 | if (last_block == 0) |
235 | last_block = blocknr; | 245 | last_block = blocknr; |
@@ -898,7 +908,7 @@ static void reada_for_search(struct btrfs_root *root, struct btrfs_path *path, | |||
898 | u32 blocksize; | 908 | u32 blocksize; |
899 | u32 nscan = 0; | 909 | u32 nscan = 0; |
900 | 910 | ||
901 | if (level == 0) | 911 | if (level != 1) |
902 | return; | 912 | return; |
903 | 913 | ||
904 | if (!path->nodes[level]) | 914 | if (!path->nodes[level]) |
@@ -2370,7 +2380,7 @@ int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
2370 | } | 2380 | } |
2371 | 2381 | ||
2372 | /* delete the leaf if it is mostly empty */ | 2382 | /* delete the leaf if it is mostly empty */ |
2373 | if (used < BTRFS_LEAF_DATA_SIZE(root) / 3) { | 2383 | if (0 && used < BTRFS_LEAF_DATA_SIZE(root) / 3) { |
2374 | /* push_leaf_left fixes the path. | 2384 | /* push_leaf_left fixes the path. |
2375 | * make sure the path still points to our leaf | 2385 | * make sure the path still points to our leaf |
2376 | * for possible call to del_ptr below | 2386 | * for possible call to del_ptr below |