Btrfs: don't try to allocate from a block group that doesn't have enough space
authorJosef Bacik <josef@redhat.com>
Fri, 13 May 2011 15:07:12 +0000 (11:07 -0400)
committerJosef Bacik <josef@redhat.com>
Mon, 23 May 2011 17:03:15 +0000 (13:03 -0400)
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>
fs/btrfs/extent-tree.c

index 1ba2cc58eab5eca00562dc96a71a30d7027d5087..c8c318494deea99a5b2a46a1c0db648f94079095 100644 (file)
@@ -5159,6 +5159,14 @@ have_block_group:
                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