Commit d89dbefb authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: check if there are free block groups for commit

may_commit_transaction will skip committing the transaction if we don't
have enough pinned space or if we're trying to find space for a SYSTEM
chunk.  However, if we have pending free block groups in this transaction
we still want to commit as we may be able to allocate a chunk to make
our reservation.  So instead of just returning ENOSPC, check if we have
free block groups pending, and if so commit the transaction to allow us
to use that free space.
Reviewed-by: default avatarOmar Sandoval <osandov@fb.com>
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 3f93aef5
...@@ -4865,8 +4865,17 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, ...@@ -4865,8 +4865,17 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
if (!bytes_needed) if (!bytes_needed)
return 0; return 0;
/* See if there is enough pinned space to make this reservation */ trans = btrfs_join_transaction(fs_info->extent_root);
if (__percpu_counter_compare(&space_info->total_bytes_pinned, if (IS_ERR(trans))
return PTR_ERR(trans);
/*
* See if there is enough pinned space to make this reservation, or if
* we have block groups that are going to be freed, allowing us to
* possibly do a chunk allocation the next loop through.
*/
if (test_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags) ||
__percpu_counter_compare(&space_info->total_bytes_pinned,
bytes_needed, bytes_needed,
BTRFS_TOTAL_BYTES_PINNED_BATCH) >= 0) BTRFS_TOTAL_BYTES_PINNED_BATCH) >= 0)
goto commit; goto commit;
...@@ -4876,7 +4885,7 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, ...@@ -4876,7 +4885,7 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
* this reservation. * this reservation.
*/ */
if (space_info != delayed_rsv->space_info) if (space_info != delayed_rsv->space_info)
return -ENOSPC; goto enospc;
spin_lock(&delayed_rsv->lock); spin_lock(&delayed_rsv->lock);
reclaim_bytes += delayed_rsv->reserved; reclaim_bytes += delayed_rsv->reserved;
...@@ -4891,16 +4900,14 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, ...@@ -4891,16 +4900,14 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
if (__percpu_counter_compare(&space_info->total_bytes_pinned, if (__percpu_counter_compare(&space_info->total_bytes_pinned,
bytes_needed, bytes_needed,
BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0) { BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0)
return -ENOSPC; goto enospc;
}
commit: commit:
trans = btrfs_join_transaction(fs_info->extent_root);
if (IS_ERR(trans))
return -ENOSPC;
return btrfs_commit_transaction(trans); return btrfs_commit_transaction(trans);
enospc:
btrfs_end_transaction(trans);
return -ENOSPC;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment