aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-05-10 11:24:42 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-05-10 11:24:42 -0400
commit8d7be552a733e53135a91d2d28f57ab87dc0e889 (patch)
tree62126fc82875b81f0132392f1d1833ceb960e1fb /fs
parente37c9e6921207cf503634b06bee37ecb7904408d (diff)
Btrfs: fix check_node and check_leaf to use less cpu
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.c44
-rw-r--r--fs/btrfs/extent-tree.c6
2 files changed, 29 insertions, 21 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index dbd3f636dd3d..990d297a7a13 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -130,15 +130,17 @@ static int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
130static int check_node(struct btrfs_root *root, struct btrfs_path *path, 130static int check_node(struct btrfs_root *root, struct btrfs_path *path,
131 int level) 131 int level)
132{ 132{
133 int i;
134 struct btrfs_node *parent = NULL; 133 struct btrfs_node *parent = NULL;
135 struct btrfs_node *node = btrfs_buffer_node(path->nodes[level]); 134 struct btrfs_node *node = btrfs_buffer_node(path->nodes[level]);
136 int parent_slot; 135 int parent_slot;
136 int slot;
137 struct btrfs_key cpukey;
137 u32 nritems = btrfs_header_nritems(&node->header); 138 u32 nritems = btrfs_header_nritems(&node->header);
138 139
139 if (path->nodes[level + 1]) 140 if (path->nodes[level + 1])
140 parent = btrfs_buffer_node(path->nodes[level + 1]); 141 parent = btrfs_buffer_node(path->nodes[level + 1]);
141 parent_slot = path->slots[level + 1]; 142 parent_slot = path->slots[level + 1];
143 slot = path->slots[level];
142 BUG_ON(nritems == 0); 144 BUG_ON(nritems == 0);
143 if (parent) { 145 if (parent) {
144 struct btrfs_disk_key *parent_key; 146 struct btrfs_disk_key *parent_key;
@@ -149,10 +151,13 @@ static int check_node(struct btrfs_root *root, struct btrfs_path *path,
149 btrfs_header_blocknr(&node->header)); 151 btrfs_header_blocknr(&node->header));
150 } 152 }
151 BUG_ON(nritems > BTRFS_NODEPTRS_PER_BLOCK(root)); 153 BUG_ON(nritems > BTRFS_NODEPTRS_PER_BLOCK(root));
152 for (i = 0; nritems > 1 && i < nritems - 2; i++) { 154 if (slot != 0) {
153 struct btrfs_key cpukey; 155 btrfs_disk_key_to_cpu(&cpukey, &node->ptrs[slot - 1].key);
154 btrfs_disk_key_to_cpu(&cpukey, &node->ptrs[i + 1].key); 156 BUG_ON(comp_keys(&node->ptrs[slot].key, &cpukey) <= 0);
155 BUG_ON(comp_keys(&node->ptrs[i].key, &cpukey) >= 0); 157 }
158 if (slot < nritems - 1) {
159 btrfs_disk_key_to_cpu(&cpukey, &node->ptrs[slot + 1].key);
160 BUG_ON(comp_keys(&node->ptrs[slot].key, &cpukey) >= 0);
156 } 161 }
157 return 0; 162 return 0;
158} 163}
@@ -160,10 +165,12 @@ static int check_node(struct btrfs_root *root, struct btrfs_path *path,
160static int check_leaf(struct btrfs_root *root, struct btrfs_path *path, 165static int check_leaf(struct btrfs_root *root, struct btrfs_path *path,
161 int level) 166 int level)
162{ 167{
163 int i;
164 struct btrfs_leaf *leaf = btrfs_buffer_leaf(path->nodes[level]); 168 struct btrfs_leaf *leaf = btrfs_buffer_leaf(path->nodes[level]);
165 struct btrfs_node *parent = NULL; 169 struct btrfs_node *parent = NULL;
166 int parent_slot; 170 int parent_slot;
171 int slot = path->slots[0];
172 struct btrfs_key cpukey;
173
167 u32 nritems = btrfs_header_nritems(&leaf->header); 174 u32 nritems = btrfs_header_nritems(&leaf->header);
168 175
169 if (path->nodes[level + 1]) 176 if (path->nodes[level + 1])
@@ -182,19 +189,20 @@ static int check_leaf(struct btrfs_root *root, struct btrfs_path *path,
182 BUG_ON(btrfs_node_blockptr(parent, parent_slot) != 189 BUG_ON(btrfs_node_blockptr(parent, parent_slot) !=
183 btrfs_header_blocknr(&leaf->header)); 190 btrfs_header_blocknr(&leaf->header));
184 } 191 }
185 for (i = 0; nritems > 1 && i < nritems - 2; i++) { 192 if (slot != 0) {
186 struct btrfs_key cpukey; 193 btrfs_disk_key_to_cpu(&cpukey, &leaf->items[slot - 1].key);
187 btrfs_disk_key_to_cpu(&cpukey, &leaf->items[i + 1].key); 194 BUG_ON(comp_keys(&leaf->items[slot].key, &cpukey) <= 0);
188 BUG_ON(comp_keys(&leaf->items[i].key, 195 BUG_ON(btrfs_item_offset(leaf->items + slot - 1) !=
189 &cpukey) >= 0); 196 btrfs_item_end(leaf->items + slot));
190 BUG_ON(btrfs_item_offset(leaf->items + i) != 197 }
191 btrfs_item_end(leaf->items + i + 1)); 198 if (slot < nritems - 1) {
192 if (i == 0) { 199 btrfs_disk_key_to_cpu(&cpukey, &leaf->items[slot + 1].key);
193 BUG_ON(btrfs_item_offset(leaf->items + i) + 200 BUG_ON(comp_keys(&leaf->items[slot].key, &cpukey) >= 0);
194 btrfs_item_size(leaf->items + i) != 201 BUG_ON(btrfs_item_offset(leaf->items + slot) !=
195 BTRFS_LEAF_DATA_SIZE(root)); 202 btrfs_item_end(leaf->items + slot + 1));
196 }
197 } 203 }
204 BUG_ON(btrfs_item_offset(leaf->items) +
205 btrfs_item_size(leaf->items) != BTRFS_LEAF_DATA_SIZE(root));
198 return 0; 206 return 0;
199} 207}
200 208
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 3ac9da453472..1497ff98f0d3 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -235,7 +235,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
235 hint->key.offset - 1, 235 hint->key.offset - 1,
236 BTRFS_BLOCK_GROUP_AVAIL); 236 BTRFS_BLOCK_GROUP_AVAIL);
237 } 237 }
238 last = hint->key.offset * 2; 238 last = hint->key.offset * 3;
239 if (hint->key.objectid >= last) 239 if (hint->key.objectid >= last)
240 last = max(search_start + hint->key.offset - 1, 240 last = max(search_start + hint->key.offset - 1,
241 hint->key.objectid - last); 241 hint->key.objectid - last);
@@ -554,8 +554,8 @@ static int update_block_group(struct btrfs_trans_handle *trans,
554 blocknr + i); 554 blocknr + i);
555 } 555 }
556 } 556 }
557 if (old_val < (cache->key.offset * 8) / 10 && 557 if (old_val < (cache->key.offset * 6) / 10 &&
558 old_val + num >= (cache->key.offset * 8) / 10) { 558 old_val + num >= (cache->key.offset * 6) / 10) {
559printk("group %Lu now available\n", cache->key.objectid); 559printk("group %Lu now available\n", cache->key.objectid);
560 radix_tree_tag_set(cache->radix, 560 radix_tree_tag_set(cache->radix,
561 cache->key.objectid + 561 cache->key.objectid +