Skip to content

Commit a746cfd

Browse files
Josef Bacikgregkh
authored andcommitted
btrfs: don't use ctl->free_space for max_extent_size
commit fb5c39d upstream. max_extent_size is supposed to be the largest contiguous range for the space info, and ctl->free_space is the total free space in the block group. We need to keep track of these separately and _only_ use the max_free_space if we don't have a max_extent_size, as that means our original request was too large to search any of the block groups for and therefore wouldn't have a max_extent_size set. CC: [email protected] # 4.14+ Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4a351e7 commit a746cfd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/btrfs/extent-tree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7230,6 +7230,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info,
72307230
struct btrfs_block_group_cache *block_group = NULL;
72317231
u64 search_start = 0;
72327232
u64 max_extent_size = 0;
7233+
u64 max_free_space = 0;
72337234
u64 empty_cluster = 0;
72347235
struct btrfs_space_info *space_info;
72357236
int loop = 0;
@@ -7525,8 +7526,8 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info,
75257526
spin_lock(&ctl->tree_lock);
75267527
if (ctl->free_space <
75277528
num_bytes + empty_cluster + empty_size) {
7528-
if (ctl->free_space > max_extent_size)
7529-
max_extent_size = ctl->free_space;
7529+
max_free_space = max(max_free_space,
7530+
ctl->free_space);
75307531
spin_unlock(&ctl->tree_lock);
75317532
goto loop;
75327533
}
@@ -7693,6 +7694,8 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info,
76937694
}
76947695
out:
76957696
if (ret == -ENOSPC) {
7697+
if (!max_extent_size)
7698+
max_extent_size = max_free_space;
76967699
spin_lock(&space_info->lock);
76977700
space_info->max_extent_size = max_extent_size;
76987701
spin_unlock(&space_info->lock);

0 commit comments

Comments
 (0)