From: David Sterba <dsterba@suse.cz>
To: Naohiro Aota <naohiro.aota@wdc.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/4] btrfs: zoned: consolidate zone finish function
Date: Thu, 28 Apr 2022 18:11:03 +0200 [thread overview]
Message-ID: <20220428161103.GD18596@twin.jikos.cz> (raw)
In-Reply-To: <4d5e42d343318979a254f7dbdd96aa1c48908ed8.1651157034.git.naohiro.aota@wdc.com>
On Fri, Apr 29, 2022 at 12:02:15AM +0900, Naohiro Aota wrote:
> 1 file changed, 54 insertions(+), 73 deletions(-)
>
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 997a96d7a3d5..9cddafe78fb1 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -1879,20 +1879,14 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
> return ret;
> }
>
> -int btrfs_zone_finish(struct btrfs_block_group *block_group)
> +static int __btrfs_zone_finish(struct btrfs_block_group *block_group, bool nowait)
Can you please avoid using __ for functions? Eg. the main function can
be btrfs_zone_finish(taking 2 parameters) and the exported one being
btrfs_zone_finish_nowait reflecting the preset parameter and also making
the 'nowait' semantics clear.
> {
> struct btrfs_fs_info *fs_info = block_group->fs_info;
> struct map_lookup *map;
> - struct btrfs_device *device;
> - u64 physical;
> + bool need_zone_finish;
> int ret = 0;
> int i;
>
> - if (!btrfs_is_zoned(fs_info))
> - return 0;
> -
> - map = block_group->physical_map;
> -
> spin_lock(&block_group->lock);
> if (!block_group->zone_is_active) {
> spin_unlock(&block_group->lock);
> @@ -1906,36 +1900,42 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group)
> spin_unlock(&block_group->lock);
> return -EAGAIN;
> }
> - spin_unlock(&block_group->lock);
>
> - ret = btrfs_inc_block_group_ro(block_group, false);
> - if (ret)
> - return ret;
> + if (!nowait) {
> + spin_unlock(&block_group->lock);
>
> - /* Ensure all writes in this block group finish */
> - btrfs_wait_block_group_reservations(block_group);
> - /* No need to wait for NOCOW writers. Zoned mode does not allow that. */
> - btrfs_wait_ordered_roots(fs_info, U64_MAX, block_group->start,
> - block_group->length);
> + ret = btrfs_inc_block_group_ro(block_group, false);
> + if (ret)
> + return ret;
>
> - spin_lock(&block_group->lock);
> + /* Ensure all writes in this block group finish */
> + btrfs_wait_block_group_reservations(block_group);
> + /* No need to wait for NOCOW writers. Zoned mode does not allow that. */
> + btrfs_wait_ordered_roots(fs_info, U64_MAX, block_group->start,
> + block_group->length);
>
> - /*
> - * Bail out if someone already deactivated the block group, or
> - * allocated space is left in the block group.
> - */
> - if (!block_group->zone_is_active) {
> - spin_unlock(&block_group->lock);
> - btrfs_dec_block_group_ro(block_group);
> - return 0;
> - }
> + spin_lock(&block_group->lock);
>
> - if (block_group->reserved) {
> - spin_unlock(&block_group->lock);
> - btrfs_dec_block_group_ro(block_group);
> - return -EAGAIN;
> + /*
> + * Bail out if someone already deactivated the block group, or
> + * allocated space is left in the block group.
> + */
> + if (!block_group->zone_is_active) {
> + spin_unlock(&block_group->lock);
> + btrfs_dec_block_group_ro(block_group);
> + return 0;
> + }
> +
> + if (block_group->reserved) {
> + spin_unlock(&block_group->lock);
> + btrfs_dec_block_group_ro(block_group);
> + return -EAGAIN;
> + }
> }
>
> + /* There is unwritten space left. Need to finish the underlying zones. */
> + need_zone_finish = (block_group->zone_capacity - block_group->alloc_offset) > 0;
This could be simplified to 'bg->zone_capacity > bg->alloc_offset',
but maybe should be behind a helper as the expression appears more
times.
> +
> block_group->zone_is_active = 0;
> block_group->alloc_offset = block_group->zone_capacity;
> block_group->free_space_ctl->free_space = 0;
> @@ -1943,24 +1943,29 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group)
> btrfs_clear_data_reloc_bg(block_group);
> spin_unlock(&block_group->lock);
>
> + map = block_group->physical_map;
> for (i = 0; i < map->num_stripes; i++) {
> - device = map->stripes[i].dev;
> - physical = map->stripes[i].physical;
> + struct btrfs_device *device = map->stripes[i].dev;
> + const u64 physical = map->stripes[i].physical;
>
> if (device->zone_info->max_active_zones == 0)
> continue;
>
> - ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
> - physical >> SECTOR_SHIFT,
> - device->zone_info->zone_size >> SECTOR_SHIFT,
> - GFP_NOFS);
> + if (need_zone_finish) {
> + ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
> + physical >> SECTOR_SHIFT,
> + device->zone_info->zone_size >> SECTOR_SHIFT,
> + GFP_NOFS);
>
> - if (ret)
> - return ret;
> + if (ret)
> + return ret;
> + }
>
> btrfs_dev_clear_active_zone(device, physical);
> }
> - btrfs_dec_block_group_ro(block_group);
> +
> + if (!nowait)
> + btrfs_dec_block_group_ro(block_group);
>
> spin_lock(&fs_info->zone_active_bgs_lock);
> ASSERT(!list_empty(&block_group->active_bg_list));
next prev parent reply other threads:[~2022-04-28 16:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 15:02 [PATCH 0/4] btrfs: zoned: fixes for zone finishing Naohiro Aota
2022-04-28 15:02 ` [PATCH 1/4] btrfs: zoned: consolidate zone finish function Naohiro Aota
2022-04-28 16:11 ` David Sterba [this message]
2022-04-29 4:56 ` Naohiro Aota
2022-04-29 18:41 ` David Sterba
2022-04-28 15:02 ` [PATCH 2/4] btrfs: zoned: finish BG when there are no more allocatable bytes left Naohiro Aota
2022-04-29 11:55 ` Pankaj Raghav
2022-05-02 18:40 ` Naohiro Aota
2022-04-28 15:02 ` [PATCH 3/4] btrfs: zoned: properly finish block group on metadata write Naohiro Aota
2022-04-28 15:02 ` [PATCH 4/4] btrfs: zoned: zone finish unused block group Naohiro Aota
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220428161103.GD18596@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox