Skip to content

Commit

Permalink
Btrfs: Add block group pinned accounting back
Browse files Browse the repository at this point in the history
This patch adds a helper function 'update_pinned_extents' to
extent-tree.c. The usage of the helper function is similar to
'update_block_group',  the last parameter of the function indicates
pin vs unpin.

Signed-off-by: Chris Mason <[email protected]>
  • Loading branch information
ukernel authored and chrismason-xx committed Sep 25, 2008
1 parent 5103e94 commit 324ae4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
5 changes: 3 additions & 2 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ struct btrfs_block_group_cache {
struct btrfs_block_group_item item;
int data;
int cached;
u64 pinned;
};

struct btrfs_fs_info {
u8 fsid[BTRFS_FSID_SIZE];
struct btrfs_root *extent_root;
Expand Down Expand Up @@ -324,8 +324,9 @@ struct btrfs_fs_info {
struct completion kobj_unregister;
int do_barriers;
int closing;
};

u64 total_pinned;
};
/*
* in ram representation of the tree. extent_root is used for all allocations
* and for the extent tree extent_root root.
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info->btree_inode->i_mapping, GFP_NOFS);
fs_info->do_barriers = 1;
fs_info->closing = 0;
fs_info->total_pinned = 0;

INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
BTRFS_I(fs_info->btree_inode)->root = tree_root;
Expand Down
54 changes: 40 additions & 14 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,17 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
if (shint && (shint->data == data ||
shint->data == BTRFS_BLOCK_GROUP_MIXED)) {
used = btrfs_block_group_used(&shint->item);
if (used < div_factor(shint->key.offset, factor)) {
if (used + shint->pinned <
div_factor(shint->key.offset, factor)) {
return shint;
}
}
}
if (hint && (hint->data == data ||
hint->data == BTRFS_BLOCK_GROUP_MIXED)) {
used = btrfs_block_group_used(&hint->item);
if (used < div_factor(hint->key.offset, factor)) {
if (used + hint->pinned <
div_factor(hint->key.offset, factor)) {
return hint;
}
last = hint->key.objectid + hint->key.offset;
Expand Down Expand Up @@ -317,8 +319,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
free_check = cache->key.offset;
else
free_check = div_factor(cache->key.offset, factor);

if (used < free_check) {
if (used + cache->pinned < free_check) {
found_group = cache;
goto found;
}
Expand Down Expand Up @@ -664,6 +665,37 @@ static int update_block_group(struct btrfs_trans_handle *trans,
}
return 0;
}
static int update_pinned_extents(struct btrfs_root *root,
u64 bytenr, u64 num, int pin)
{
u64 len;
struct btrfs_block_group_cache *cache;
struct btrfs_fs_info *fs_info = root->fs_info;

if (pin) {
set_extent_dirty(&fs_info->pinned_extents,
bytenr, bytenr + num - 1, GFP_NOFS);
} else {
clear_extent_dirty(&fs_info->pinned_extents,
bytenr, bytenr + num - 1, GFP_NOFS);
}
while (num > 0) {
cache = btrfs_lookup_block_group(fs_info, bytenr);
WARN_ON(!cache);
len = min(num, cache->key.offset -
(bytenr - cache->key.objectid));
if (pin) {
cache->pinned += len;
fs_info->total_pinned += len;
} else {
cache->pinned -= len;
fs_info->total_pinned -= len;
}
bytenr += len;
num -= len;
}
return 0;
}

int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy)
{
Expand Down Expand Up @@ -691,19 +723,15 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
u64 start;
u64 end;
int ret;
struct extent_map_tree *pinned_extents = &root->fs_info->pinned_extents;
struct extent_map_tree *free_space_cache;

free_space_cache = &root->fs_info->free_space_cache;

while(1) {
ret = find_first_extent_bit(unpin, 0, &start, &end,
EXTENT_DIRTY);
if (ret)
break;

clear_extent_dirty(pinned_extents, start, end,
GFP_NOFS);
update_pinned_extents(root, start, end + 1 - start, 0);
clear_extent_dirty(unpin, start, end, GFP_NOFS);
set_extent_dirty(free_space_cache, start, end, GFP_NOFS);
}
Expand Down Expand Up @@ -761,8 +789,7 @@ static int pin_down_bytes(struct btrfs_root *root, u64 bytenr, u32 num_bytes,
}
free_extent_buffer(buf);
}
set_extent_dirty(&root->fs_info->pinned_extents,
bytenr, bytenr + num_bytes - 1, GFP_NOFS);
update_pinned_extents(root, bytenr, num_bytes, 1);
} else {
set_extent_bits(&root->fs_info->pending_del,
bytenr, bytenr + num_bytes - 1,
Expand Down Expand Up @@ -866,8 +893,7 @@ static int del_pending_extents(struct btrfs_trans_handle *trans, struct
EXTENT_LOCKED);
if (ret)
break;

set_extent_dirty(pinned_extents, start, end, GFP_NOFS);
update_pinned_extents(extent_root, start, end + 1 - start, 1);
clear_extent_bits(pending_del, start, end, EXTENT_LOCKED,
GFP_NOFS);
ret = __free_extent(trans, extent_root,
Expand Down Expand Up @@ -1579,7 +1605,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
sizeof(cache->item));
memcpy(&cache->key, &found_key, sizeof(found_key));
cache->cached = 0;

cache->pinned = 0;
key.objectid = found_key.objectid + found_key.offset;
btrfs_release_path(root, path);

Expand Down

0 comments on commit 324ae4d

Please sign in to comment.