Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128383
b: refs/heads/master
c: de428b6
h: refs/heads/master
i:
  128381: 58b3195
  128379: 3243e38
  128375: 32e4b92
  128367: 12ad5f4
  128351: bc9fd9c
  128319: f7e6059
  128255: ad8077d
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed May 18, 2007
1 parent 6960171 commit fe58e78
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 38 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 098f59c2512426926722a96f82af127bd91fb5e4
refs/heads/master: de428b63b16f9c74a24228a517713e8c65f79475
2 changes: 1 addition & 1 deletion trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh)
struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
struct btrfs_block_group_cache
*hint, u64 search_start,
int data);
int data, int owner);
int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
Expand Down
12 changes: 9 additions & 3 deletions trunk/fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,30 @@ static struct address_space_operations btree_aops = {
int readahead_tree_block(struct btrfs_root *root, u64 blocknr)
{
struct buffer_head *bh = NULL;
int ret = 0;

bh = btrfs_find_create_tree_block(root, blocknr);
if (!bh)
return 0;
if (buffer_uptodate(bh))
if (buffer_uptodate(bh)) {
ret = 1;
goto done;
if (test_set_buffer_locked(bh))
}
if (test_set_buffer_locked(bh)) {
ret = 1;
goto done;
}
if (!buffer_uptodate(bh)) {
get_bh(bh);
bh->b_end_io = end_buffer_read_sync;
submit_bh(READ, bh);
} else {
unlock_buffer(bh);
ret = 1;
}
done:
brelse(bh);
return 0;
return ret;
}

struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
Expand Down
76 changes: 62 additions & 14 deletions trunk/fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ static int finish_current_insert(struct btrfs_trans_handle *trans, struct
static int del_pending_extents(struct btrfs_trans_handle *trans, struct
btrfs_root *extent_root);

static void reada_extent_leaves(struct btrfs_root *root,
struct btrfs_path *path, u64 limit)
{
struct btrfs_node *node;
int i;
int nritems;
u64 item_objectid;
u64 blocknr;
int slot;
int ret;

if (!path->nodes[1])
return;
node = btrfs_buffer_node(path->nodes[1]);
slot = path->slots[1] + 1;
nritems = btrfs_header_nritems(&node->header);
for (i = slot; i < nritems && i < slot + 8; i++) {
item_objectid = btrfs_disk_key_objectid(&node->ptrs[i].key);
if (item_objectid > limit)
break;
blocknr = btrfs_node_blockptr(node, i);
ret = readahead_tree_block(root, blocknr);
if (ret)
break;
}
}

static int cache_block_group(struct btrfs_root *root,
struct btrfs_block_group_cache *block_group)
{
Expand All @@ -24,6 +51,7 @@ static int cache_block_group(struct btrfs_root *root,
u64 i;
u64 last = 0;
u64 hole_size;
u64 limit;
int found = 0;

root = root->fs_info->extent_root;
Expand All @@ -46,14 +74,17 @@ printk("cache block group %Lu\n", block_group->key.objectid);
return ret;
if (ret && path->slots[0] > 0)
path->slots[0]--;
limit = block_group->key.objectid + block_group->key.offset;
reada_extent_leaves(root, path, limit);
while(1) {
leaf = btrfs_buffer_leaf(path->nodes[0]);
slot = path->slots[0];
if (slot >= btrfs_header_nritems(&leaf->header)) {
reada_extent_leaves(root, path, limit);
ret = btrfs_next_leaf(root, path);
if (ret == 0)
if (ret == 0) {
continue;
else {
} else {
if (found) {
hole_size = block_group->key.objectid +
block_group->key.offset - last;
Expand Down Expand Up @@ -187,15 +218,15 @@ static u64 find_search_start(struct btrfs_root *root,
return max((*cache_ret)->last_alloc, search_start);
}
cache = btrfs_find_block_group(root, cache,
last + cache->key.offset - 1, 0);
last + cache->key.offset - 1, 0, 0);
*cache_ret = cache;
goto again;
}

struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
struct btrfs_block_group_cache
*hint, u64 search_start,
int data)
int data, int owner)
{
struct btrfs_block_group_cache *cache[8];
struct btrfs_block_group_cache *found_group = NULL;
Expand All @@ -207,6 +238,10 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
int i;
int ret;
int full_search = 0;
int factor = 8;

if (!owner)
factor = 5;

if (data)
radix = &info->block_group_data_radix;
Expand All @@ -219,14 +254,14 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
if (shint->data == data) {
used = btrfs_block_group_used(&shint->item);
if (used + shint->pinned <
(shint->key.offset * 8) / 10) {
(shint->key.offset * factor) / 10) {
return shint;
}
}
}
if (hint && hint->data == data) {
used = btrfs_block_group_used(&hint->item);
if (used + hint->pinned < (hint->key.offset * 8) / 10) {
if (used + hint->pinned < (hint->key.offset * factor) / 10) {
return hint;
}
if (used >= (hint->key.offset * 8) / 10) {
Expand Down Expand Up @@ -261,7 +296,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
cache[i]->key.offset;
used = btrfs_block_group_used(&cache[i]->item);
if (used + cache[i]->pinned <
(cache[i]->key.offset * 8) / 10) {
(cache[i]->key.offset * factor) / 10) {
found_group = cache[i];
goto found;
}
Expand All @@ -272,6 +307,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
BTRFS_BLOCK_GROUP_AVAIL);
}
}
cond_resched();
}
last = hint_last;
again:
Expand All @@ -295,13 +331,16 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
BTRFS_BLOCK_GROUP_AVAIL);
}
}
cond_resched();
}
if (!full_search) {
printk("find block group doing full search data %d start %Lu\n", data, search_start);
last = search_start;
full_search = 1;
goto again;
}
if (!found_group) {
printk("find block group bailing to zero data %d\n", data);
ret = radix_tree_gang_lookup(radix,
(void **)&found_group, 0, 1);
BUG_ON(ret != 1);
Expand Down Expand Up @@ -554,8 +593,8 @@ static int update_block_group(struct btrfs_trans_handle *trans,
blocknr + i);
}
}
if (old_val < (cache->key.offset * 6) / 10 &&
old_val + num >= (cache->key.offset * 6) / 10) {
if (old_val < (cache->key.offset * 5) / 10 &&
old_val + num >= (cache->key.offset * 5) / 10) {
printk("group %Lu now available\n", cache->key.objectid);
radix_tree_tag_set(cache->radix,
cache->key.objectid +
Expand Down Expand Up @@ -842,6 +881,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
int level;
struct btrfs_block_group_cache *block_group;
int full_scan = 0;
u64 limit;

path = btrfs_alloc_path();
ins->flags = 0;
Expand All @@ -858,11 +898,11 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
if (search_start) {
block_group = lookup_block_group(info, search_start);
block_group = btrfs_find_block_group(root, block_group,
search_start, data);
search_start, data, 1);
} else {
block_group = btrfs_find_block_group(root,
trans->block_group, 0,
data);
data, 1);
}

check_failed:
Expand Down Expand Up @@ -916,6 +956,12 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
info->extent_tree_prealloc_nr = 0;
total_found = 0;
}
if (start_found)
limit = last_block +
block_group->key.offset / 2;
else
limit = search_start +
block_group->key.offset / 2;
ret = btrfs_next_leaf(root, path);
if (ret == 0)
continue;
Expand Down Expand Up @@ -960,6 +1006,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
}
next:
path->slots[0]++;
cond_resched();
}
// FIXME -ENOSPC
check_pending:
Expand Down Expand Up @@ -1049,7 +1096,8 @@ printk("doing full scan!\n");
block_group = lookup_block_group(info, search_start);
if (!full_scan)
block_group = btrfs_find_block_group(root, block_group,
search_start, data);
search_start, data, 0);
cond_resched();
goto check_failed;

error:
Expand Down Expand Up @@ -1102,7 +1150,7 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
* in the correct block group.
*/
if (data) {
ret = find_free_extent(trans, root, 0, search_start,
ret = find_free_extent(trans, root, 0, 0,
search_end, &prealloc_key, 0);
if (ret) {
return ret;
Expand Down Expand Up @@ -1173,7 +1221,7 @@ struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct buffer_head *buf;

ret = btrfs_alloc_extent(trans, root, root->root_key.objectid,
1, 0, (unsigned long)-1, &ins, 0);
1, hint, (unsigned long)-1, &ins, 0);
if (ret) {
BUG();
return NULL;
Expand Down
Loading

0 comments on commit fe58e78

Please sign in to comment.