Skip to content

Commit 02444f2

Browse files
naotakdave
authored andcommitted
btrfs: zoned: optimize hint byte for zoned allocator
Writing sequentially to a huge file on btrfs on a SMR HDD revealed a decline of the performance (220 MiB/s to 30 MiB/s after 500 minutes). The performance goes down because of increased latency of the extent allocation, which is induced by a traversing of a lot of full block groups. So, this patch optimizes the ffe_ctl->hint_byte by choosing a block group with sufficient size from the active block group list, which does not contain full block groups. After applying the patch, the performance is maintained well. Fixes: 2eda570 ("btrfs: zoned: implement sequential extent allocation") CC: stable@vger.kernel.org # 5.15+ 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 b271fee commit 02444f2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,24 @@ static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
43114311
if (fs_info->data_reloc_bg)
43124312
ffe_ctl->hint_byte = fs_info->data_reloc_bg;
43134313
spin_unlock(&fs_info->relocation_bg_lock);
4314+
} else if (ffe_ctl->flags & BTRFS_BLOCK_GROUP_DATA) {
4315+
struct btrfs_block_group *block_group;
4316+
4317+
spin_lock(&fs_info->zone_active_bgs_lock);
4318+
list_for_each_entry(block_group, &fs_info->zone_active_bgs, active_bg_list) {
4319+
/*
4320+
* No lock is OK here because avail is monotinically
4321+
* decreasing, and this is just a hint.
4322+
*/
4323+
u64 avail = block_group->zone_capacity - block_group->alloc_offset;
4324+
4325+
if (block_group_bits(block_group, ffe_ctl->flags) &&
4326+
avail >= ffe_ctl->num_bytes) {
4327+
ffe_ctl->hint_byte = block_group->start;
4328+
break;
4329+
}
4330+
}
4331+
spin_unlock(&fs_info->zone_active_bgs_lock);
43144332
}
43154333

43164334
return 0;

0 commit comments

Comments
 (0)