* [PATCH 1/2] btrfs: zoned: split out prepare_allocation_zoned()
2023-12-18 16:01 [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton Naohiro Aota
@ 2023-12-18 16:02 ` Naohiro Aota
2023-12-18 16:02 ` [PATCH 2/2] btrfs: zoned: optimize hint byte for zoned allocator Naohiro Aota
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Naohiro Aota @ 2023-12-18 16:02 UTC (permalink / raw)
To: linux-btrfs; +Cc: Naohiro Aota
Split out prepare_allocation_zoned() for further extension. While at it,
optimize the if-branch a bit.
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
fs/btrfs/extent-tree.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f396aba92c57..d260b970bec7 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4298,6 +4298,24 @@ static int prepare_allocation_clustered(struct btrfs_fs_info *fs_info,
return 0;
}
+static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
+ struct find_free_extent_ctl *ffe_ctl)
+{
+ if (ffe_ctl->for_treelog) {
+ spin_lock(&fs_info->treelog_bg_lock);
+ if (fs_info->treelog_bg)
+ ffe_ctl->hint_byte = fs_info->treelog_bg;
+ spin_unlock(&fs_info->treelog_bg_lock);
+ } else if (ffe_ctl->for_data_reloc) {
+ spin_lock(&fs_info->relocation_bg_lock);
+ if (fs_info->data_reloc_bg)
+ ffe_ctl->hint_byte = fs_info->data_reloc_bg;
+ spin_unlock(&fs_info->relocation_bg_lock);
+ }
+
+ return 0;
+}
+
static int prepare_allocation(struct btrfs_fs_info *fs_info,
struct find_free_extent_ctl *ffe_ctl,
struct btrfs_space_info *space_info,
@@ -4308,19 +4326,7 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info,
return prepare_allocation_clustered(fs_info, ffe_ctl,
space_info, ins);
case BTRFS_EXTENT_ALLOC_ZONED:
- if (ffe_ctl->for_treelog) {
- spin_lock(&fs_info->treelog_bg_lock);
- if (fs_info->treelog_bg)
- ffe_ctl->hint_byte = fs_info->treelog_bg;
- spin_unlock(&fs_info->treelog_bg_lock);
- }
- if (ffe_ctl->for_data_reloc) {
- spin_lock(&fs_info->relocation_bg_lock);
- if (fs_info->data_reloc_bg)
- ffe_ctl->hint_byte = fs_info->data_reloc_bg;
- spin_unlock(&fs_info->relocation_bg_lock);
- }
- return 0;
+ return prepare_allocation_zoned(fs_info, ffe_ctl);
default:
BUG();
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] btrfs: zoned: optimize hint byte for zoned allocator
2023-12-18 16:01 [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton Naohiro Aota
2023-12-18 16:02 ` [PATCH 1/2] btrfs: zoned: split out prepare_allocation_zoned() Naohiro Aota
@ 2023-12-18 16:02 ` Naohiro Aota
2023-12-18 16:21 ` [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton Johannes Thumshirn
2024-01-04 15:45 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: Naohiro Aota @ 2023-12-18 16:02 UTC (permalink / raw)
To: linux-btrfs; +Cc: Naohiro Aota
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: 2eda57089ea3 ("btrfs: zoned: implement sequential extent allocation")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
fs/btrfs/extent-tree.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d260b970bec7..6d680031211a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4311,6 +4311,24 @@ static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
if (fs_info->data_reloc_bg)
ffe_ctl->hint_byte = fs_info->data_reloc_bg;
spin_unlock(&fs_info->relocation_bg_lock);
+ } else if (ffe_ctl->flags & BTRFS_BLOCK_GROUP_DATA) {
+ struct btrfs_block_group *block_group;
+
+ spin_lock(&fs_info->zone_active_bgs_lock);
+ list_for_each_entry(block_group, &fs_info->zone_active_bgs, active_bg_list) {
+ /*
+ * No lock is OK here because avail is monotinically
+ * decreasing, and this is just a hint.
+ */
+ u64 avail = block_group->zone_capacity - block_group->alloc_offset;
+
+ if (block_group_bits(block_group, ffe_ctl->flags) &&
+ avail >= ffe_ctl->num_bytes) {
+ ffe_ctl->hint_byte = block_group->start;
+ break;
+ }
+ }
+ spin_unlock(&fs_info->zone_active_bgs_lock);
}
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton
2023-12-18 16:01 [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton Naohiro Aota
2023-12-18 16:02 ` [PATCH 1/2] btrfs: zoned: split out prepare_allocation_zoned() Naohiro Aota
2023-12-18 16:02 ` [PATCH 2/2] btrfs: zoned: optimize hint byte for zoned allocator Naohiro Aota
@ 2023-12-18 16:21 ` Johannes Thumshirn
2024-01-04 15:45 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2023-12-18 16:21 UTC (permalink / raw)
To: Naohiro Aota, linux-btrfs@vger.kernel.org
For the series,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton
2023-12-18 16:01 [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton Naohiro Aota
` (2 preceding siblings ...)
2023-12-18 16:21 ` [PATCH 0/2] btrfs: zoned: fix bandwidth degradaton Johannes Thumshirn
@ 2024-01-04 15:45 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2024-01-04 15:45 UTC (permalink / raw)
To: Naohiro Aota; +Cc: linux-btrfs@vger.kernel.org
On Mon, Dec 18, 2023 at 04:01:55PM +0000, Naohiro Aota wrote:
> 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). As
> shown in the attached plot, current btrfs exponentially drops its
> performance.
>
> The drop is because find_free_extent() need to traverse a lot of full block
> groups, trying to find a space.
>
> This series fixes the performance drop by choosing a proper block group
> from the zone_active_bgs. Since the list does not contain full block
> groups, there is no need of traversing the full BGs.
>
> Naohiro Aota (2):
> btrfs: zoned: split out prepare_allocation_zoned()
> btrfs: zoned: optimize hint byte for zoned allocator
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread