Skip to content

Commit 5a7d107

Browse files
naotakdave
authored andcommitted
btrfs: zoned: don't activate non-DATA BG on allocation
Now that a non-DATA block group is activated at write time, don't activate it on allocation time. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 6a8ebc7 commit 5a7d107

3 files changed

Lines changed: 8 additions & 30 deletions

File tree

fs/btrfs/block-group.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4089,7 +4089,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
40894089

40904090
if (IS_ERR(ret_bg)) {
40914091
ret = PTR_ERR(ret_bg);
4092-
} else if (from_extent_allocation) {
4092+
} else if (from_extent_allocation && (flags & BTRFS_BLOCK_GROUP_DATA)) {
40934093
/*
40944094
* New block group is likely to be used soon. Try to activate
40954095
* it now. Failure is OK for now.

fs/btrfs/extent-tree.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3690,7 +3690,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group,
36903690
}
36913691
spin_unlock(&block_group->lock);
36923692

3693-
if (!ret && !btrfs_zone_activate(block_group)) {
3693+
/* Metadata block group is activated at write time. */
3694+
if (!ret && (block_group->flags & BTRFS_BLOCK_GROUP_DATA) &&
3695+
!btrfs_zone_activate(block_group)) {
36943696
ret = 1;
36953697
/*
36963698
* May need to clear fs_info->{treelog,data_reloc}_bg.
@@ -3866,6 +3868,10 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl,
38663868
static int can_allocate_chunk_zoned(struct btrfs_fs_info *fs_info,
38673869
struct find_free_extent_ctl *ffe_ctl)
38683870
{
3871+
/* Block group's activeness is not a requirement for METADATA block groups. */
3872+
if (!(ffe_ctl->flags & BTRFS_BLOCK_GROUP_DATA))
3873+
return 0;
3874+
38693875
/* If we can activate new zone, just allocate a chunk and use it */
38703876
if (btrfs_can_activate_zone(fs_info->fs_devices, ffe_ctl->flags))
38713877
return 0;

fs/btrfs/space-info.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -761,18 +761,6 @@ static void flush_space(struct btrfs_fs_info *fs_info,
761761
break;
762762
case ALLOC_CHUNK:
763763
case ALLOC_CHUNK_FORCE:
764-
/*
765-
* For metadata space on zoned filesystem, reaching here means we
766-
* don't have enough space left in active_total_bytes. Try to
767-
* activate a block group first, because we may have inactive
768-
* block group already allocated.
769-
*/
770-
ret = btrfs_zoned_activate_one_bg(fs_info, space_info, false);
771-
if (ret < 0)
772-
break;
773-
else if (ret == 1)
774-
break;
775-
776764
trans = btrfs_join_transaction(root);
777765
if (IS_ERR(trans)) {
778766
ret = PTR_ERR(trans);
@@ -784,22 +772,6 @@ static void flush_space(struct btrfs_fs_info *fs_info,
784772
CHUNK_ALLOC_FORCE);
785773
btrfs_end_transaction(trans);
786774

787-
/*
788-
* For metadata space on zoned filesystem, allocating a new chunk
789-
* is not enough. We still need to activate the block * group.
790-
* Active the newly allocated block group by (maybe) finishing
791-
* a block group.
792-
*/
793-
if (ret == 1) {
794-
ret = btrfs_zoned_activate_one_bg(fs_info, space_info, true);
795-
/*
796-
* Revert to the original ret regardless we could finish
797-
* one block group or not.
798-
*/
799-
if (ret >= 0)
800-
ret = 1;
801-
}
802-
803775
if (ret > 0 || ret == -ENOSPC)
804776
ret = 0;
805777
break;

0 commit comments

Comments
 (0)