diff mbox series

[2/4] btrfs: zoned: finish BG when there are no more allocatable bytes left

Message ID 42758829d8696a471a27f7aaeab5468f60b1565d.1651157034.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned: fixes for zone finishing | expand

Commit Message

Naohiro Aota April 28, 2022, 3:02 p.m. UTC
Currently, btrfs_zone_finish_endio() finishes a block group only when the
written region reaches the end of the block group. We can also finish the
block group when no more allocation is possible.

Cc: stable@vger.kernel.org # 5.16+
Fixes: be1a1d7a5d24 ("btrfs: zoned: finish fully written block group")
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/zoned.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Pankaj Raghav April 29, 2022, 11:55 a.m. UTC | #1
On Fri, Apr 29, 2022 at 12:02:16AM +0900, Naohiro Aota wrote:
> +++ b/fs/btrfs/zoned.c
> @@ -2017,6 +2017,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
>  void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length)
>  {
>  	struct btrfs_block_group *block_group;
> +	u64 min_use;
minor nit:
Could you rename this variable to `min_alloc_bytes` or something else
more descriptive?
>  
>  	if (!btrfs_is_zoned(fs_info))
>  		return;
> @@ -2024,7 +2025,14 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
>  	block_group = btrfs_lookup_block_group(fs_info, logical);
>  	ASSERT(block_group);
>  
> -	if (logical + length < block_group->start + block_group->zone_capacity)
> +	/* No MIXED BG on zoned btrfs. */
> +	if (block_group->flags & BTRFS_BLOCK_GROUP_DATA)
> +		min_use = fs_info->sectorsize;
> +	else
> +		min_use = fs_info->nodesize;
> +
> +	/* Bail out if we can allocate more data from this BG. */
> +	if (logical + length + min_use <= block_group->start + block_group->zone_capacity)
>  		goto out;
>  
>  	__btrfs_zone_finish(block_group, true);
> -- 
> 2.35.1
> 
Otherwise the changes look good to me.

Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Naohiro Aota May 2, 2022, 6:40 p.m. UTC | #2
On Fri, Apr 29, 2022 at 01:55:07PM +0200, Pankaj Raghav wrote:
> On Fri, Apr 29, 2022 at 12:02:16AM +0900, Naohiro Aota wrote:
> > +++ b/fs/btrfs/zoned.c
> > @@ -2017,6 +2017,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
> >  void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length)
> >  {
> >  	struct btrfs_block_group *block_group;
> > +	u64 min_use;
> minor nit:
> Could you rename this variable to `min_alloc_bytes` or something else
> more descriptive?

Sure. It looks better.

> >  
> >  	if (!btrfs_is_zoned(fs_info))
> >  		return;
> > @@ -2024,7 +2025,14 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
> >  	block_group = btrfs_lookup_block_group(fs_info, logical);
> >  	ASSERT(block_group);
> >  
> > -	if (logical + length < block_group->start + block_group->zone_capacity)
> > +	/* No MIXED BG on zoned btrfs. */
> > +	if (block_group->flags & BTRFS_BLOCK_GROUP_DATA)
> > +		min_use = fs_info->sectorsize;
> > +	else
> > +		min_use = fs_info->nodesize;
> > +
> > +	/* Bail out if we can allocate more data from this BG. */
> > +	if (logical + length + min_use <= block_group->start + block_group->zone_capacity)
> >  		goto out;
> >  
> >  	__btrfs_zone_finish(block_group, true);
> > -- 
> > 2.35.1
> > 
> Otherwise the changes look good to me.
> 
> Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
> 
> -- 
> Pankaj Raghav
diff mbox series

Patch

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 9cddafe78fb1..0f6ca3587c3b 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2017,6 +2017,7 @@  bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
 void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length)
 {
 	struct btrfs_block_group *block_group;
+	u64 min_use;
 
 	if (!btrfs_is_zoned(fs_info))
 		return;
@@ -2024,7 +2025,14 @@  void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
 	block_group = btrfs_lookup_block_group(fs_info, logical);
 	ASSERT(block_group);
 
-	if (logical + length < block_group->start + block_group->zone_capacity)
+	/* No MIXED BG on zoned btrfs. */
+	if (block_group->flags & BTRFS_BLOCK_GROUP_DATA)
+		min_use = fs_info->sectorsize;
+	else
+		min_use = fs_info->nodesize;
+
+	/* Bail out if we can allocate more data from this BG. */
+	if (logical + length + min_use <= block_group->start + block_group->zone_capacity)
 		goto out;
 
 	__btrfs_zone_finish(block_group, true);