Btrfs: seperate out btrfs_block_rsv_check out into 2 different functions
PATCH 1/1 Btrfs: seperate out btrfs_block_rsv_check out into 2 different functions
Currently btrfs_block_rsv_check does 2 things, it will either refill a block reserve like in the truncate or refill case, or it will check to see if there is enough space in the global reserve and possibly refill it. However because of overcommit we could be well overcommitting ourselves just to try and refill the global reserve, when really we should just be committing the transaction. So breack this out into btrfs_block_rsv_refill and btrfs_block_rsv_check. Refill will try to reserve more metadata if it can and btrfs_block_rsv_check will not, it will only tell you if the factor of the total space is still reserved. Thanks,
--- fs/btrfs/ctree.h | 4 +++- fs/btrfs/extent-tree.c | 41 +++++++++++++++++++++++++++-------------- fs/btrfs/free-space-cache.c | 2 +- fs/btrfs/inode.c | 4 ++-- fs/btrfs/relocation.c | 6 ++---- fs/btrfs/transaction.c | 4 ++-- 6 files changed, 37 insertions(+), 24 deletions(-)
fs/btrfs/ctree.h +3 -1
@@ -2252,8 +2252,10 @@ int btrfs_block_rsv_add(struct btrfs_root *root,struct btrfs_block_rsv *block_rsv, u64 num_bytes);int btrfs_block_rsv_check (struct btrfs_root *root, +struct btrfs_block_rsv *block_rsv,int min_factor); +int btrfs_block_rsv_refill (struct btrfs_root *root,struct btrfs_block_rsv *block_rsv, -u64 min_reserved,int min_factor,int flush); +u64 min_reserved);int btrfs_block_rsv_migrate (struct btrfs_block_rsv *src_rsv,struct btrfs_block_rsv *dst_rsv,u64 num_bytes);
fs/btrfs/extent-tree.c +27 -14
102 lines not on this page · raw message
fs/btrfs/free-space-cache.c +1 -1
@@ -203,7 +203,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root, rsv = trans->block_rsv; trans->block_rsv = root->orphan_block_rsv; - ret =btrfs_block_rsv_check (root, root->orphan_block_rsv,0 ,5 ,0 ); + ret =btrfs_block_rsv_check (root, root->orphan_block_rsv,5 );if (ret)return ret;
fs/btrfs/inode.c +2 -2
@@ -3604,7 +3604,7 @@ void btrfs_evict_inode(struct inode *inode)* doing the truncate. */ while (1 ) { - ret =btrfs_block_rsv_check (root, rsv, min_size,0 ,1 ); + ret =btrfs_block_rsv_refill (root, rsv, min_size);/* * Try and steal from the global reserve since we will
@@ -6603,7 +6603,7 @@ static int btrfs_truncate(struct inode *inode)btrfs_add_ordered_operation (trans, root, inode);while (1 ) { - ret =btrfs_block_rsv_check (root, rsv, min_size,0 ,1 ); + ret =btrfs_block_rsv_refill (root, rsv, min_size);if (ret) {/* * This can only happen with the original transaction we
fs/btrfs/relocation.c +2 -4
@@ -2041,8 +2041,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,BUG_ON (IS_ERR (trans)); trans->block_rsv = rc->block_rsv; - ret =btrfs_block_rsv_check (root, rc->block_rsv, min_reserved, -0 ,0 ); + ret =btrfs_block_rsv_refill (root, rc->block_rsv, min_reserved);if (ret) {BUG_ON (ret != -EAGAIN ); ret =btrfs_commit_transaction (trans, root);
@@ -3774,8 +3773,7 @@ restart: } } - ret =btrfs_block_rsv_check (rc->extent_root, rc->block_rsv,0 , -5 ,0 ); + ret =btrfs_block_rsv_check (rc->extent_root, rc->block_rsv,5 );if (ret <0 ) {if (ret != -EAGAIN ) { err = ret;
fs/btrfs/transaction.c +2 -2
@@ -418,8 +418,8 @@ static int should_end_transaction(struct btrfs_trans_handle *trans, struct btrfs_root *root) {int ret; - ret =btrfs_block_rsv_check (root, &root->fs_info->global_block_rsv,0 , -5 ,0 ); + + ret =btrfs_block_rsv_check (root, &root->fs_info->global_block_rsv,5 );return ret ?1 :0 ; }
Signature · 1 line
1.7.5.2