Skip to content

Commit

Permalink
Btrfs: don't try to allocate from a block group that doesn't have eno…
Browse files Browse the repository at this point in the history
…ugh space

If we have a very large filesystem, we can spend a lot of time in
find_free_extent just trying to allocate from empty block groups.  So instead
check to see if the block group even has enough space for the allocation, and if
not go on to the next block group.

Signed-off-by: Josef Bacik <josef@redhat.com>
  • Loading branch information
Josef Bacik committed May 23, 2011
1 parent 026fd31 commit cca1c81
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5159,6 +5159,14 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
if (unlikely(block_group->ro))
goto loop;

spin_lock(&block_group->tree_lock);
if (cached &&
block_group->free_space < num_bytes + empty_size) {
spin_unlock(&block_group->tree_lock);
goto loop;
}
spin_unlock(&block_group->tree_lock);

/*
* Ok we want to try and use the cluster allocator, so lets look
* there, unless we are on LOOP_NO_EMPTY_SIZE, since we will
Expand Down

0 comments on commit cca1c81

Please sign in to comment.