From patchwork Wed May 4 00:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12836609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46F85C433FE for ; Wed, 4 May 2022 00:49:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244772AbiEDAxO (ORCPT ); Tue, 3 May 2022 20:53:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244751AbiEDAxM (ORCPT ); Tue, 3 May 2022 20:53:12 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865663F89D for ; Tue, 3 May 2022 17:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1651625379; x=1683161379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CwJPU/Bd44I87KvZod58QD9K1Mdp7OF2dH0K6wp4nps=; b=jodfTvQAjf1+ikS3FQqM6E3/Dt+d2mas0m5pIe1aMj8O0dD1Bid5ra5r ujV5TVi9ygVOqKwY+CtOxl+tdO4qHIYu19t5ZQI++oX12AeyCn8kcqNTY srRYKXubquJxcsggfBgccphrccN3LIClStCOt74SEbwKoUcnTu09hCwVS D8s4l6C4VfmquQsA333IucFfTSrBzIFsNmbyQ4sxO0K/J3QL93Cfc3tXn y7K8GgqWjbFa2V8NvwNz7a9MFdQWQs+p9qX+JjpW1AJxU7DG4YOiccYJN bWY26glFT6qs6M9zwwJGnlWIOd/AqgeelXxeg+TJ68Fbx5wgo2oMxerBY w==; X-IronPort-AV: E=Sophos;i="5.91,196,1647273600"; d="scan'208";a="200341876" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 04 May 2022 08:49:38 +0800 IronPort-SDR: DJGHu9zfbQhsrNzALsvgVcTTsWbNaFw2OoWOPB/mdHe0G2P+jG+OaIZmCXfXI8IO+DWf5M2SpS iPDugYH4GaIqdaAzVhTFGwQ8k/eIBfW4dPbXOu+VXhgFpwoZYcELA/LeFr8Gzkw42YaXFH5SGU WiV4KFjCrWnAtax96qPAppeaU6pmoMDs+FePMg0nsf6fnk7VQexSTib/RYmbPR8j6q3r+yLmkZ Gcc+1fKzFvCSqiF7qaHTS3hCA7ws9SwI+IlZs8gJlf8E4QN8OvaQYJCi32dLGAhrMz133DzWcg 9PL6AMqdTJzYNSQVhkyh0mqm Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 03 May 2022 17:19:40 -0700 IronPort-SDR: yn4TxpDRnqgL/OfDxCQJ8pNOdp3kZL6luC6SkgHp6bBG7dpfa6JzmyiE8o+zAB6WQdDPQ7v/Li N7SWh8e8LiVGuiBVqrF+b/TG7/II4+00TzzRnTnMZikTIJKXrr4h1MkDXoRKrP9jDiyapwv7qY 4AcnTVvu8qjHA4NyLHldLnKaIUL/tvo1SIC0jmypTqpIa5yWS93MrzsjvyhYVDY/CfZARg+tPu vXcQxC5OqxLGFej0VB3k+DYnIR0qtHBHQxOLVNAg3Gd/F1tGmWHrxIWe7Sx7Jya7EF6ZM4Zh86 OB0= WDCIronportException: Internal Received: from jv0vzd3.ad.shared (HELO naota-x1.wdc.com) ([10.225.48.207]) by uls-op-cesaip02.wdc.com with ESMTP; 03 May 2022 17:49:37 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 1/5] btrfs: zoned: introduce btrfs_zoned_bg_is_full Date: Tue, 3 May 2022 17:48:50 -0700 Message-Id: <1b20c7e3f675e7752d94e5d6543aa8bbdb281225.1651624820.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce a wrapper to check if all the space in a block group is allocated or not. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 3 +-- fs/btrfs/zoned.c | 2 +- fs/btrfs/zoned.h | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1dc6b2014813..1a2959be579d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3800,8 +3800,7 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, /* Check RO and no space case before trying to activate it */ spin_lock(&block_group->lock); - if (block_group->ro || - block_group->alloc_offset == block_group->zone_capacity) { + if (block_group->ro || btrfs_zoned_bg_is_full(block_group)) { ret = 1; /* * May need to clear fs_info->{treelog,data_reloc}_bg. diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 6e91022ae9f6..cc0c5dd5a901 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1836,7 +1836,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) } /* No space left */ - if (block_group->alloc_offset == block_group->zone_capacity) { + if (btrfs_zoned_bg_is_full(block_group)) { ret = false; goto out_unlock; } diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index de923fc8449d..98f277ed5138 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -372,4 +372,10 @@ static inline void btrfs_zoned_data_reloc_unlock(struct btrfs_inode *inode) mutex_unlock(&root->fs_info->zoned_data_reloc_io_lock); } +static inline bool btrfs_zoned_bg_is_full(struct btrfs_block_group *bg) +{ + ASSERT(btrfs_is_zoned(bg->fs_info)); + return bg->alloc_offset == bg->zone_capacity; +} + #endif From patchwork Wed May 4 00:48:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12836610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E4DFC433F5 for ; Wed, 4 May 2022 00:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244773AbiEDAxP (ORCPT ); Tue, 3 May 2022 20:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244769AbiEDAxO (ORCPT ); Tue, 3 May 2022 20:53:14 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29EDD3F881 for ; Tue, 3 May 2022 17:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1651625380; x=1683161380; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nh9pnvyypqwWTofcXe8XBLctV0p4cmgHPKQU0UzWMSw=; b=WqOO11D6ig1Zx+ZEUTX8gFxphKc6evLjv8ttdFOj6p6u4nnx8nrsmhPU 0Zr4tGBpo1H+ruT7AnA6E2xAMtdjaNiuBUhB43WaLIsLVfs2RVRCThG1i TjOnSX7NEbI/eMiZU9wVWdkNxfoN1DKWwih8mJ37AyNurq2vPYb+RQLT7 eukV8SuKlkcgMZokvkgwAwtoG/p2vxX4E0yL00VmefwLd6WridmGVdgYT WzUEC3WtYLFlBQf8L2PK+YCojrkcxOMroaoRbZjnswDJjFaKrSAW4KcyS QPdRZvauqA25GYdAyaJr/nVx1pDVgBL7Ba2CtJDjpKH84qoZtijCOVQFa w==; X-IronPort-AV: E=Sophos;i="5.91,196,1647273600"; d="scan'208";a="200341881" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 04 May 2022 08:49:40 +0800 IronPort-SDR: Udx/7ISMvUM+i1CAfhmROtJHUjT7uYYFiCMs7UfIh26sNJMceXIKPXRl09RWnk2dD2a1PSy3Cq tFWo/R5tKmdjLzzTY2K+/jZrOwguSNcucGpAh7TtSyf4SwNNTndj7v6PWGmPPdNMm3cya04AJJ apTjEwnt93evvN30D5Pryq9jQX8aAk8XZpbn3rII1qhvUcKG1mJzdx2krd3RYvGrYJF7Q8DLQs Fi3hFrmGsYSxUYZlwP+RGIZY9rOfGa6W2RDWYYo/9mN3c/AS2RodKIAnDA0/KkeSKxODryOORn iFv9bUKAfQWUBCZORtmbDZ9N Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 03 May 2022 17:19:42 -0700 IronPort-SDR: fsImnAQxQlsIw162V/XofqdCKJ+FBSRkNI1FcBYv0IpIn6ByV2rh3C67JXJr2OMCEeMUnx7LVX TE8VCIJtHjHNcdl1WMoJr0kUjkuiPfvtExT0nfM4Q4lsPVAsYSmr4lZih6c4EY6mVfyY2DRF2+ hBm/71kkamCLnga3a+kNH2gsESdndjCE4Gjj01vB2XOnG4j0QNvMFMSgziXiFT77emIwdf7YiV x4Hjoj6iaZxPyObPQIfzrxtrs4TovL805EHdNaGTFk/94KdQuUCenaSe1uGQHYjyqBQFxHgStU UAo= WDCIronportException: Internal Received: from jv0vzd3.ad.shared (HELO naota-x1.wdc.com) ([10.225.48.207]) by uls-op-cesaip02.wdc.com with ESMTP; 03 May 2022 17:49:39 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v2 2/5] btrfs: zoned: consolidate zone finish function Date: Tue, 3 May 2022 17:48:51 -0700 Message-Id: <3710880ddfd0ce03bc0c239dc8665a846f0049c6.1651624820.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_zone_finish() and btrfs_zone_finish_endio() have similar code. Introduce __btrfs_zone_finish() to consolidate them. Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 137 ++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 73 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index cc0c5dd5a901..0286fb1c63db 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1873,20 +1873,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 do_zone_finish(struct btrfs_block_group *block_group, bool fully_written) { 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); @@ -1900,36 +1894,52 @@ 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; - - /* 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); - - spin_lock(&block_group->lock); /* - * Bail out if someone already deactivated the block group, or - * allocated space is left in the block group. + * If we are sure that the block group is full (= no more room left for + * new allocation) and the IO for the last usable block is completed, we + * don't need to wait for the other IOs. This holds because we ensure + * the sequential IO submissions using the ZONE_APPEND command for data + * and block_group->meta_write_pointer for metadata. */ - if (!block_group->zone_is_active) { + if (!fully_written) { 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; + ret = btrfs_inc_block_group_ro(block_group, false); + if (ret) + return ret; + + /* 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); + + spin_lock(&block_group->lock); + + /* + * 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; + } } + /* + * The block group is not fully allocated, so not fully written yet. We + * need to send ZONE_FINISH command to free up an active zone. + */ + need_zone_finish = !btrfs_zoned_bg_is_full(block_group); + block_group->zone_is_active = 0; block_group->alloc_offset = block_group->zone_capacity; block_group->free_space_ctl->free_space = 0; @@ -1937,24 +1947,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 (!fully_written) + btrfs_dec_block_group_ro(block_group); spin_lock(&fs_info->zone_active_bgs_lock); ASSERT(!list_empty(&block_group->active_bg_list)); @@ -1967,6 +1982,14 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group) return 0; } +int btrfs_zone_finish(struct btrfs_block_group *block_group) +{ + if (!btrfs_is_zoned(block_group->fs_info)) + return 0; + + return do_zone_finish(block_group, false); +} + bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) { struct btrfs_fs_info *fs_info = fs_devices->fs_info; @@ -1998,9 +2021,6 @@ 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; - struct map_lookup *map; - struct btrfs_device *device; - u64 physical; if (!btrfs_is_zoned(fs_info)) return; @@ -2011,36 +2031,7 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len if (logical + length < block_group->start + block_group->zone_capacity) goto out; - spin_lock(&block_group->lock); - - if (!block_group->zone_is_active) { - spin_unlock(&block_group->lock); - goto out; - } - - block_group->zone_is_active = 0; - /* We should have consumed all the free space */ - ASSERT(block_group->alloc_offset == block_group->zone_capacity); - ASSERT(block_group->free_space_ctl->free_space == 0); - btrfs_clear_treelog_bg(block_group); - btrfs_clear_data_reloc_bg(block_group); - spin_unlock(&block_group->lock); - - map = block_group->physical_map; - device = map->stripes[0].dev; - physical = map->stripes[0].physical; - - if (!device->zone_info->max_active_zones) - goto out; - - btrfs_dev_clear_active_zone(device, physical); - - spin_lock(&fs_info->zone_active_bgs_lock); - ASSERT(!list_empty(&block_group->active_bg_list)); - list_del_init(&block_group->active_bg_list); - spin_unlock(&fs_info->zone_active_bgs_lock); - - btrfs_put_block_group(block_group); + do_zone_finish(block_group, true); out: btrfs_put_block_group(block_group); From patchwork Wed May 4 00:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12836611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E5F4C4332F for ; Wed, 4 May 2022 00:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244778AbiEDAxR (ORCPT ); Tue, 3 May 2022 20:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244769AbiEDAxQ (ORCPT ); Tue, 3 May 2022 20:53:16 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E7B43F8BB; Tue, 3 May 2022 17:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1651625383; x=1683161383; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5HVpc36GD/gLGbmClhd7HS6r7wGttaAQGBxRDAT8lus=; b=RieTnPKKAKPdp6baQq2+TpWbhayI5uX0lHn7MRj2b4SkQIPam3KmKm/l hcgpmiO2K0+9UaHgmM0JQbcxqv+UrlgNqN9hFp+9w7HHHCjtLTFZWp3l3 zaUeQneDRS2o8pQARnMfQWgLNigWowNJCVzDKJLV+dLEbmWkQtkugCMm3 8Wn/uUkEqNKf1K/UxWjw7An2JlZ9WA95TFi/wh2e2eSjNIqnvsaU5p2YP FX5rkug1nqX37ZziFnjYFRBamutOp1WVHm5u0zNp3lUxRngVMHeLXxSd6 tkl1M63zzKSI4DByztiG/YZQ75USZsjrE+66Nh7+xUu+EGTdhdORPhqYP w==; X-IronPort-AV: E=Sophos;i="5.91,196,1647273600"; d="scan'208";a="200341886" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 04 May 2022 08:49:42 +0800 IronPort-SDR: AhIQwvzX+I0GmabbE87AMzDjVqbBrLAodbwwuWWsuymVnAJ9HC4SyXjCzByZYWNW+YtZOFke8R sZ3IPRPoAf1XvASY+SXIWGDoR0MBnWQKUEYdq2eQOH1hOPVdrNDY7aO1/CwhBEvhTfAM1TTUBh uxstnm0bK7Bg9Pa9QLwLNTGrAHgeH2bvpvm2scLn6Kb1XZXQSeQNuQZsaSFKCjlKoIy6SQBYgt 7NsUGy6sPxEL2eJpdsg9I8LzGVdLqNrtNuwxysYTq+DRt43VLVIwd9HfNKoGRJwpr0wmr1xDEk xu9qvw7p/l5e4K1/l1nr48Uu Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 03 May 2022 17:19:44 -0700 IronPort-SDR: 76vdjQFV9lyxlFcn3HOzX8kH1l9ZPXNpJuG9uwtNZOQ7QS6tTlQrOpgU+M65V6/VXMHi38zf+y fzWAHmr8wwT3poHU/okiCz9v+ig+SOCzd1XSBXlAXjm/DsxPwXL/FSi67nDbght+Y8dgPdL02c syOuOs1R5AWEdk+TdYieVHxBsg5wiPCWj4CigALERBnJ89Pl9qkOnwu29q6qpXxaI/YGNd5Qkw xADxxwKtQ3TBbAri8iIddK26mVcOxE8k0fd87YYBfHYpTyMSIPrMuhuuuPFsbqfhZzhwZCsSs/ Gvw= WDCIronportException: Internal Received: from jv0vzd3.ad.shared (HELO naota-x1.wdc.com) ([10.225.48.207]) by uls-op-cesaip02.wdc.com with ESMTP; 03 May 2022 17:49:40 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , stable@vger.kernel.org, Pankaj Raghav Subject: [PATCH v2 3/5] btrfs: zoned: finish BG when there are no more allocatable bytes left Date: Tue, 3 May 2022 17:48:52 -0700 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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") Reviewed-by: Pankaj Raghav Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 0286fb1c63db..320bb7ba1c49 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -2021,6 +2021,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_alloc_bytes; if (!btrfs_is_zoned(fs_info)) return; @@ -2028,7 +2029,15 @@ 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_alloc_bytes = fs_info->sectorsize; + else + min_alloc_bytes = fs_info->nodesize; + + /* Bail out if we can allocate more data from this BG. */ + if (logical + length + min_alloc_bytes <= + block_group->start + block_group->zone_capacity) goto out; do_zone_finish(block_group, true); From patchwork Wed May 4 00:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12836612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0AAEC433FE for ; Wed, 4 May 2022 00:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244784AbiEDAxY (ORCPT ); Tue, 3 May 2022 20:53:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244779AbiEDAxX (ORCPT ); Tue, 3 May 2022 20:53:23 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B248340932; Tue, 3 May 2022 17:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1651625390; x=1683161390; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yiKnEhrLwB32uH0TxkjE71vEjFENE1v5C96HCMmf58I=; b=amfGKprnY0otDamkFHLPMRSmAskm6KY66S+HliLYYR7YdIU7uRjP3yaW 3uPivDBcsC+IUo/3vEaOhlQEsopiWkHOfmaWsm2opUuhjZbwQq8Z8xfCD QgA1nSQ+4FNHZZfmpefb9PYLs8IwR6PbQ01+n4JCw8b/SlPMmRhVo2no3 esXHxGmqw7we3j5yE8P//bBLzrbY3Qx2M91In2h0NoooVnyCN9DFXmXXm qbDD6zaeulQIfO7uU0c9NURh0A4O+jxXmypZguU2qYzVsv/CW8UCiAjfl mQ1TVjmwBVJY4SKm+O8wApQwsg+jAwAFJQkXSLfYS/AzeddFOhnyxydg8 g==; X-IronPort-AV: E=Sophos;i="5.91,196,1647273600"; d="scan'208";a="200341894" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 04 May 2022 08:49:45 +0800 IronPort-SDR: /YUemx7Xp6un2Rm1efKirzj16lrhRu4/o/AxeVBbhQwl6jPjlJciYvRsXPo74DwaUfgumNRmXx SVAWHLjUA9EBGhRLpuXTXGpndaX2cWLSS4+yfuj1gWCaNstgpxTz40bYswx659e4P92HkyuaWC y459M18Ln1Vv9MZeFhRb/6EeJyhpNNJAHcb14VLcZ+kOvb0joaZy+bpi8l2zy28djvwAOFw/dc 3LJmgiQT3Mk+O2oWlwoZe8txMtJBLI/vwg2yP5/aOhvWUySWf+/jypGa8vZSRoKjis4eKtJJZ2 dqnMMYJMdGb+hDstU8+VmOqi Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 03 May 2022 17:19:46 -0700 IronPort-SDR: vb9BDfJGNvlUci4qb6Ru3Soli6Qtp+ndg5/ZxK1PEg0CUE7uHZucWgDVx2kD5KUxVxXjhYTikt qG3Dwn3kCtv+nW5+AvpRxnd6FeoKdYbxgLSmqJ3BlNXqSAS1qkpH46++3diV5VylT+00UBfny/ WsWSoRwStUbgyLQBviaoQ9EXy12kgBG9eSJbKAEni4iH7a2/DgdKBTHBRpJAixEuVCYF0HDoxb x5OBtG2cz/hJn1X57Sm2wWIitoBts2aLa1gZHjKBwzd4n+usaa9/XOD4RFVh6JhplqaQJ74J9X zWM= WDCIronportException: Internal Received: from jv0vzd3.ad.shared (HELO naota-x1.wdc.com) ([10.225.48.207]) by uls-op-cesaip02.wdc.com with ESMTP; 03 May 2022 17:49:42 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , stable@vger.kernel.org Subject: [PATCH v2 4/5] btrfs: zoned: properly finish block group on metadata write Date: Tue, 3 May 2022 17:48:53 -0700 Message-Id: <5dfca7a3630ec2fe8c1ae1219cbbea7240f6d6de.1651624820.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Commit be1a1d7a5d24 ("btrfs: zoned: finish fully written block group") introduced zone finishing code both for data and metadata end_io path. However, the metadata side is not working as it should be. First, it compares logical address (eb->start + eb->len) with offset within a block group (cache->zone_capacity) in submit_eb_page(). That essentially disabled zone finishing on metadata end_io path. Furthermore, fixing the issue above revealed we cannot call btrfs_zone_finish_endio() in end_extent_buffer_writeback(). We cannot call btrfs_lookup_block_group() which require spin lock inside end_io context. This commit introduces btrfs_schedule_zone_finish_bg() to wait for the extent buffer writeback and do the zone finish IO in a workqueue. Also, drop EXTENT_BUFFER_ZONE_FINISH as it is no longer used. Cc: stable@vger.kernel.org # 5.16+ Fixes: be1a1d7a5d24 ("btrfs: zoned: finish fully written block group") Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.h | 2 ++ fs/btrfs/extent_io.c | 6 +----- fs/btrfs/extent_io.h | 1 - fs/btrfs/zoned.c | 34 ++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 5 +++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index c9bf01dd10e8..3ac668ace50a 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -212,6 +212,8 @@ struct btrfs_block_group { u64 meta_write_pointer; struct map_lookup *physical_map; struct list_head active_bg_list; + struct work_struct zone_finish_work; + struct extent_buffer *last_eb; }; static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 1b1baeb0d76b..588c7c606a2c 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4251,9 +4251,6 @@ void wait_on_extent_buffer_writeback(struct extent_buffer *eb) static void end_extent_buffer_writeback(struct extent_buffer *eb) { - if (test_bit(EXTENT_BUFFER_ZONE_FINISH, &eb->bflags)) - btrfs_zone_finish_endio(eb->fs_info, eb->start, eb->len); - clear_bit(EXTENT_BUFFER_WRITEBACK, &eb->bflags); smp_mb__after_atomic(); wake_up_bit(&eb->bflags, EXTENT_BUFFER_WRITEBACK); @@ -4843,8 +4840,7 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc, /* * Implies write in zoned mode. Mark the last eb in a block group. */ - if (cache->seq_zone && eb->start + eb->len == cache->zone_capacity) - set_bit(EXTENT_BUFFER_ZONE_FINISH, &eb->bflags); + btrfs_schedule_zone_finish_bg(cache, eb); btrfs_put_block_group(cache); } ret = write_one_eb(eb, wbc, epd); diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 17674b7e699c..956fa434df43 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -26,7 +26,6 @@ enum { /* write IO error */ EXTENT_BUFFER_WRITE_ERR, EXTENT_BUFFER_NO_CHECK, - EXTENT_BUFFER_ZONE_FINISH, }; /* these are flags for __process_pages_contig */ diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 320bb7ba1c49..905ce5498ee0 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -2046,6 +2046,40 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len btrfs_put_block_group(block_group); } +static void btrfs_zone_finish_endio_workfn(struct work_struct *work) +{ + struct btrfs_block_group *bg = + container_of(work, struct btrfs_block_group, zone_finish_work); + + wait_on_extent_buffer_writeback(bg->last_eb); + free_extent_buffer(bg->last_eb); + btrfs_zone_finish_endio(bg->fs_info, bg->start, bg->length); + btrfs_put_block_group(bg); +} + +void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg, + struct extent_buffer *eb) +{ + if (!bg->seq_zone || + eb->start + eb->len * 2 <= bg->start + bg->zone_capacity) + return; + + if (WARN_ON(bg->zone_finish_work.func == + btrfs_zone_finish_endio_workfn)) { + btrfs_err(bg->fs_info, + "double scheduling of BG %llu zone finishing", + bg->start); + return; + } + + /* For the work */ + btrfs_get_block_group(bg); + atomic_inc(&eb->refs); + bg->last_eb = eb; + INIT_WORK(&bg->zone_finish_work, btrfs_zone_finish_endio_workfn); + queue_work(system_unbound_wq, &bg->zone_finish_work); +} + void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg) { struct btrfs_fs_info *fs_info = bg->fs_info; diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 98f277ed5138..a4126ec6b909 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -72,6 +72,8 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group); 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); +void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg, + struct extent_buffer *eb); void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg); void btrfs_free_zone_cache(struct btrfs_fs_info *fs_info); bool btrfs_zoned_should_reclaim(struct btrfs_fs_info *fs_info); @@ -230,6 +232,9 @@ static inline bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, static inline void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length) { } +static inline void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg, + struct extent_buffer *eb) { } + static inline void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg) { } static inline void btrfs_free_zone_cache(struct btrfs_fs_info *fs_info) { } From patchwork Wed May 4 00:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12836613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AD11C433EF for ; Wed, 4 May 2022 00:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244787AbiEDAxZ (ORCPT ); Tue, 3 May 2022 20:53:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244783AbiEDAxY (ORCPT ); Tue, 3 May 2022 20:53:24 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A985403DE; Tue, 3 May 2022 17:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1651625391; x=1683161391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=McS6LOQ+qbCDqY9h9ImN2+sDf7qjg7/obzhcg89zg0o=; b=qovhTbmrGmFDiFrcqr5XqHVhBz+VsxJ7HG6mfhvR3r1gBaDCpf0i13ml ntBHkXQ0F8+mTBBBM7W9Euxg/1/GDEqvFBcqpzE/ZsJotaE1f/pzhCmvZ KN43a56GTExU/QwXZZpmgFEUhZUwOhvmT/tsGUBEoO95hQm1eSx2TefkC 0xmdiAuEIxpWSOkqI89lcFO+O2kDAMrumDvFzVP0SXn2WKVFKjLyOfbLB W7pBI/dzgit39SJfbJNgNGwIBLCXqYGZ5eoVIiRcXOWOWnMQy04E+Ck1H ePaghz/zizwov/GIdvlGMkNntOCUXNIjYR1Bl2SE75dbpCasEOZBeqkfT A==; X-IronPort-AV: E=Sophos;i="5.91,196,1647273600"; d="scan'208";a="200341896" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 04 May 2022 08:49:47 +0800 IronPort-SDR: N0s6hZ7XSu6jf1WmUqdmBBi6Y47coCEvs6I6y91r7rHgF6pVfz2fgleGkY2j8XbC/nLMZI8eCd /6J8BY7omU1S99rr40LTWFUjp2VBTg/H4QEMDkBkCzPAS6NEL5stFCUsv616OBdfDUfFi9IhfT MdPl04oRSvjU5vC8iYwpDuh9mLXg1kRLUDhIfEHHFLjhxe3aPfr8oY1boWpJKB/fYBm+dMjjrZ FpCHwbYIP7CyMoujsicpoyZt3IvEYoNYyFt4QXtCBhxruvfHJNCAaURrYJwFmxagVJtR5gau/0 BNbvwsVMrQSsgsQ1N57iOPjo Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 03 May 2022 17:19:48 -0700 IronPort-SDR: f/KeC8mR9T8DNqYFNSy7nxiVC6DambtZiVi1S5f6H5nD5WCJbvjFfyYhA9ZfwU6h5c55zXAONf BXAojG4V53wOmqDLGxQ04tgyqI5n7vY/k0CUM1oMuF18pMTgBOuUnZRgpwGdKbzkZ6xR+imvv8 x3X08BVZ1/JlLNVKaAeo4IOGhLSy/tg7vPS3RnOzEHprtBjIWyAEqg3a3FFvN4cgH1X8lyIGoy LcXFziy4HzoHlW/siCnLEHOuW/UwVraWeHWBX2SreKs7N4dCM9QkoR2I+F6eot80prwEDX9aV8 W/g= WDCIronportException: Internal Received: from jv0vzd3.ad.shared (HELO naota-x1.wdc.com) ([10.225.48.207]) by uls-op-cesaip02.wdc.com with ESMTP; 03 May 2022 17:49:44 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , stable@vger.kernel.org Subject: [PATCH v2 5/5] btrfs: zoned: zone finish unused block group Date: Tue, 3 May 2022 17:48:54 -0700 Message-Id: <39cf96b9872341d88593f293f2211935d7a6bfac.1651624820.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org While the active zones within an active block group are reset, and their active resource is released, the block group itself is kept in the active block group list and marked as active. As a result, the list will contain more than max_active_zones block groups. That itself is not fatal for the device as the zones are properly reset. However, that inflated list is, of course, strange. Also, a to-appear patch series, which deactivates an active block group on demand, get confused with the wrong list. So, fix the issue by finishing the unused block group once it gets read-only, so that we can release the active resource in an early stage. Cc: stable@vger.kernel.org # 5.16+ Fixes: be1a1d7a5d24 ("btrfs: zoned: finish fully written block group") Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 9739f3e8230a..ede389f2602d 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1385,6 +1385,14 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) goto next; } + ret = btrfs_zone_finish(block_group); + if (ret < 0) { + btrfs_dec_block_group_ro(block_group); + if (ret == -EAGAIN) + ret = 0; + goto next; + } + /* * Want to do this before we do anything else so we can recover * properly if we fail to join the transaction.