Skip to contentSkip to conversation

Btrfs: throttle transactions based on dirty bgs

PATCH New Josef Bacik 1 participant 1 message Feb 24, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: throttle transactions based on dirty bgs

When we delete large files that span many block groups we can run short on the global reserve as we use it to account for space in the csum tree as well as the extent tree. If our files span many block groups then we can get into a situation where we don't have enough room to update all the block groups and we abort the transaction. So keep track of the number of dirty block groups and use that space in seeing if we have enough global reserve. Thanks,

---
 fs/btrfs/extent-tree.c | 3 +++
 fs/btrfs/transaction.c | 1 +
 fs/btrfs/transaction.h | 1 +
 3 files changed, 5 insertions(+)
fs/btrfs/extent-tree.c +3 -0
index 89f1726..b2f7cf4 100644
@@ -2632,6 +2632,7 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
 {
 	struct btrfs_block_rsv *global_rsv;
 	u64 num_heads = trans->transaction->delayed_refs.num_heads_ready;
+	u64 num_dirty_bgs = trans->transaction->num_dirty_bgs;
 	u64 num_bytes;
 	int ret = 0;
 
@@ -2640,6 +2641,7 @@ int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans,
 	if (num_heads > 1)
 		num_bytes += (num_heads - 1) * root->nodesize;
 	num_bytes <<= 1;
+	num_bytes += btrfs_calc_trans_metadata_size(root, num_dirty_bgs);
 	global_rsv = &root->fs_info->global_block_rsv;
 
 	/*
@@ -5365,6 +5367,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
 			if (list_empty(&cache->dirty_list)) {
 				list_add_tail(&cache->dirty_list,
 					      &trans->transaction->dirty_bgs);
+				trans->transaction->num_dirty_bgs++;
 				btrfs_get_block_group(cache);
 			}
 			spin_unlock(&trans->transaction->dirty_bgs_lock);
fs/btrfs/transaction.c +1 -0
index e0faf80..822a26e 100644
@@ -249,6 +249,7 @@ loop:
 	INIT_LIST_HEAD(&cur_trans->switch_commits);
 	INIT_LIST_HEAD(&cur_trans->pending_ordered);
 	INIT_LIST_HEAD(&cur_trans->dirty_bgs);
+	cur_trans->num_dirty_bgs = 0;
 	spin_lock_init(&cur_trans->dirty_bgs_lock);
 	list_add_tail(&cur_trans->list, &fs_info->trans_list);
 	extent_io_tree_init(&cur_trans->dirty_pages,
fs/btrfs/transaction.h +1 -0
index 3305451..8ac29f0 100644
@@ -59,6 +59,7 @@ struct btrfs_transaction {
 	struct list_head pending_ordered;
 	struct list_head switch_commits;
 	struct list_head dirty_bgs;
+	u64 num_dirty_bgs;
 	spinlock_t dirty_bgs_lock;
 	struct btrfs_delayed_ref_root delayed_refs;
 	int aborted;
Signature · 1 line
1.8.3.1