mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-23 07:27:30 -04:00
btrfs: zoned: always set data_relocation_bg
When searching for a data relocation block-group on mount, btrfs_zoned_reserve_data_reloc_bg() is looking for the first empty DATA block-group. But it first checks if the block-group is empty and if yes continues the search, and then checks if it is the first DATA block-group. There is actually no point in looking for the second empty DATA block group as new DATA allocations will just allocate a new chunk for it. Pick the first DATA block-group without any allocations done and set it as relocation block-group. At first, the commit694ce5e143("btrfs: zoned: reserve data_reloc block group on mount") introduced the functionality. At that time, we took second unused (used == 0) block group, as the first one might be a block group used for normal data. Later, commitdaa0fde322("btrfs: zoned: fix data relocation block group reservation") switched to look for an empty block group (alloc_offset == 0). At this point, there is no reason taking the second one anymore. So, this commit is fixing an issue in commitdaa0fde322. Reviewed-by: Boris Burkov <boris@bur.io> Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
@@ -2765,7 +2765,6 @@ void btrfs_zoned_reserve_data_reloc_bg(struct btrfs_fs_info *fs_info)
|
||||
struct btrfs_block_group *bg;
|
||||
struct list_head *bg_list;
|
||||
u64 alloc_flags;
|
||||
bool first = true;
|
||||
bool did_chunk_alloc = false;
|
||||
int index;
|
||||
int ret;
|
||||
@@ -2782,18 +2781,13 @@ void btrfs_zoned_reserve_data_reloc_bg(struct btrfs_fs_info *fs_info)
|
||||
alloc_flags = btrfs_get_alloc_profile(fs_info, space_info->flags);
|
||||
index = btrfs_bg_flags_to_raid_index(alloc_flags);
|
||||
|
||||
/* Scan the data space_info to find empty block groups. Take the second one. */
|
||||
again:
|
||||
bg_list = &space_info->block_groups[index];
|
||||
list_for_each_entry(bg, bg_list, list) {
|
||||
|
||||
if (bg->alloc_offset != 0)
|
||||
continue;
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (space_info == data_sinfo) {
|
||||
/* Migrate the block group to the data relocation space_info. */
|
||||
struct btrfs_space_info *reloc_sinfo = data_sinfo->sub_group[0];
|
||||
@@ -2805,8 +2799,6 @@ void btrfs_zoned_reserve_data_reloc_bg(struct btrfs_fs_info *fs_info)
|
||||
|
||||
down_write(&space_info->groups_sem);
|
||||
list_del_init(&bg->list);
|
||||
/* We can assume this as we choose the second empty one. */
|
||||
ASSERT(!list_empty(&space_info->block_groups[index]));
|
||||
up_write(&space_info->groups_sem);
|
||||
|
||||
spin_lock(&space_info->lock);
|
||||
@@ -2851,7 +2843,6 @@ void btrfs_zoned_reserve_data_reloc_bg(struct btrfs_fs_info *fs_info)
|
||||
* We allocated a new block group in the data relocation space_info. We
|
||||
* can take that one.
|
||||
*/
|
||||
first = false;
|
||||
did_chunk_alloc = true;
|
||||
goto again;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user