btrfs: zoned: fix zone activation logic
cover btrfs: zoned: fix zone activation logic
btrfs_zone_activate() "continue"s on seeing a devie without max_active_zone restriction, and it never set the block group as active if the block group does not contain a device with the restriction.
While it still return true and make the allocation works, it is confusing for other code and it is waste of time to iterate the loop every time btrfs_zone_activate() is called.
Also, there is a non-changing condition check in the loop.
Fix them with this series.
Naohiro Aota (2):
btrfs: zoned: move non-changing condition check out of the loop
btrfs: zoned: activate block group properly on unlimited active zone
device
fs/btrfs/zoned.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/2 btrfs: zoned: move non-changing condition check out of the loop
btrfs_zone_activate() checks if block_group->alloc_offset == block_group->zone_capacity every time it iterates the loop. But, it is not depending on the index. Move out the check and do it only once.
--- fs/btrfs/zoned.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/zoned.c +6 -6
@@ -1835,6 +1835,12 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) goto out_unlock; } +/* No space left */ +if (block_group->alloc_offset == block_group->zone_capacity) { + ret = false; + goto out_unlock; + } +for (i =0 ; i < map->num_stripes; i++) { device = map->stripes[i].dev; physical = map->stripes[i].physical;
@@ -1842,12 +1848,6 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)if (device->zone_info->max_active_zones ==0 )continue ; -/* No space left */ -if (block_group->alloc_offset == block_group->zone_capacity) { - ret = false; - goto out_unlock; - } -if (!btrfs_dev_set_active_zone (device, physical)) {/* Cannot activate the zone */ ret = false;
Signature · 1 line
2.35.1
PATCH 2/2 btrfs: zoned: activate block group properly on unlimited active zone device
In reply to Naohiro Aotabtrfs_zone_activate() checks if it activated all the underlying zones in the loop. However, that check never hit on an unlimited activate zone device (max_active_zones == 0).
Fortunately, it still works without ENOSPC because btrfs_zone_activate() returns true in the end, even if block_group->zone_is_active == 0. But, it is confusing to have non zone_is_active block group still usable for allocation. Also, we are wasting CPU time to iterate the loop every time btrfs_zone_activate() is called for the BGs.
Since error case in the loop is handled by out_unlock, we can just set zone_is_active and do the list stuff after the loop.
--- fs/btrfs/zoned.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
fs/btrfs/zoned.c +8 -14
@@ -1853,24 +1853,18 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) ret = false; goto out_unlock; } - -/* Successfully activated all the zones */ -if (i == map->num_stripes -1 ) - block_group->zone_is_active =1 ; - - } + +/* Successfully activated all the zones */ + block_group->zone_is_active =1 ;spin_unlock (&block_group->lock); -if (block_group->zone_is_active) { -/* For the active block group list */ -btrfs_get_block_group (block_group); +/* For the active block group list */ +btrfs_get_block_group (block_group); -spin_lock (&fs_info->zone_active_bgs_lock); -list_add_tail (&block_group->active_bg_list, - &fs_info->zone_active_bgs); -spin_unlock (&fs_info->zone_active_bgs_lock); - } +spin_lock (&fs_info->zone_active_bgs_lock); +list_add_tail (&block_group->active_bg_list, &fs_info->zone_active_bgs); +spin_unlock (&fs_info->zone_active_bgs_lock);return true;
Signature · 1 line
2.35.1
Quoted 8 lines · Naohiro Aota
btrfs_zone_activate()"continue"s on seeing a devie withoutmax_active_zonerestriction, and it never set the block group as active if the block group does not contain a device with the restriction.While it still return true and make the allocation works, it is confusing for other code and it is waste of time to iterate the loop every time
btrfs_zone_activate()is called.
Quoted 8 lines
Also, there is a non-changing condition check in the loop.
Fix them with this series.
Naohiro Aota (2):
btrfs: zoned: move non-changing condition check out of the loop
btrfs: zoned: activate block group properly on unlimited active zone
device
There's a minor conflict with the other series fixing the zone finish but this 2 patch series is a clear regression so I'll take it first for rc, not sure about the other yet.
Quoted 13 lines · David Sterba
Quoted 12 lines · Naohiro Aota
btrfs_zone_activate()"continue"s on seeing a devie withoutmax_active_zonerestriction, and it never set the block group as active if the block group does not contain a device with the restriction.While it still return true and make the allocation works, it is confusing for other code and it is waste of time to iterate the loop every time
btrfs_zone_activate()is called.Also, there is a non-changing condition check in the loop.
Fix them with this series.
Quoted 8 lines
Quoted 4 lines
Naohiro Aota (2):
btrfs: zoned: move non-changing condition check out of the loop
btrfs: zoned: activate block group properly on unlimited active zone
deviceThere's a minor conflict with the other series fixing the zone finish but this 2 patch series is a clear regression so I'll take it first for rc, not sure about the other yet.
Oh, sorry for confusion. As noted in "btrfs: zoned: fixes for zone finishing" series, that series depends on this series as they both touch the btrfs_zone_activate() function.