Skip to content

Commit cb723e4

Browse files
Josef Bacikmasoncl
authored andcommitted
Btrfs: reserve space for block groups
This changes our delayed refs calculations to include the space needed to write back dirty block groups. Signed-off-by: Chris Mason <[email protected]>
1 parent 28f75a0 commit cb723e4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

fs/btrfs/extent-tree.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,8 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
26572657
struct btrfs_block_rsv *global_rsv;
26582658
u64 num_heads = trans->transaction->delayed_refs.num_heads_ready;
26592659
u64 csum_bytes = trans->transaction->delayed_refs.pending_csums;
2660-
u64 num_bytes;
2660+
u64 num_dirty_bgs = trans->transaction->num_dirty_bgs;
2661+
u64 num_bytes, num_dirty_bgs_bytes;
26612662
int ret = 0;
26622663

26632664
num_bytes = btrfs_calc_trans_metadata_size(root, 1);
@@ -2666,17 +2667,21 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
26662667
num_bytes += (num_heads - 1) * root->nodesize;
26672668
num_bytes <<= 1;
26682669
num_bytes += btrfs_csum_bytes_to_leaves(root, csum_bytes) * root->nodesize;
2670+
num_dirty_bgs_bytes = btrfs_calc_trans_metadata_size(root,
2671+
num_dirty_bgs);
26692672
global_rsv = &root->fs_info->global_block_rsv;
26702673

26712674
/*
26722675
* If we can't allocate any more chunks lets make sure we have _lots_ of
26732676
* wiggle room since running delayed refs can create more delayed refs.
26742677
*/
2675-
if (global_rsv->space_info->full)
2678+
if (global_rsv->space_info->full) {
2679+
num_dirty_bgs_bytes <<= 1;
26762680
num_bytes <<= 1;
2681+
}
26772682

26782683
spin_lock(&global_rsv->lock);
2679-
if (global_rsv->reserved <= num_bytes)
2684+
if (global_rsv->reserved <= num_bytes + num_dirty_bgs_bytes)
26802685
ret = 1;
26812686
spin_unlock(&global_rsv->lock);
26822687
return ret;
@@ -5408,6 +5413,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
54085413
if (list_empty(&cache->dirty_list)) {
54095414
list_add_tail(&cache->dirty_list,
54105415
&trans->transaction->dirty_bgs);
5416+
trans->transaction->num_dirty_bgs++;
54115417
btrfs_get_block_group(cache);
54125418
}
54135419
spin_unlock(&trans->transaction->dirty_bgs_lock);

fs/btrfs/transaction.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ static noinline int join_transaction(struct btrfs_root *root, unsigned int type)
251251
INIT_LIST_HEAD(&cur_trans->switch_commits);
252252
INIT_LIST_HEAD(&cur_trans->pending_ordered);
253253
INIT_LIST_HEAD(&cur_trans->dirty_bgs);
254+
cur_trans->num_dirty_bgs = 0;
254255
spin_lock_init(&cur_trans->dirty_bgs_lock);
255256
list_add_tail(&cur_trans->list, &fs_info->trans_list);
256257
extent_io_tree_init(&cur_trans->dirty_pages,

fs/btrfs/transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct btrfs_transaction {
6464
struct list_head pending_ordered;
6565
struct list_head switch_commits;
6666
struct list_head dirty_bgs;
67+
u64 num_dirty_bgs;
6768
spinlock_t dirty_bgs_lock;
6869
struct btrfs_delayed_ref_root delayed_refs;
6970
int aborted;

0 commit comments

Comments
 (0)