Commit 1cdda9b8 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: fix possible softlockup in the allocator

Like the cluster allocating stuff, we can lockup the box with the normal
allocation path.  This happens when we

1) Start to cache a block group that is severely fragmented, but has a decent
amount of free space.
2) Start to commit a transaction
3) Have the commit try and empty out some of the delalloc inodes with extents
that are relatively large.

The inodes will not be able to make the allocations because they will ask for
allocations larger than a contiguous area in the free space cache.  So we will
wait for more progress to be made on the block group, but since we're in a
commit the caching kthread won't make any more progress and it already has
enough free space that wait_block_group_cache_progress will just return.  So,
if we wait and fail to make the allocation the next time around, just loop and
go to the next block group.  This keeps us from getting stuck in a softlockup.
Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@redhat.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 61d92c32
...@@ -4028,6 +4028,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -4028,6 +4028,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
int loop = 0; int loop = 0;
bool found_uncached_bg = false; bool found_uncached_bg = false;
bool failed_cluster_refill = false; bool failed_cluster_refill = false;
bool failed_alloc = false;
WARN_ON(num_bytes < root->sectorsize); WARN_ON(num_bytes < root->sectorsize);
btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY); btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY);
...@@ -4232,14 +4233,23 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -4232,14 +4233,23 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
offset = btrfs_find_space_for_alloc(block_group, search_start, offset = btrfs_find_space_for_alloc(block_group, search_start,
num_bytes, empty_size); num_bytes, empty_size);
if (!offset && (cached || (!cached && /*
loop == LOOP_CACHING_NOWAIT))) { * If we didn't find a chunk, and we haven't failed on this
goto loop; * block group before, and this block group is in the middle of
} else if (!offset && (!cached && * caching and we are ok with waiting, then go ahead and wait
loop > LOOP_CACHING_NOWAIT)) { * for progress to be made, and set failed_alloc to true.
*
* If failed_alloc is true then we've already waited on this
* block group once and should move on to the next block group.
*/
if (!offset && !failed_alloc && !cached &&
loop > LOOP_CACHING_NOWAIT) {
wait_block_group_cache_progress(block_group, wait_block_group_cache_progress(block_group,
num_bytes + empty_size); num_bytes + empty_size);
failed_alloc = true;
goto have_block_group; goto have_block_group;
} else if (!offset) {
goto loop;
} }
checks: checks:
search_start = stripe_align(root, offset); search_start = stripe_align(root, offset);
...@@ -4287,6 +4297,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -4287,6 +4297,7 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
break; break;
loop: loop:
failed_cluster_refill = false; failed_cluster_refill = false;
failed_alloc = false;
btrfs_put_block_group(block_group); btrfs_put_block_group(block_group);
} }
up_read(&space_info->groups_sem); up_read(&space_info->groups_sem);
......
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