From patchwork Wed Aug 11 14:16:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54EACC432BE for ; Wed, 11 Aug 2021 14:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F3FD6101E for ; Wed, 11 Aug 2021 14:20:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232545AbhHKOVP (ORCPT ); Wed, 11 Aug 2021 10:21:15 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35961 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232463AbhHKOVK (ORCPT ); Wed, 11 Aug 2021 10:21:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691646; x=1660227646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R0HG1SaOMAX5EARuUJru4/592OjUQV/ulzYy4Q3vdcc=; b=Np6OlJUXLJDRZZu1sQGGBO1cao2ru3wiXWtiPCumGj/3CCp3P/15Mp70 4rsG5HLgQbjyM1OFUhoUT3AawLkrM5o2hPyd+mrCbLnlsUBMejWfVTCHW j2hCyureKRvH2H+9IGaBZ2Q60DkehL9R5k75/g6HQ4vcXC3fDHnpJU5lK vIUCD5n233t7d6rHtTa4z6aCi3L2+QFf2A5a2pRAX0/tiOsyvxJ1of2rj tVAKawfTIfWlbXm2hS6Hc+spdKOdxRwWLEhG/aJKASVuC8Ef16ZD1XSmy 8J4glCHSOmMnnB+12B6Zvj9UJi2X5O7orHzxbVQ+KhwsFhiJZUZcT5UuD Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937863" 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; 11 Aug 2021 22:20:46 +0800 IronPort-SDR: YHYpY/4oqPjK2KqsLk7Oe0Hyj4aXT8gY4f4kGhn5k/7TxkGj56sm6tBGzrPk7Mrkcdn0DUskr3 +FWyonAYIiIUk6XQy1ijXCWgVHtNZ4qqOFJEmqyaQTxy41jXUpJmpqc2RghkEMghA8AyeOYlgk nyxUwlQWuTXh5StDfBdt1ipUxv14X/oOqnJ/CefPR6qSrHt8VT4LTD17rMyVLQZJK7IwGXktRo 7dpShs69H7cv2hWqsX36DucQFxyuA/Tc4vfyvoW9gjXgz7liuwLI8AwYGKJQJRLBE7O9sQA5D/ EOABvMQwIVKQgxD326+l6cZs Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:16 -0700 IronPort-SDR: wuQI8qgL7c8tjrcnSMNdgSPXzyGAEdn/fhSSGyAbF85Q7/TqSjU5xAIfmShnXi7iVrFTHAcnbP ScG4OjfFHp0OQ+KHNUKaJb02N8vKDmpLR5Z90EDMVYZJ6Knlbejk1sGp2Ph4sf7J53Xci/54ZS 252g+/74QLo54zEm1jYmAxoun3RNShHDhEEfGZKx15xroqvVPdxP9rjkeudDlrLHANugoOTOSz FYUZCI2j4fi+p4/vx1pLnCUcPZH7/k76ZGyPt5dFZYwRKcCOQxRCy19Pr+ycaYCEuIKMqpl3GE SQk= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:46 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 01/17] btrfs: zoned: load zone capacity information from devices Date: Wed, 11 Aug 2021 23:16:25 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The ZNS specification introduces the concept of a Zone Capacity. A zone capacity is an additional per-zone attribute that indicates the number of usable logical blocks within each zone, starting from the first logical block of each zone. It is always smaller or equal to the zone size. With the SINGLE profile, we can set a block group's "capacity" as the same as the underlying zone's Zone Capacity. We will limit the allocation not to exceed in a following commit. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.h | 1 + fs/btrfs/zoned.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index c72a71efcb18..2db40a005512 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -202,6 +202,7 @@ struct btrfs_block_group { */ u64 alloc_offset; u64 zone_unusable; + u64 zone_capacity; u64 meta_write_pointer; }; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 47af1ab3bf12..32f444c7ec76 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1039,6 +1039,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) int i; unsigned int nofs_flag; u64 *alloc_offsets = NULL; + u64 *caps = NULL; u64 last_alloc = 0; u32 num_sequential = 0, num_conventional = 0; @@ -1069,6 +1070,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) return -ENOMEM; } + caps = kcalloc(map->num_stripes, sizeof(*caps), GFP_NOFS); + if (!caps) { + ret = -ENOMEM; + goto out; + } + for (i = 0; i < map->num_stripes; i++) { bool is_sequential; struct blk_zone zone; @@ -1131,6 +1138,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) goto out; } + caps[i] = zone.capacity << SECTOR_SHIFT; + switch (zone.cond) { case BLK_ZONE_COND_OFFLINE: case BLK_ZONE_COND_READONLY: @@ -1144,7 +1153,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) alloc_offsets[i] = 0; break; case BLK_ZONE_COND_FULL: - alloc_offsets[i] = fs_info->zone_size; + alloc_offsets[i] = caps[i]; break; default: /* Partially used zone */ @@ -1169,6 +1178,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) * calculate_alloc_pointer() which takes extent buffer * locks to avoid deadlock. */ + + /* Zone capacity is always zone size in emulation */ + cache->zone_capacity = cache->length; if (new) { cache->alloc_offset = 0; goto out; @@ -1195,6 +1207,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) goto out; } cache->alloc_offset = alloc_offsets[0]; + cache->zone_capacity = caps[0]; break; case BTRFS_BLOCK_GROUP_DUP: case BTRFS_BLOCK_GROUP_RAID1: @@ -1218,6 +1231,14 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) ret = -EIO; } + if (cache->alloc_offset > cache->zone_capacity) { + btrfs_err(fs_info, +"zoned: invalid write pointer %llu (larger than zone capacity %llu) in block group %llu", + cache->alloc_offset, cache->zone_capacity, + cache->start); + ret = -EIO; + } + /* An extent is allocated after the write pointer */ if (!ret && num_conventional && last_alloc > cache->alloc_offset) { btrfs_err(fs_info, @@ -1229,6 +1250,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) if (!ret) cache->meta_write_pointer = cache->alloc_offset + cache->start; + kfree(caps); kfree(alloc_offsets); free_extent_map(em); From patchwork Wed Aug 11 14:16:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76133C4338F for ; Wed, 11 Aug 2021 14:20:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ADCC60E78 for ; Wed, 11 Aug 2021 14:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232555AbhHKOVT (ORCPT ); Wed, 11 Aug 2021 10:21:19 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35964 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbhHKOVL (ORCPT ); Wed, 11 Aug 2021 10:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691647; x=1660227647; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=083VbVpuPIiBHeyUyg4bbSl1cDJieON3B5IrJ/WVDS4=; b=h8QLECeHC9KHM6mOCXw+9zt9DoTnEYO/ioGtTx6J6rwWzb1IbdGA9Sqt UEYx2u2krWz6RRP9y3edvnw9jl9h1mdarwLw1SVscz+S81KjiUv+KqN2w Hv+YNfnS4axjHtLsjOPevLzad445E4oxgZ2SrVkQcL8GJC9bqMO60GrTX f/KYpUDps/4Vsg2EzxOhN2YoFBFsWa/ppD+mMJIJu6hj9wjpMzsFRy9Ks 1Hw83jBDK91T76kJ/hHx7MB37xHCLoMfVWO+DBi2qONeQHHENaF+1IsRh dXIKu2mgUYfJxz9evgqrBamSi0yOcrhR4+iuCkjuys1uHkAqTM7yT516E A==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937869" 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; 11 Aug 2021 22:20:47 +0800 IronPort-SDR: 34B/gGkRhwC5NcKimpjOE1XBeBuroCNax3A9N5VnLmaERXTIoVhGVkhuoBkC/FYbm8jZkg6ZVz +2XyGk9Lzs/Bx2/DkcIwoXIqtAa7DuxKGigy2xEliUIl2GAOa2G7g6FZDWO3hv1G6ZviKk/36e Qst+5QgRqJ8BuRmXzSuCDW3iUKUfe9gYK+ygja0Br1zup29OSKKSSpW0PskvV/z2xnMrrjDkOD cTQob3FS5ul3ZHXwWp98R+j5l4r3SR9wGbmR1VhZizxchuD4fKbSbw8vyVaoBeC6MG+CtMSnXV 3Y2tbwdiMnrpFbL7UUDwLsxu Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:17 -0700 IronPort-SDR: t1LUSO0W+GMXWyfudliju14PZE3VapRtHvOQJQYSe2yFbpVSUmggWk+3b0ylTRLE23yWuN8lQL ZIO3os4zR34G/Z8hnsLrh268qHhP1mTJyZQNh8yb0xMmLBKEoLEIZdhA0hlz6A9dd0uUVoZTyQ EeG+LkKZwoXUYis9ga3m3hHbeOQ2q3WZC1xu7ZveAFUWe/r5Mz1P6MyNN3ZsOikCzxKSGgPsoK G2vaH5FGW3CEw8JtkfEsDs8ogSx1AeLxCtC2bstFXEr+v2I5jHYk6VRX27eFb6hgUpCONOIHt2 ibg= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:47 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 02/17] btrfs: zoned: move btrfs_free_excluded_extents out from btrfs_calc_zone_unusable Date: Wed, 11 Aug 2021 23:16:26 +0900 Message-Id: <09e4304e298cd1a2691eeebb59759103aa9e5409.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_free_excluded_extents() is not nccessary for btrfs_calc_zone_unusable() and it makes btrfs_calc_zone_unusable() difficult to reuse. Move it out and call btrfs_free_excluded_extents() in the proper context. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 5 +++++ fs/btrfs/zoned.c | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 9e833d74e8dc..db368518d42c 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2037,6 +2037,11 @@ static int read_one_block_group(struct btrfs_fs_info *info, */ if (btrfs_is_zoned(info)) { btrfs_calc_zone_unusable(cache); + /* + * Should not have any excluded extents. Just in case, + * though + */ + btrfs_free_excluded_extents(cache); } else if (cache->length == cache->used) { cache->last_byte_to_unpin = (u64)-1; cache->cached = BTRFS_CACHE_FINISHED; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 32f444c7ec76..579fb03ba937 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1273,9 +1273,6 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) cache->cached = BTRFS_CACHE_FINISHED; cache->free_space_ctl->free_space = free; cache->zone_unusable = unusable; - - /* Should not have any excluded extents. Just in case, though */ - btrfs_free_excluded_extents(cache); } void btrfs_redirty_list_add(struct btrfs_transaction *trans, From patchwork Wed Aug 11 14:16:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0224BC432BE for ; Wed, 11 Aug 2021 14:20:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D12A460F21 for ; Wed, 11 Aug 2021 14:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbhHKOVV (ORCPT ); Wed, 11 Aug 2021 10:21:21 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35964 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232512AbhHKOVM (ORCPT ); Wed, 11 Aug 2021 10:21:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691648; x=1660227648; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WHHHyzmaQNqHHiR0/yfc/HMQjiwgTVRiaoBwgQHTpUI=; b=Aa8ClHXzYdzws3e+Tdhdd8HV5UD7hVkbGHCY8S3YoTLY/6wC5Pu5AUTe 5hKRIe01aRdkpfYxYPbpyEuqowTKYwM6DXq6ePTYuP9M6DVIRhRlma6c+ EGFot36uv1y5T2wWHSLuw4DiMg914QLBx6S2O+Agu302+YZcp7US9Bf+z tdxyiDM8EOd0ydL44how1ty/2IXuGPLRwCgCBvX+F+MFGZXcE1CqfY+4H guL9RbEoYCFuWqUP5oFipRadoq2Ys/9pEWoHoW4VieoHMO2M+thnBcp4i vZ8Y6QrT4oXh9vIgMHdMKmMKDnKwbAbfuNzYxI3xLh1u6TJACBkxh8qOw g==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937872" 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; 11 Aug 2021 22:20:48 +0800 IronPort-SDR: qe66fF4KGXvKbpg/QeUTjTB7hKEkFWKmSjOIorXVqO+ddLFLooFFVxEq+ucPrle0ATKLUvuGYE gHCknmblVcdkTcV7J9ZXBcBN0L0LrQMyj00iQecPQ/bPTup3jxY50mMOaqgr8xfyI4gtNTkNPu BjtfyFcLN6dCscmluNuE9V/QEgtRhckjH+JgPGiW8y2wYhpzex74bdLBLGMVgrzO8PZqZQx91R ghMLRa1cRjkwveIWqVO5qDmzWNFi1wRMYUMp+syk17QKzHIT3dtYNYH43dL97pUep1+O4zPUy9 vXguQgZle5xuYVActzmxUbD0 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:19 -0700 IronPort-SDR: 2aRpCCmN/J7XvM7xWuL9fu/LZTzcmMqWJkk1ZA1+STQlu6Wb0B9z9mMz2M95B1sGwdY/72k3cU 7QHeglpi9LTzTC7RVwgCfd18ocAcuYkFi9OMpC2ZCihO8BGcc+MxXi+lvXEUEXk6/sn+F+57Ku Tu9qf/SZwQ8CI2cgNxhgRTocLoVwYZFYT8H7r2B7pLtZ71PU/yHEyCIKauBQ1kKRqR2D+kwlQA ZHDJGAvOnstlTIKQ5XNPCcDBaf8Cxpf3cD8jjstButXrOY5qlH/MlzHyylhcDRDrhN139pBur5 YUc= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:48 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 03/17] btrfs: zoned: calculate free space from zone capacity Date: Wed, 11 Aug 2021 23:16:27 +0900 Message-Id: <55e57e66f8c6b4821e43e816ca8bbdc9bc3f351d.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we introduced capacity in a block group, we need to calculate free space using the capacity instead of the length. Thus, bytes we account capacity - alloc_pointer as free, and account bytes [capacity, length] as zone unusable. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 6 ++++-- fs/btrfs/extent-tree.c | 3 ++- fs/btrfs/free-space-cache.c | 8 +++++++- fs/btrfs/zoned.c | 5 +++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index db368518d42c..de22e3c9599e 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2486,7 +2486,8 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran */ trace_btrfs_add_block_group(fs_info, cache, 1); btrfs_update_space_info(fs_info, cache->flags, size, bytes_used, - cache->bytes_super, 0, &cache->space_info); + cache->bytes_super, cache->zone_unusable, + &cache->space_info); btrfs_update_global_block_rsv(fs_info); link_block_group(cache); @@ -2601,7 +2602,8 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache) if (!--cache->ro) { if (btrfs_is_zoned(cache->fs_info)) { /* Migrate zone_unusable bytes back */ - cache->zone_unusable = cache->alloc_offset - cache->used; + cache->zone_unusable = (cache->alloc_offset - cache->used) + + (cache->length - cache->zone_capacity); sinfo->bytes_zone_unusable += cache->zone_unusable; sinfo->bytes_readonly -= cache->zone_unusable; } diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index fc3da7585fb7..8dafb61c4946 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3796,7 +3796,8 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, goto out; } - avail = block_group->length - block_group->alloc_offset; + WARN_ON_ONCE(block_group->alloc_offset > block_group->zone_capacity); + avail = block_group->zone_capacity - block_group->alloc_offset; if (avail < num_bytes) { if (ffe_ctl->max_extent_size < avail) { /* diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index da0eee7c9e5f..bb2536c745cd 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2539,10 +2539,15 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, u64 offset = bytenr - block_group->start; u64 to_free, to_unusable; const int bg_reclaim_threshold = READ_ONCE(fs_info->bg_reclaim_threshold); + bool initial = (size == block_group->length); + + WARN_ON(!initial && offset + size > block_group->zone_capacity); spin_lock(&ctl->tree_lock); if (!used) to_free = size; + else if (initial) + to_free = block_group->zone_capacity; else if (offset >= block_group->alloc_offset) to_free = size; else if (offset + size <= block_group->alloc_offset) @@ -2755,7 +2760,8 @@ void btrfs_dump_free_space(struct btrfs_block_group *block_group, */ if (btrfs_is_zoned(fs_info)) { btrfs_info(fs_info, "free space %llu", - block_group->length - block_group->alloc_offset); + block_group->zone_capacity - + block_group->alloc_offset); return; } diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 579fb03ba937..0eb8ea4d3542 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1265,8 +1265,9 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) return; WARN_ON(cache->bytes_super != 0); - unusable = cache->alloc_offset - cache->used; - free = cache->length - cache->alloc_offset; + unusable = (cache->alloc_offset - cache->used) + + (cache->length - cache->zone_capacity); + free = cache->zone_capacity - cache->alloc_offset; /* We only need ->free_space in ALLOC_SEQ block groups */ cache->last_byte_to_unpin = (u64)-1; From patchwork Wed Aug 11 14:16:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D3BBC4338F for ; Wed, 11 Aug 2021 14:21:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5023260E78 for ; Wed, 11 Aug 2021 14:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232541AbhHKOVW (ORCPT ); Wed, 11 Aug 2021 10:21:22 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35972 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232532AbhHKOVN (ORCPT ); Wed, 11 Aug 2021 10:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691649; x=1660227649; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FIQ2V+kIMZeT6Kqo8vrdRnKidRkC521Ht60fnLVbg7U=; b=UQZriHF/kCnd+z7xwpgiE0ks8sRjfJPVQt57TSewT5UtIdt/X6IOoJRu SgmmemhOtj6un80tCnfTbmWBVkB1e5RGVOdO0F4aswfFQ+U13eovJjcko ud5kEhceE0vj1ajslyFEOSfQ+KJHti56ITsKplKgEGkk0kw4Ys3W6QXFB vWpChgZyVYwuTaW9BD+XRgf4A6zS/F1DnFEF+b+Y7Zlomyak414BlRWEq ovkbwl1zIE58a+yMxcyDZOmXQ7w6lQfPV6hCJRKOVz62l6qc1frH1Bsyi Cf1glwW8cb/IaA8o0+jBjK9qb7sCSu4XFzi+fIzaocDxV4puV+1pxL8Fu A==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937875" 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; 11 Aug 2021 22:20:49 +0800 IronPort-SDR: fpISgMWddRjb8OmuzCetRkau/N13w3CHZvT+ptLOxzoFgvBpPfVoZkhS+O219sq8RBeQSkulqf fc8eVtYgVmWMVLQngrp8UqI2CjBxq1NmFRAQSSSFoaj5D486cJAiXQFszuRvZQoK3hzLDkPgI1 5p/Nht2XfqIK15oBlZZx6OAG+Wz6UUboyQ9dW/z4ee6oCVqYPP+UqbsVfkgeCGVvk/izVvINRG 8FCszyFDde7hq5LtCLwCjg7XFflpE/+lLu9Fblpr8LQ108EnyEWjAEBGwwGe4zLSp00s2w33vu cY3bwhVwxKevTwriZBZrLDm4 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:20 -0700 IronPort-SDR: RhHIt+mTxBfPvws7NOQJskRIcrzjJ5qza187noV7/lhKuvVaqQBjNlGTSDZ+7NGuENSC+jtue3 J01ZbGUUH1LP0TkYrvumSd3UVH2Mxhh9Kvw68AqxI6o/iBTmjYIlRvFLnCghVcinxsfbJkCkvc ab5Cg5aVOxW+IkBGi9ojTLeJ7s4fu15MAmICyq2iF0cVAy0oLWzmCiVpFMa2t9qNRs2FPUUaEo ZQvphHZjKK9OZZy81FKYOdpq/Z7dP3StoxXxbm+9Sd2NdzIe1KKPSEUSPn4sZv1R5WmQmqkuCM NQY= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:49 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 04/17] btrfs: zoned: tweak reclaim threshold for zone capacity Date: Wed, 11 Aug 2021 23:16:28 +0900 Message-Id: <940fa7fa954f507bfc3c401a32257c08e7fe8c7c.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org With the introduction of zone capacity, bytes [capacity, length] are always zone unusable. Counting this region as a reclaim target will cause reclaiming too early. Reclaim block groups based on bytes that can be usable after resetting. Signed-off-by: Naohiro Aota --- fs/btrfs/free-space-cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index bb2536c745cd..772485c39e45 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2540,6 +2540,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, u64 to_free, to_unusable; const int bg_reclaim_threshold = READ_ONCE(fs_info->bg_reclaim_threshold); bool initial = (size == block_group->length); + u64 reclaimable_unusable; WARN_ON(!initial && offset + size > block_group->zone_capacity); @@ -2570,12 +2571,15 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, spin_unlock(&block_group->lock); } + reclaimable_unusable = block_group->zone_unusable - + (block_group->length - block_group->zone_capacity); /* All the region is now unusable. Mark it as unused and reclaim */ if (block_group->zone_unusable == block_group->length) { btrfs_mark_bg_unused(block_group); } else if (bg_reclaim_threshold && - block_group->zone_unusable >= - div_factor_fine(block_group->length, bg_reclaim_threshold)) { + reclaimable_unusable >= + div_factor_fine(block_group->zone_capacity, + bg_reclaim_threshold)) { btrfs_mark_bg_to_reclaim(block_group); } From patchwork Wed Aug 11 14:16:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C057C4320A for ; Wed, 11 Aug 2021 14:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E345A60E78 for ; Wed, 11 Aug 2021 14:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232548AbhHKOVX (ORCPT ); Wed, 11 Aug 2021 10:21:23 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35974 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbhHKOVO (ORCPT ); Wed, 11 Aug 2021 10:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691650; x=1660227650; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qPFgbVgcLq2p0fDO+TzE8v4FfTU1y2CyIExGFOZBU4U=; b=lkwXirpC2kg5rstVsGOvol0imsqB3xN/sA+Rd30mtWGQCxVryaxjhqcI YkHF1o2Hx9gwXHzuirLhTFjup8zsAeYO358jkBTIjnrl6owoD2VIzQSgk YyVL4sZnvsAsPeLskVXuJ4UPBzt+epAXx5UHuLzmLgywmSdUIFGzLaIvw mefcFCldvPkqWmckRCjQMZTjn3vqG82TyMekgvNMKmhejcUlwTxqYbIxx 4EqWn9qD0d0XWR08lYuQt1pCFnXMkGSIVJwci53K2FnMYoH93/h1M/H3f rX77yf+TO3ug3S/pjdWfWYc+9Mu8kiCq55eFZv8LBs4c7jZTupFG4C0jh g==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937877" 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; 11 Aug 2021 22:20:50 +0800 IronPort-SDR: tYzRNHDHt+wuvc11QvVvNFhqbspmie9W5Yy+YmYRD6qEY8ttGrxquF/ZNt+q/7TfK8LnKjqpbk wEe6/J9EDot+MZbpy9X1ZB1K1DslgAfb7lgwvOU1qm3nRAgD9MjXzQ86dvU3PPlO5Ye9Q8A06M LnZEsf5AXtELt1PvQ430uRqJpU5u6azlI5tb5P0Hc3Bc8w6hZK+177cv4LeTHTkvkxaf5Q0kol +0ACKTMNFczUVUpFuWpSmbb4673mZB2A5h5vPJ9Pc0RWkVxLCWGC0e57K6r68YJjXuAJbNtpPg wgLJJdB6pF717ZGScH2B8GgC Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:21 -0700 IronPort-SDR: jW/azO0ZT6HunARblGz/zzuC3/8jFF21hKVJGuyAigzQ3HzsZscaWsIxlPP5tmEW8pNKhSkgiZ /ZrY06qtacySGbCvqI1sCr7W5f0tl4R0yTTtrASfZhctKwuJeiWpiRGq1xmodhzowiWtAIcPqR E5Ryu6V7MI5cGdR/sZfDWhKbzO9Csc7LLjhBiUkMHMs+mk4gPk9R7dFUr8Y8M5LtlTU9qMPcjL EtGV4siGM3FN945ka9rXuJWHtLOvTC/ODv9snJbOQEg9eEPWQcTJPzv6olHv9Jv/urevKehlfY ArY= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:50 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 05/17] btrfs: zoned: consider zone as full when no more SB can be written Date: Wed, 11 Aug 2021 23:16:29 +0900 Message-Id: <74323d21d61fa334e033d301fb3163f1b73f0238.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We cannot write beyond zone capacity. So, we should consider a zone as "full" when the write pointer goes beyond capacity - the size of super info. Also, take this opportunity to replace a subtle duplicated code with a loop and fix a typo in comment. Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 0eb8ea4d3542..d20c97395a70 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -45,6 +45,14 @@ */ #define BTRFS_MAX_ZONE_SIZE SZ_8G +#define SUPER_INFO_SECTORS ((u64)BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT) + +static inline bool sb_zone_is_full(struct blk_zone *zone) +{ + return (zone->cond == BLK_ZONE_COND_FULL) || + (zone->wp + SUPER_INFO_SECTORS > zone->start + zone->capacity); +} + static int copy_zone_info_cb(struct blk_zone *zone, unsigned int idx, void *data) { struct blk_zone *zones = data; @@ -60,14 +68,13 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, bool empty[BTRFS_NR_SB_LOG_ZONES]; bool full[BTRFS_NR_SB_LOG_ZONES]; sector_t sector; + int i; - ASSERT(zones[0].type != BLK_ZONE_TYPE_CONVENTIONAL && - zones[1].type != BLK_ZONE_TYPE_CONVENTIONAL); - - empty[0] = (zones[0].cond == BLK_ZONE_COND_EMPTY); - empty[1] = (zones[1].cond == BLK_ZONE_COND_EMPTY); - full[0] = (zones[0].cond == BLK_ZONE_COND_FULL); - full[1] = (zones[1].cond == BLK_ZONE_COND_FULL); + for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) { + ASSERT(zones[i].type != BLK_ZONE_TYPE_CONVENTIONAL); + empty[i] = (zones[i].cond == BLK_ZONE_COND_EMPTY); + full[i] = sb_zone_is_full(&zones[i]); + } /* * Possible states of log buffer zones @@ -664,7 +671,7 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, reset = &zones[1]; if (reset && reset->cond != BLK_ZONE_COND_EMPTY) { - ASSERT(reset->cond == BLK_ZONE_COND_FULL); + ASSERT(sb_zone_is_full(reset)); ret = blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET, reset->start, reset->len, From patchwork Wed Aug 11 14:16:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42F9AC432BE for ; Wed, 11 Aug 2021 14:21:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25E6A61008 for ; Wed, 11 Aug 2021 14:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232563AbhHKOVY (ORCPT ); Wed, 11 Aug 2021 10:21:24 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35974 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232546AbhHKOVP (ORCPT ); Wed, 11 Aug 2021 10:21:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691652; x=1660227652; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5Px+itNgdnBz6vWpI7MNAb57rRUL1XvG1mQkAplwfIk=; b=FaQjXDEk1z4gQVjDxoNeq2lUh098zOIjfXCoA2VSWVnquYNKfxu9wDV8 rS7XNmWc1W5nqq7WdJAF3Y+5EJsAaYZ699m2D4JrsxTBeY0NYzFw3tY1c /Oe4yNQbPQkefTrP6jUcL29W1A/MqqEl9M59xFYoXkLh1oHvSJLD+LrPB tQ6gQPeZNONQ2hvVdrZB6unq5RE7RdJN/UnjoAxemSov1ay9iRdQOAn9r OIwT8EQpr/AKFbbdpr+woOPOYENADrSvlB0+noZdKp66RCUndriE+gVbJ byTxHsXm49nYqdvs+vhdIc9uiHVQoUPp55OaRYwAx+JBfukBTdTwzbkwy Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937880" 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; 11 Aug 2021 22:20:51 +0800 IronPort-SDR: j6AybjEhhf6UckAN9Oh/Dw7ZSLHXSGagFXju1dGG/BTpNti2YoadHWOr2x5mA5+FsvAHmit9Ux G/BgHghNAxorfiLLo1LQCfoqSG3xoYh2hCfQVBux+1J8slPASVL62O3yBwZIygzHcATgDAkZqv XJ5gJ3p/bbYnccmIOjP5vy4LosDg3udkf/ZCZuE79/5VzaDczJ6QeAezmrZZbOGXuBhMR0t2Kw ng0IFzQ3i5kIk95EZP9Y24YsDuAtgArcCEXVkJz354o2IKbpu6Gbgzl0XqufGUl7egzuUkrEyw f161SZDL8YTmdAqd1OUDRuLQ Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:22 -0700 IronPort-SDR: cgcJEn2c7ueGDNwiZ0oOlJ4YV15DYc8BkS1KdQR11CxoCOlaY/Zlddyxx6JkpVfyi2Rd/DjyII kqf4TPVn85bBCEmY8a+cFs7Yag1c3OriNpv1GVtbNCizva3/laS17/N+lKFeU64mwTGwGpNtyv 5vwIMLMzcNRRTsuG+6PKPCCzpQQpju0+RDxDWFP6NdYazlnyKJsG9iVOXPVPVQjKPzEuXiQ+Fv nQogs9iBMdcal9PzpSYzJzZkNd3UWJdx1G7fGJiVdSpspv4xmjzZUBXKx6LumUfMsycFoWy59L q5E= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:51 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 06/17] btrfs: zoned: locate superblock position using zone capacity Date: Wed, 11 Aug 2021 23:16:30 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org sb_write_pointer() returns the write position of next superblock. For READ, we need a previous location. When the pointer is at the head, the previous one is the last one of the other zone. Calculate the last one's position from zone capacity. Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index d20c97395a70..188a4ebefe59 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -683,9 +683,20 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, reset->wp = reset->start; } } else if (ret != -ENOENT) { - /* For READ, we want the precious one */ + /* + * For READ, we want the previous one. Move write pointer + * to the end of a zone, if it is at the head of a zone. + */ + u64 zone_end = 0; + if (wp == zones[0].start << SECTOR_SHIFT) - wp = (zones[1].start + zones[1].len) << SECTOR_SHIFT; + zone_end = zones[1].start + zones[1].capacity; + else if (wp == zones[1].start << SECTOR_SHIFT) + zone_end = zones[0].start + zones[0].capacity; + if (zone_end) + wp = ALIGN_DOWN(zone_end << SECTOR_SHIFT, + BTRFS_SUPER_INFO_SIZE); + wp -= BTRFS_SUPER_INFO_SIZE; } From patchwork Wed Aug 11 14:16:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CDEBC4338F for ; Wed, 11 Aug 2021 14:21:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F2A460D07 for ; Wed, 11 Aug 2021 14:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232566AbhHKOVY (ORCPT ); Wed, 11 Aug 2021 10:21:24 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35974 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbhHKOVR (ORCPT ); Wed, 11 Aug 2021 10:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691653; x=1660227653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L7hltgxblR23hImnrXs7/wUSzAFM0N8z5c4FTzz+w/8=; b=S38HEp2TW6M0rS8egckw3bKuBUt9Bi/JMvlsxWEi4GtDkEOVkAyoM7wv Zpmzb/O3d96RgpeSpTykthPNmJIWczT2KDEbTs/YN6/kcKvOTWKwpHpys jVtuv3Ptq1SPZONfDkCroPqCgYBqREE8aw1aB4kKDgEfc+eJKnnAHrEOv 488Gs7Rd4kR973AdmvTHiOOS1XCpXPGp2MkzcpnUJz/MfY29ka92E2oqd U9lh7UxaHRvfxzkz8q+qsIbgs6TX4FwV2j5J9QRI+njE+tpTVyAAOJK6r TZ3oUmgNmgMQZDOgDwQhd1SQy63Ts9Ey0+EiIdF5Ikqsmp6oaQYozf9HD g==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937885" 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; 11 Aug 2021 22:20:53 +0800 IronPort-SDR: qGkLLFzHc33wZ/YIVL7N7inWwQ0GMTC6klYJ+71UsWHyO57oyWdCCATMMXlvxyWaJxXDC+CONW y45H66fryF+J527mFxYFOAvv4SxQNB5FGDqPLBJa3aWptIuBaXouCINZDt5Iv4HpID1xD6C8xa UqGiG58LM9Xw/F6yazev2aZtCwLE1MPvblP+zIGU00iYC85V8URD7R0J+QdHx2J2cOZ2GfQox1 fa3l62C5tcnoVkJD0DYG26M6qCOm4+iIqHfs5goUBqnca7Y2HQOVuPXRqJ6qNGGka4i4q0CCe5 gwW1HEbamRkkEWcQfXTBPBUd Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:23 -0700 IronPort-SDR: QBlztBBOiDwVoMVsrXy5hdoRY5gwMevpoORxUFkQBGuaFsZkigxgffzul4Q+DDCONO0Pbz5xrb AcYvpzUza6iZyUJIf/xQPCKYo9erSF3CoqPrp+0JSSsb/COOV0YfSD3JCt7ZRVIJl3wTsjjxCZ U2MxbjTZICerxVsN76xUYa91PKr8LHb87r8qrkhNxNEkJUV62KPe+sxYecAWl4lH6JJxQKA2Ew 1VK7VkuXdo2kXEXTR6wQTGLe7vAqEZsV8x/XgfbAwa8PX8fSYNJmAw7sAbNgx0CmoAu3O7S1aF V90= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:52 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 07/17] btrfs: zoned: finish superblock zone once no space left for new SB Date: Wed, 11 Aug 2021 23:16:31 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If there is no more space left for a new superblock in a superblock zone, then it is better to ZONE_FINISH the zone and frees up the active zone count. Since btrfs_advance_sb_log() can now issue REQ_OP_ZONE_FINISH, we also need to convert it to return int for the error case. Signed-off-by: Naohiro Aota --- fs/btrfs/disk-io.c | 4 +++- fs/btrfs/zoned.c | 53 ++++++++++++++++++++++++++++++++-------------- fs/btrfs/zoned.h | 8 ++++--- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2f9515dccce0..74b8848de8da 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3881,7 +3881,9 @@ static int write_dev_supers(struct btrfs_device *device, bio->bi_opf |= REQ_FUA; btrfsic_submit_bio(bio); - btrfs_advance_sb_log(device, i); + + if (btrfs_advance_sb_log(device, i)) + errors++; } return errors < i ? 0 : -1; } diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 188a4ebefe59..3eb74542a9b1 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -789,36 +789,57 @@ static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo, return true; } -void btrfs_advance_sb_log(struct btrfs_device *device, int mirror) +int btrfs_advance_sb_log(struct btrfs_device *device, int mirror) { struct btrfs_zoned_device_info *zinfo = device->zone_info; struct blk_zone *zone; + int i; if (!is_sb_log_zone(zinfo, mirror)) - return; + return 0; zone = &zinfo->sb_zones[BTRFS_NR_SB_LOG_ZONES * mirror]; - if (zone->cond != BLK_ZONE_COND_FULL) { + for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) { + /* Advance the next zone */ + if (zone->cond == BLK_ZONE_COND_FULL) { + zone++; + continue; + } + if (zone->cond == BLK_ZONE_COND_EMPTY) zone->cond = BLK_ZONE_COND_IMP_OPEN; - zone->wp += (BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT); + zone->wp += SUPER_INFO_SECTORS; + + if (sb_zone_is_full(zone)) { + /* + * No room left to write new superblock. Since + * superblock is written with REQ_SYNC, it is safe + * to finish the zone now. + * + * If the write pointer is exactly at the capacity, + * explicit ZONE_FINISH is not necessary. + */ + if (zone->wp != zone->start + zone->capacity) { + int ret; + + ret = blkdev_zone_mgmt(device->bdev, + REQ_OP_ZONE_FINISH, + zone->start, zone->len, + GFP_NOFS); + if (ret) + return ret; + } - if (zone->wp == zone->start + zone->len) + zone->wp = zone->start + zone->len; zone->cond = BLK_ZONE_COND_FULL; - - return; + } + return 0; } - zone++; - ASSERT(zone->cond != BLK_ZONE_COND_FULL); - if (zone->cond == BLK_ZONE_COND_EMPTY) - zone->cond = BLK_ZONE_COND_IMP_OPEN; - - zone->wp += (BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT); - - if (zone->wp == zone->start + zone->len) - zone->cond = BLK_ZONE_COND_FULL; + /* All the zones are FULL. Should not reach here. */ + ASSERT(0); + return -EIO; } int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 4b299705bb12..4f30f3bf1886 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -40,7 +40,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, u64 *bytenr_ret); int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, u64 *bytenr_ret); -void btrfs_advance_sb_log(struct btrfs_device *device, int mirror); +int btrfs_advance_sb_log(struct btrfs_device *device, int mirror); int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror); u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, u64 hole_end, u64 num_bytes); @@ -113,8 +113,10 @@ static inline int btrfs_sb_log_location(struct btrfs_device *device, int mirror, return 0; } -static inline void btrfs_advance_sb_log(struct btrfs_device *device, int mirror) -{ } +static inline int btrfs_advance_sb_log(struct btrfs_device *device, int mirror) +{ + return 0; +} static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) { From patchwork Wed Aug 11 14:16:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CFE5C432BE for ; Wed, 11 Aug 2021 14:21:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3179360E78 for ; Wed, 11 Aug 2021 14:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbhHKOV0 (ORCPT ); Wed, 11 Aug 2021 10:21:26 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35974 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232477AbhHKOVS (ORCPT ); Wed, 11 Aug 2021 10:21:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691654; x=1660227654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kG9oyVK4uriKrldIlVDu3CcbJPeRplp/sY3XvsDRWIQ=; b=AzirkQdItF84K1zrKPVy5GEnhhz1i1BXa08hNd6ydNGrUqV/HJCbAi4t 0UpVgCszElIsuXoL+mVL07I1omMj8lWaSlUX9m59BJfcGsND78mXvi+XB lt1d165GsrLUWPzpFcIVuWtS8lr2ekVjSgDk5KoYXaIsBQ8lSn7PvQq+k w/+FVFw1Rq25RlGUDXSR4a7ErIXqQWawjCAf2dNyvfWeRvp8tZAjJ8CVM 7JSK8yTXWdJ6loEflvR0QLKexADphyYUcf2klDdiuNoo/WhZiqdNBvDbN EL/+5gavFrsfyHJz7VrFBjtV6l8kPiTv7ACUGht/t528s/SEKkU0IZySE Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937886" 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; 11 Aug 2021 22:20:54 +0800 IronPort-SDR: 7L8vqEDGTkWN/hiNEuuAPo8ZIXTINxzmD5LUjLVydgvkW74LXfAS/VmanD5myjBIz3kkiGtxKS U4m9KZ09euSsTlqSMsuyXuG/W/2ZcOjAIX9QNg8HIg86FWroI/MKFelsVTtLwaGkL4gkE10Ixg EVNJbqsGWp/DaIU4Cm5YBDkf2CHRxPA7lMeey0No0ExRStzDyhTlbLmxqIpDBCEdWV10PL9c7/ 1vLr7w2qfXtHBakPxmbHAQlz/w/ojF4h6Tm0kLHwRJRJe5wfyYc5UqFfgF9Zvrot7EkfKHRXL6 sM0youl3VA6OLvNBahtwIsvf Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:24 -0700 IronPort-SDR: Y40RXFQLXECkqXFrXWC63MxtrD2TL6GUjAnac6qNOO5al0u0G0vTBlxeP6CwKdbDtRM8IKLdyr AxnlYoYtngWQ6VO8KtHDExA7iDvZJUE9Xp4InHXbHKbNkVfsjthS9B666ib60Ivpr57X7oHvVd gnKBzwWDZ48t6lkw/YLeDA5DOS1mYzadVBKIqFiJmAITLdWqQaIeDA7WAzL5LH3dE7vgmw2Mks mZzjcycLOUKI8jP8cbydmRB3jMHdIa7KyYHhP8WX525dooSlDPZoGR4IyX9Gq06HIzpBvj/NGt zuA= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:54 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 08/17] btrfs: zoned: load active zone information from devices Date: Wed, 11 Aug 2021 23:16:32 +0900 Message-Id: <9e15c87886a2280dde1c9b1591ea8901af713341.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The ZNS specification defines a limit on the number of zones that can be in the implicit open, explicit open or closed conditions. Any zone with such condition is defined as an active zone and correspond to any zone that is being written or that has been only partially written. If the maximum number of active zones is reached, we must either reset or finish some active zones before being able to chose other zones for storing data. Load queue_max_active_zones() and track the number of active zones left on the device. Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/zoned.h | 3 +++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 3eb74542a9b1..a198ce073353 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "ctree.h" #include "volumes.h" #include "zoned.h" @@ -38,6 +39,15 @@ /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 +/* Number of minimal activate zones we want. + * + * - BTRFS_SUPER_MIRROR_MAX zones for superblock mirrors + * - 3 zones to ensure at least one zone per SYSTEM, META and DATA block group + * - 1 zone for tree-log dedicated block group + * - 1 zone for relocation + */ +#define BTRFS_MIN_ACTIVE_ZONES (BTRFS_SUPER_MIRROR_MAX + 5) + /* * Maximum supported zone size. Currently, SMR disks have a zone size of * 256MiB, and we are expecting ZNS drives to be in the 1-4GiB range. We do not @@ -303,6 +313,9 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) struct btrfs_fs_info *fs_info = device->fs_info; struct btrfs_zoned_device_info *zone_info = NULL; struct block_device *bdev = device->bdev; + struct request_queue *queue = bdev_get_queue(bdev); + unsigned int max_active_zones; + unsigned int nactive; sector_t nr_sectors; sector_t sector = 0; struct blk_zone *zones = NULL; @@ -358,6 +371,17 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) if (!IS_ALIGNED(nr_sectors, zone_sectors)) zone_info->nr_zones++; + max_active_zones = queue_max_active_zones(queue); + if (max_active_zones && max_active_zones < BTRFS_MIN_ACTIVE_ZONES) { + btrfs_err_in_rcu(fs_info, +"zoned: %s: max active zones %u is too small. Need at least %u active zones", + rcu_str_deref(device->name), max_active_zones, + BTRFS_MIN_ACTIVE_ZONES); + ret = -EINVAL; + goto out; + } + zone_info->max_active_zones = max_active_zones; + zone_info->seq_zones = bitmap_zalloc(zone_info->nr_zones, GFP_KERNEL); if (!zone_info->seq_zones) { ret = -ENOMEM; @@ -370,6 +394,12 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) goto out; } + zone_info->active_zones = bitmap_zalloc(zone_info->nr_zones, GFP_KERNEL); + if (!zone_info->active_zones) { + ret = -ENOMEM; + goto out; + } + zones = kcalloc(BTRFS_REPORT_NR_ZONES, sizeof(struct blk_zone), GFP_KERNEL); if (!zones) { ret = -ENOMEM; @@ -377,6 +407,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) } /* Get zones type */ + nactive = 0; while (sector < nr_sectors) { nr_zones = BTRFS_REPORT_NR_ZONES; ret = btrfs_get_dev_zones(device, sector << SECTOR_SHIFT, zones, @@ -387,8 +418,17 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) for (i = 0; i < nr_zones; i++) { if (zones[i].type == BLK_ZONE_TYPE_SEQWRITE_REQ) __set_bit(nreported, zone_info->seq_zones); - if (zones[i].cond == BLK_ZONE_COND_EMPTY) + switch (zones[i].cond) { + case BLK_ZONE_COND_EMPTY: __set_bit(nreported, zone_info->empty_zones); + break; + case BLK_ZONE_COND_IMP_OPEN: + case BLK_ZONE_COND_EXP_OPEN: + case BLK_ZONE_COND_CLOSED: + __set_bit(nreported, zone_info->active_zones); + nactive++; + break; + } nreported++; } sector = zones[nr_zones - 1].start + zones[nr_zones - 1].len; @@ -403,6 +443,19 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) goto out; } + if (max_active_zones) { + if (nactive > max_active_zones) { + btrfs_err_in_rcu(device->fs_info, + "zoned: %d active zones on %s exceeds max_active_zones %d", + nactive, rcu_str_deref(device->name), + max_active_zones); + ret = -EIO; + goto out; + } + atomic_set(&zone_info->active_zones_left, + max_active_zones - nactive); + } + /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { @@ -485,6 +538,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) out: kfree(zones); out_free_zone_info: + bitmap_free(zone_info->active_zones); bitmap_free(zone_info->empty_zones); bitmap_free(zone_info->seq_zones); kfree(zone_info); @@ -500,6 +554,7 @@ void btrfs_destroy_dev_zone_info(struct btrfs_device *device) if (!zone_info) return; + bitmap_free(zone_info->active_zones); bitmap_free(zone_info->seq_zones); bitmap_free(zone_info->empty_zones); kfree(zone_info); diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 4f30f3bf1886..48628782e4b8 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -23,8 +23,11 @@ struct btrfs_zoned_device_info { u64 zone_size; u8 zone_size_shift; u32 nr_zones; + unsigned int max_active_zones; + atomic_t active_zones_left; unsigned long *seq_zones; unsigned long *empty_zones; + unsigned long *active_zones; struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX]; }; From patchwork Wed Aug 11 14:16:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0394DC4338F for ; Wed, 11 Aug 2021 14:21:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D864260F21 for ; Wed, 11 Aug 2021 14:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbhHKOV1 (ORCPT ); Wed, 11 Aug 2021 10:21:27 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35977 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232517AbhHKOVT (ORCPT ); Wed, 11 Aug 2021 10:21:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691655; x=1660227655; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zU2idOabwJoqFZBtkH9iENAlTmh1ZrQD5KOMojjSq8Y=; b=rGPpHITLnDsa1XKraV3DXz6t6gWCt30OJ0/VGaPYvHpuEzm+6xgKe+1f efSXuxkTSNER90GtVCN+VYDjdPZhhz4kV/9QggVYsZIckmuab0PAJ6GvE UtSa4Po58Y7IG+PTZUXPOMpddauVnMW6C5kz6JRAJTo2fglGC9BxoKz9l hMuZE7wrAw+czdGh6LR7nG2rVBAw4cte4inAdOED6yQq2djjuxHLYKcRh segAdWIf8o1Ly3fTFGuYyG4ZOU3WGDWxgcjXvSIrrWlnExt25UIqhGnH3 lsC430Y53vDLHypzvhSTW4QV8+HpEPJOVRZvwcxzkkDBPGd7qCuaticgt A==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937890" 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; 11 Aug 2021 22:20:55 +0800 IronPort-SDR: 7vDQKOXlSW9lWxG7C1ezZLHm4UmZFVnoDq8Zz+vWV/UjJS19V/+O9dQImKOCkW1cQ3IoEhlEAc yme6tFTz136lJSDIouo79PlKcKd7s3+7Dg89NlyY4Q4zcmq9NrrLWmbYGHyKUslgYOQL6znF2l kfFLxEQDKnUTcbLiRDCx+hkMUNw5z1jQRDf7v9MCIVFeXNaTgtkqMuu4e8YZUu8eFW1wwuauCb Xy1hUL9xFFcqNV8t1ua5sR8EvMcreiH3Z8fciifmKJriQemZkFfS1X/ikUuDnARrCGqEusCNc2 qoesOHAw1u7k+Er2+EZYcww7 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:25 -0700 IronPort-SDR: cOu5A18FLJZG9NFptBlno+Ic6Zu3paAhg1o/qzXgd7crzfZrX6PyiuDRLjaM0+oSNLptteXOU5 Q1XPoFlpqQbGuevT2/nmzXq62lzUo/OWXh0+BttkgzCGGa8EpAVmoVOt5u8aNIS0zczW9P4vsH JqUBFCoNikk3B7dBYThS2vcu4CnL4j6LOXbdZ4n74JM5KoSI/J+72U0W4iaYN8uKCRo+w5xpL7 22jAF7cmtBA2YsMtO6NXu94Aobiy8SSCuGwDGA2iH1jhLylmOB20LzTofoyQapCiqUmHkyPW8Z opY= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:55 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 09/17] btrfs: zoned: introduce physical_map to btrfs_block_group Date: Wed, 11 Aug 2021 23:16:33 +0900 Message-Id: <10439dc1a45272fa6e4b6aeb3596b6e977f49fa0.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We will use a block group's physical location to track active zones and finish fully written zones in the following commits. Since the zone activation is done in the extent allocation context which already holding the tree locks, we can't query the chunk tree for the physical locations. So, copy the location info into a block group and use it for activation. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 1 + fs/btrfs/block-group.h | 1 + fs/btrfs/zoned.c | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index de22e3c9599e..c94815cbd136 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -144,6 +144,7 @@ void btrfs_put_block_group(struct btrfs_block_group *cache) */ WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root)); kfree(cache->free_space_ctl); + kfree(cache->physical_map); kfree(cache); } } diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 2db40a005512..265db2c316d3 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -204,6 +204,7 @@ struct btrfs_block_group { u64 zone_unusable; u64 zone_capacity; u64 meta_write_pointer; + struct map_lookup *physical_map; }; static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index a198ce073353..cfc6d4337473 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1158,10 +1158,19 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) map = em->map_lookup; + cache->physical_map = kmalloc(map_lookup_size(map->num_stripes), + GFP_NOFS); + if (!cache->physical_map) { + ret = -ENOMEM; + goto out; + } + + memcpy(cache->physical_map, map, map_lookup_size(map->num_stripes)); + alloc_offsets = kcalloc(map->num_stripes, sizeof(*alloc_offsets), GFP_NOFS); if (!alloc_offsets) { - free_extent_map(em); - return -ENOMEM; + ret = -ENOMEM; + goto out; } caps = kcalloc(map->num_stripes, sizeof(*caps), GFP_NOFS); @@ -1344,6 +1353,10 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) if (!ret) cache->meta_write_pointer = cache->alloc_offset + cache->start; + if (ret) { + kfree(cache->physical_map); + cache->physical_map = NULL; + } kfree(caps); kfree(alloc_offsets); free_extent_map(em); From patchwork Wed Aug 11 14:16:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D311C432BE for ; Wed, 11 Aug 2021 14:21:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AA2B60F21 for ; Wed, 11 Aug 2021 14:21:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232588AbhHKOV1 (ORCPT ); Wed, 11 Aug 2021 10:21:27 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35979 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232482AbhHKOVU (ORCPT ); Wed, 11 Aug 2021 10:21:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691656; x=1660227656; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X+nEsMisGz6VUscYrWXRfYuxXcHrximBLnC6rdppjmw=; b=PuzF3zALTK99ll46/XRAxDXYuEwbfbhb8+xX1+mBA5kflc1ArDUkhzpO z1KzgNXwv2yrcrhMATG45++9qU6VPKyy+LLX+bBkIQ1oizrxaeMR9OEUo KFxPGg5khhUvFAH8xFVFQUgzMCPc7d9gMy9HNXt3trqFMzFbyN82bY6K9 eWOJ7soy1B1Fz/MXRGjQEoV6RRNPFQxVGf8gcK4F0vnr8zoATBFNviFh1 QG2y8X3jYjUT8+MFulDjfV/X98spoz1BHzYduFF951PI1+dLOS65DJics nBHZEdXmm+XbNnc4YudZdRmUaLlmtWPkawkp9HavEq6wgzFs+q3NXDVCt A==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937893" 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; 11 Aug 2021 22:20:56 +0800 IronPort-SDR: 8tzTIkQpuZrzfz9OZZar9pLndLpPCL9uB/3vzwnGQGlQ4qAi8f6Brpuqbh5t0j3HdEJiMPkRYV OKrSc2b9aoLH4bEQi8YJEpDq6kPZ3wZ6+EUT9snf/pxUjSaF+nDN1FnFSwbqNiKP92+tfNIMX0 vGZrSQvDdVO4gDFDN0ie1o2Jsylc9/S18VhENLHRdkdcFdPa0pDgbBQtwiAEUAQC4nkfngnClX fAJOg3hj5e2CISSdAjYsUPsuRpafO3JtTmh+1yG/BzurkGyYZYvzk4/p1lYUr/gqWKFOJbHv7X 50hDYOkEKvD0YagGT7N/xZlr Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:26 -0700 IronPort-SDR: 2rXqkc8fu/K2jgidscjSVR/99EJMLE7WRvXDPPOq6uaFzBOlQilENSC2p7LzZVTlk37t2/5D80 Hxq8atAvI0MU3rcLOcUNPhQDazeTtU7ncF8iceo/+JivJ/ajlRQbCEy0vxZ3hBSOHntzHPmoNk pkx8GP0VfiY8nJmZ/RqSMCLfBKGZlqcWcYSngrBH9qBOFvIiCikZiPd0sMM6SEmljcPL2qbrko mvhNhs9RG6DhnfWULE5TRYfdORqq5o66hJOwy51Yn7UZCJBr9PQPrm8Umsh8zGUayYCStg1Vnb IUY= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:56 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 10/17] btrfs: zoned: implement active zone tracking Date: Wed, 11 Aug 2021 23:16:34 +0900 Message-Id: <3decf1b58d55d025879b5883bb7cf879572282d2.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add zone_is_active flag to btrfs_block_group. This flag indicates the underlying zones are all active. Such zone active block groups are tracked by fs_info->active_bg_list. btrfs_dev_{set,clear}_active_zone() take responsibility for the underlying device part. They set/clear the bitmap to indicate zone activeness and count the number of zones we can activate left. btrfs_zone_{activate,finish}() take responsibility for the logical part and the list management. In addition, btrfs_zone_finish() wait for any writes on it and send REQ_OP_ZONE_FINISH to the zone. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 11 +++ fs/btrfs/block-group.h | 2 + fs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 2 + fs/btrfs/free-space-cache.c | 5 +- fs/btrfs/zoned.c | 183 ++++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 12 +++ 7 files changed, 216 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c94815cbd136..90c4279592a0 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1898,6 +1898,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache( INIT_LIST_HEAD(&cache->discard_list); INIT_LIST_HEAD(&cache->dirty_list); INIT_LIST_HEAD(&cache->io_list); + INIT_LIST_HEAD(&cache->active_bg_list); btrfs_init_free_space_ctl(cache, cache->free_space_ctl); atomic_set(&cache->frozen, 0); mutex_init(&cache->free_space_lock); @@ -3843,6 +3844,16 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) } spin_unlock(&info->unused_bgs_lock); + spin_lock(&info->zone_active_bgs_lock); + while (!list_empty(&info->zone_active_bgs)) { + block_group = list_first_entry(&info->zone_active_bgs, + struct btrfs_block_group, + active_bg_list); + list_del_init(&block_group->active_bg_list); + btrfs_put_block_group(block_group); + } + spin_unlock(&info->zone_active_bgs_lock); + spin_lock(&info->block_group_cache_lock); while ((n = rb_last(&info->block_group_cache_tree)) != NULL) { block_group = rb_entry(n, struct btrfs_block_group, diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 265db2c316d3..f751b802b173 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -98,6 +98,7 @@ struct btrfs_block_group { unsigned int to_copy:1; unsigned int relocating_repair:1; unsigned int chunk_item_inserted:1; + unsigned int zone_is_active:1; int disk_cache_state; @@ -205,6 +206,7 @@ struct btrfs_block_group { u64 zone_capacity; u64 meta_write_pointer; struct map_lookup *physical_map; + struct list_head active_bg_list; }; static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a898257ad2b5..bbe1a93a5d6e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1017,6 +1017,9 @@ struct btrfs_fs_info { spinlock_t treelog_bg_lock; u64 treelog_bg; + spinlock_t zone_active_bgs_lock; + struct list_head zone_active_bgs; + #ifdef CONFIG_BTRFS_FS_REF_VERIFY spinlock_t ref_verify_lock; struct rb_root block_tree; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 74b8848de8da..88c7b2dcf78d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2883,6 +2883,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) spin_lock_init(&fs_info->buffer_lock); spin_lock_init(&fs_info->unused_bgs_lock); spin_lock_init(&fs_info->treelog_bg_lock); + spin_lock_init(&fs_info->zone_active_bgs_lock); rwlock_init(&fs_info->tree_mod_log_lock); mutex_init(&fs_info->unused_bg_unpin_mutex); mutex_init(&fs_info->reclaim_bgs_lock); @@ -2896,6 +2897,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); INIT_LIST_HEAD(&fs_info->unused_bgs); INIT_LIST_HEAD(&fs_info->reclaim_bgs); + INIT_LIST_HEAD(&fs_info->zone_active_bgs); #ifdef CONFIG_BTRFS_DEBUG INIT_LIST_HEAD(&fs_info->allocated_roots); INIT_LIST_HEAD(&fs_info->allocated_ebs); diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 772485c39e45..e74e0ec1e3cc 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2763,9 +2763,10 @@ void btrfs_dump_free_space(struct btrfs_block_group *block_group, * out the free space after the allocation offset. */ if (btrfs_is_zoned(fs_info)) { - btrfs_info(fs_info, "free space %llu", + btrfs_info(fs_info, "free space %llu active %d", block_group->zone_capacity - - block_group->alloc_offset); + block_group->alloc_offset, + block_group->zone_is_active); return; } diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index cfc6d4337473..39468989a203 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -989,6 +989,41 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start, return pos; } +static bool btrfs_dev_set_active_zone(struct btrfs_device *device, u64 pos) +{ + struct btrfs_zoned_device_info *zone_info = device->zone_info; + unsigned int zno = pos >> zone_info->zone_size_shift; + + /* We can use any number of zones */ + if (!zone_info->max_active_zones) + return true; + + if (!test_bit(zno, zone_info->active_zones)) { + /* Active zone left? */ + if (atomic_dec_if_positive(&zone_info->active_zones_left) < 0) + return false; + if (test_and_set_bit(zno, zone_info->active_zones)) { + /* Someone already set the bit */ + atomic_inc(&zone_info->active_zones_left); + } + } + + return true; +} + +static void btrfs_dev_clear_active_zone(struct btrfs_device *device, u64 pos) +{ + struct btrfs_zoned_device_info *zone_info = device->zone_info; + unsigned int zno = pos >> zone_info->zone_size_shift; + + /* We can use any number of zones */ + if (!zone_info->max_active_zones) + return; + + if (test_and_clear_bit(zno, zone_info->active_zones)) + atomic_inc(&zone_info->active_zones_left); +} + int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, u64 length, u64 *bytes) { @@ -1004,6 +1039,7 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, *bytes = length; while (length) { btrfs_dev_set_zone_empty(device, physical); + btrfs_dev_clear_active_zone(device, physical); physical += device->zone_info->zone_size; length -= device->zone_info->zone_size; } @@ -1657,3 +1693,150 @@ struct btrfs_device *btrfs_zoned_get_device(struct btrfs_fs_info *fs_info, return device; } + +/** + * btrfs_zone_activate - activate block group and underlying device zones + * + * @block_group: the block group to activate + * + * @return: true on success, false otherwise + */ +bool btrfs_zone_activate(struct btrfs_block_group *block_group) +{ + struct btrfs_fs_info *fs_info = block_group->fs_info; + struct map_lookup *map; + struct btrfs_device *device; + u64 physical; + bool ret; + + if (!btrfs_is_zoned(block_group->fs_info)) + return true; + + map = block_group->physical_map; + /* Currently support SINGLE profile only */ + ASSERT(map->num_stripes == 1); + device = map->stripes[0].dev; + physical = map->stripes[0].physical; + + if (!device->zone_info->max_active_zones) + return true; + + spin_lock(&block_group->lock); + + if (block_group->zone_is_active) { + ret = true; + goto out_unlock; + } + + /* No space left */ + if (block_group->alloc_offset == block_group->zone_capacity) { + ret = false; + goto out_unlock; + } + + if (!btrfs_dev_set_active_zone(device, physical)) { + /* Cannot activate the zone */ + ret = false; + goto out_unlock; + } + + /* Successfully activated all the zones */ + block_group->zone_is_active = 1; + + spin_unlock(&block_group->lock); + + /* for the active BG list */ + btrfs_get_block_group(block_group); + + spin_lock(&fs_info->zone_active_bgs_lock); + ASSERT(list_empty(&block_group->active_bg_list)); + list_add_tail(&block_group->active_bg_list, &fs_info->zone_active_bgs); + spin_unlock(&fs_info->zone_active_bgs_lock); + + return true; + +out_unlock: + spin_unlock(&block_group->lock); + return ret; +} + +int btrfs_zone_finish(struct btrfs_block_group *block_group) +{ + struct btrfs_fs_info *fs_info = block_group->fs_info; + struct map_lookup *map; + struct btrfs_device *device; + u64 physical; + int ret = 0; + + if (!btrfs_is_zoned(fs_info)) + return 0; + + map = block_group->physical_map; + /* Currently support SINGLE profile only */ + ASSERT(map->num_stripes == 1); + + device = map->stripes[0].dev; + physical = map->stripes[0].physical; + + if (!device->zone_info->max_active_zones) + return 0; + + spin_lock(&block_group->lock); + if (!block_group->zone_is_active) { + spin_unlock(&block_group->lock); + return 0; + } + + /* Check if we have unwritten allocated space */ + if ((block_group->flags & + (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM)) && + block_group->alloc_offset > block_group->meta_write_pointer) { + 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 nocow writers. Zoned btrfs does not allow + * nocow anyway. + */ + btrfs_wait_ordered_roots(fs_info, U64_MAX, block_group->start, + block_group->length); + + spin_lock(&block_group->lock); + if (!block_group->zone_is_active) { + spin_unlock(&block_group->lock); + return 0; + } + block_group->zone_is_active = 0; + block_group->alloc_offset = block_group->zone_capacity; + block_group->free_space_ctl->free_space = 0; + btrfs_clear_treelog_bg(block_group); + spin_unlock(&block_group->lock); + + ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH, + physical >> SECTOR_SHIFT, + device->zone_info->zone_size >> SECTOR_SHIFT, + GFP_NOFS); + btrfs_dec_block_group_ro(block_group); + + if (!ret) { + 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); + + /* for active_bg_list */ + btrfs_put_block_group(block_group); + } + + return ret; +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 48628782e4b8..2345ecfa1805 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -69,6 +69,8 @@ int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical, u64 physical_start, u64 physical_pos); struct btrfs_device *btrfs_zoned_get_device(struct btrfs_fs_info *fs_info, u64 logical, u64 length); +bool btrfs_zone_activate(struct btrfs_block_group *block_group); +int btrfs_zone_finish(struct btrfs_block_group *block_group); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -204,6 +206,16 @@ static inline struct btrfs_device *btrfs_zoned_get_device( return ERR_PTR(-EOPNOTSUPP); } +static inline bool btrfs_zone_activate(struct btrfs_block_group *block_group) +{ + return true; +} + +static inline int btrfs_zone_finish(struct btrfs_block_group *block_group) +{ + return 0; +} + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Wed Aug 11 14:16:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09D25C4320E for ; Wed, 11 Aug 2021 14:21:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCA2B6101D for ; Wed, 11 Aug 2021 14:21:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232505AbhHKOVc (ORCPT ); Wed, 11 Aug 2021 10:21:32 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:35979 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbhHKOVY (ORCPT ); Wed, 11 Aug 2021 10:21:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691659; x=1660227659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sEFzRrszix1l6/flV4/Vc8Vbl2iM2mpVhEcj9YgXBHs=; b=hXhhN6+Zr/O48ODL3+PjJJ9IcfXvHRMijxORG7q8vL5NcGKTa17Z2dGC tA2seR7sHHFGYB8EAQ+STo0aoWCjVQz6lq82+nj2NAABx5YtntDVZY2e2 GDSq0zyh5hCzTs8TDxUrmxHwcrbkGOzpquRR629eprbOkMSehxsif4svw mwEqnvsJGH+xpcZRITjsB/0KWP5n83u/+uZoaS0UYnYKx1ugyFmOKzlQA O88+TKvO4VAdwkmZHvkDhF1CVV4ZlRn4tKJXWpSC/z8piqId4Br4lm+Lh bBh4ANHeI8id151eMZ/2TVdV/I2CKRJosst0C/2O7YSYLbEQmzjbD39Lk Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="176937896" 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; 11 Aug 2021 22:20:57 +0800 IronPort-SDR: hKclg5GTtOM+5aVnr4eJ17Rk1I4bg+moztezXzChVSo1sku/+YRPgCpGzEIux9pJCfAeHtHnaZ TEbI9kN39Zj0vYWZZAnd/QChaCaOB1YGsVBhSnlQ5BaPtyPpa8gol/pRI39+Wap2RUKBqiWdCM oaZZSuZklfhAbhfDrIzvjh6HqaxvTv6t0uVNXf8+nxwtmYfw2/Bz2DA1EhUrwpBaj6jIyqdGtb Yg9SO9o0oW1BQLsgQ6xdY0RwESCv+3aS0YnC8qVFGG4h19SwOvpmZNxB9S9VhY7hGBqJrid3nf LL+RTZVDbs21dinxjs9MPWbq Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:28 -0700 IronPort-SDR: 54gQQmasViOzuUtirGlerAt6MfVMWsuSZmsKUrdMWvm3OiN6ZNSLQXyDKNk5sjxILx7Wdb+a1i +y6DPf3WIURpShY27RcjfVEabXU/XmOvlaOdmXz56zjALjMAt9gQZpPUHy15uDrQ+D4ofnyHnP yQW5zARrTgeiu6dool6GeH1VyVntq7GchLIYrkD4qBsU7mJh03WSwbCv4S3vvcEjkWV995AVPp 4e3vU9mjgF878uWizVws/t8GkMKn1dbEg5WnGPxc8UKrdU85Z/aR3ApHtqtaWDYbTA35BQx7Vs Wys= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:57 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 11/17] btrfs: zoned: load active zone info for block group Date: Wed, 11 Aug 2021 23:16:35 +0900 Message-Id: <39157881e58cda60e4f5672dc87e9a2384bd4a5d.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Load activeness of underlying zones of a block group. When underlying zones are active, we add the block group to the fs_info->zone_active_bgs list. Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 39468989a203..f3c31159fb2e 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1170,6 +1170,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) unsigned int nofs_flag; u64 *alloc_offsets = NULL; u64 *caps = NULL; + unsigned long *active = NULL; u64 last_alloc = 0; u32 num_sequential = 0, num_conventional = 0; @@ -1215,6 +1216,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) goto out; } + active = bitmap_zalloc(map->num_stripes, GFP_NOFS); + if (!active) { + ret = -ENOMEM; + goto out; + } + for (i = 0; i < map->num_stripes; i++) { bool is_sequential; struct blk_zone zone; @@ -1298,8 +1305,16 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) /* Partially used zone */ alloc_offsets[i] = ((zone.wp - zone.start) << SECTOR_SHIFT); + __set_bit(i, active); break; } + + /* + * Consider a zone as active if we can allow any number of + * active zones. + */ + if (!device->zone_info->max_active_zones) + __set_bit(i, active); } if (num_sequential > 0) @@ -1347,6 +1362,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) } cache->alloc_offset = alloc_offsets[0]; cache->zone_capacity = caps[0]; + cache->zone_is_active = test_bit(0, active); break; case BTRFS_BLOCK_GROUP_DUP: case BTRFS_BLOCK_GROUP_RAID1: @@ -1362,6 +1378,14 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) goto out; } + if (cache->zone_is_active) { + btrfs_get_block_group(cache); + spin_lock(&fs_info->zone_active_bgs_lock); + list_add_tail(&cache->active_bg_list, + &fs_info->zone_active_bgs); + spin_unlock(&fs_info->zone_active_bgs_lock); + } + out: if (cache->alloc_offset > fs_info->zone_size) { btrfs_err(fs_info, @@ -1393,6 +1417,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) kfree(cache->physical_map); cache->physical_map = NULL; } + bitmap_free(active); kfree(caps); kfree(alloc_offsets); free_extent_map(em); From patchwork Wed Aug 11 14:16:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A089C4320A for ; Wed, 11 Aug 2021 14:21:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48FAE60F21 for ; Wed, 11 Aug 2021 14:21:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbhHKOVb (ORCPT ); Wed, 11 Aug 2021 10:21:31 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31791 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232543AbhHKOVX (ORCPT ); Wed, 11 Aug 2021 10:21:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691659; x=1660227659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tmr0/LZH6L0mF134k+SLQgfcNiGUcTiEeyyHTL/B2p8=; b=p9grAhtJKoQPVNvyZ4g0DphIwJY9k4ZfvHFg/esjIMZ5q6As5xl5HkDD VmTJD+Q/NvHfOLCV25TO7fXRM8LL8WJ+9pxGrZ1VMhd+7zAekN/WJdhdA VdiaSM1di7Al9Su2Sw55t81Z2GDoPC5Ln2WhAm4p7IuoEdBRSBK9uPDCW ggY8xfR931WDVdPWpskZUDrfIEnV1PtT8esFhAFOdra9n/HnqpRsdgifO NC1DytJNANWwPyuwqjRjWxUCebdxJpvDjbPvYnX5aPIGKkKZRAbfrSpst +bmC0JBcVht/jvzMCcdIS7KesOUD9LgLWK7gCntH91p3Z/ULHUjyygK+C Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="280761380" 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; 11 Aug 2021 22:20:58 +0800 IronPort-SDR: VUuJQDKykB/zeSwWpXcgjoqfVBdhXoN1dXHJ3Xcbxwp7Og65oy9VLYqio6HVgHgjFtBwF3fdNo iXwnGH2Atql0AqOMTfyY3QiNe98/YnKU86CAYrrnESoKAuu3tsscE4E4k1CLh83zcy41x8reQQ +FkrX80EmVbEbKHPkw8up8YHu6mExn3fcgoriZFret6d8hJZOHZovEMwBK7jBvHy+KKWXJO2C+ ePIWTEcdcXWzgHpG5RGkb37dAY2lyLG9Tah0tjymbsh/M1NvxzshVrGrUwCqfbh/GSv6wT0E46 eeBSptHQUtYhAi3338XrOC1i Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:29 -0700 IronPort-SDR: iy2L/Ni+TTyDZNJtxs66JaeIN85xVinjEcKIjXQG9HUz5QAqPkykgOBvAiVTE4jpqLga0wJqw2 EgxEaT1Dmjbu801VBVkjqh2Q03zJKtskuphRBrQJD9bAcNC5LOXaMc7lAI+1pKc5j7Ae924ZDX Nzv8vMAb7zTMjQo3SiueUSVgzNF8slXcyiZGCqwq36M2qEmjE4eDmnt1Hw1hDfn9MQ8PAONyNm FU88o2p2PVmQIew5y7vS3EXXd8sMB0e8gjT+iMjN5R1E5A/VQQjRxlCSQ7v8zvHXHDOPSfJCAG M5U= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:58 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 12/17] btrfs: zoned: activate block group on allocation Date: Wed, 11 Aug 2021 23:16:36 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Activate a block group when trying to allocate an extent from it. We check read-only case and no space left case before trying to activate a block group not to consume the number of active zones uselessly. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 8dafb61c4946..ac367f1dc4e6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3773,6 +3773,18 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, if (skip) return 1; + /* 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) { + spin_unlock(&block_group->lock); + return 1; + } + spin_unlock(&block_group->lock); + + if (!btrfs_zone_activate(block_group)) + return 1; + spin_lock(&space_info->lock); spin_lock(&block_group->lock); spin_lock(&fs_info->treelog_bg_lock); From patchwork Wed Aug 11 14:16:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B98B8C4338F for ; Wed, 11 Aug 2021 14:21:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9119D61008 for ; Wed, 11 Aug 2021 14:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232601AbhHKOVd (ORCPT ); Wed, 11 Aug 2021 10:21:33 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:64262 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232560AbhHKOVY (ORCPT ); Wed, 11 Aug 2021 10:21:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691660; x=1660227660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k1yNoVcCd5aPyEBAtdlR6pEGuekOtr26ywy3I2FMQOE=; b=QJQpOg9G+hcz0wryrk8ncMaNWXBq5gnbFZAFol+m5wmFZTAiC1T6ylfv FDsh2/354xybOAFLdXCSoiW8JqM4MpAZCHGT1kf2NyCufiWeklyvvnqr0 F6pNlQ+TQet2aTOIuTsWkcIbRtx4+7nkyZi/hDGqYcn5pdoE7aEhGWwW1 EdWWfgxpDUS/bUD9prgC3OG5yM/z9Mxsi7RwqYqgigIQ/QZDwQzs1z06O 2PzqyXcu7OYyxfaNfJK6OZR1SL9Xq1TsqRkYf8Fb1Z/OWfAUCr5GbebMt fcAGz3rgLBd6KWZZrp4QoFKyP6aMREK83z/N/AnUHyXCPCscQxEfM91i7 A==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="288506679" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Aug 2021 22:20:59 +0800 IronPort-SDR: jMJ/9Z4kum0U6sYVKlKaztGujPWhvyDfuPLcDjIos01x6VNod5CWNT1t6uigM2ZxnQ7UWrpEDI vnZxyj7BqceC3n1mDTsLSYdxsZTHg53nGQ8v/6SfTPtBvHZu1pDtxZSUg1psk+Hirf2CGKNYIy ahga3S6svYaJ2m0OvQNQKX2sD8/QjGBxIxVzJ9xwf+bQrsfZ6qF14pxEan3kz6kzIE8H4K5bh3 2NGAGjpjnw8bvx5eXTro7gb/4pT4mp46BRRsr99CeXeCKHene8nJzt2PkY/Tae8ByBx57sfSum gSfMxAhDGxGfJ3hkg0ur4QwX Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:30 -0700 IronPort-SDR: 1HF39dvzAf/DGJsfUV84Jj285+O5yIqJOwznr9Q6/FXnkk3uveqTACNMGkGECeDzodzZs6xTDL L4xiHoF4EogowhVNqdM3+r7SKBdOxF0wne2as3X8T+qWwbDXTbLbtqL6/+pqN4eyAmqLI3LhL2 qy9Jjdr7+DvHL1YRhPdhYqhknWDKFCW7cWptsUgNZNSClu1IZMQDx7kf+88U02gMo1TyP9EIB8 Y3W4ADY1kn42am4tDS9ucVsJc8MvVUbY/ItJp05AuRo08sCsB/Po10m9YcG08+RukvQldTKQWf yHQ= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:20:59 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 13/17] btrfs: zoned: activate new block group Date: Wed, 11 Aug 2021 23:16:37 +0900 Message-Id: <3967ca687f61272b719260b2c114d3c2531195d2.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Activate new block group at btrfs_make_block_group(). We do not check the return value. If failed, we can try again later at the actual extent allocation phase. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 90c4279592a0..f4fa65438eed 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2447,6 +2447,12 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran return ERR_PTR(ret); } + /* + * New block group is likely to be used soon. Try to activate it now. + * Failure is OK for now. + */ + btrfs_zone_activate(cache); + ret = exclude_super_stripes(cache); if (ret) { /* We may have excluded something, so call this just in case */ From patchwork Wed Aug 11 14:16:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB26BC432BE for ; Wed, 11 Aug 2021 14:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 153C160F21 for ; Wed, 11 Aug 2021 14:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232606AbhHKOVd (ORCPT ); Wed, 11 Aug 2021 10:21:33 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:64262 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232565AbhHKOVY (ORCPT ); Wed, 11 Aug 2021 10:21:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691661; x=1660227661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/BpbDK93nw+1bhmMiqkxfoz00aBEg5rmcp31KK0F73Q=; b=aSEmRvzGTgS3uy0VP5Eci6yQPT04zMm993/We7nBbl4kI3sMyA72YnDc o2ZwEniiddRbu5e0OYuLNRaYThCYWtR6BNb7HT2JyydFie/gs6HUTYULY odwwPkRoxfUBaf0JF/kQXKTYYEGgGLZL+YqBFwNN8MS06UoJt5fXl6dwL AKFcLF3ok8yO3QWZ7KVKZB6szNwdpF3pK3/5YUIHhqs0qLdbt22sYzIM+ z+zlIakOaDQKZmlISBKaQqYjHPlo+38SxHdA1P0Dk/1zQ9zERQKb4T1bD nr7QxnTpe+Z053htc8/MhS0oiFqjtW+a7kt7qDjEOMBI/MyKmDiXoc1yI Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="288506681" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Aug 2021 22:21:01 +0800 IronPort-SDR: 8SNKYf3Cc+w+ZVn4DmtbGtXVkmssfrdxwBMaKMYLubC1LvHxOg/xrrwkSiW7dgiurlJHaud+Nb 2wIl++FH6tZcVC0ED0Wj9LDybOWlF8Ejcc06Scl7g73vyPI++mWdF7uhnAxOFLapnG8G9eVbr+ YbGxzqtetGZHp7dcUVfgwZaLATWbfaArowRBKMvnVYsTdSsAGsEaAxrwQu21p9bmdzDDiqfMKf FrnMifKWebYwrz4JCM/LX87aPWUfNcGqCSWRffeihlc+bBsom6co+EbUEvGHQleiJrzxoMeAI6 Jnx6z7Bo60iLBWrf7tOThfIE Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:31 -0700 IronPort-SDR: vfPY2FsuJYMDF8r10NDIjnBfac5HKjqUgJhG2NtX7GSQxDVGHNhq4vzSh/Jdn0PT8wM6c1hvGl anVmc9bgImxIWGH1CGa1YlRH5QdF0Ow6FTa3UirwjgKC7jlwj4h11uakfzJU0q4Lro4Ac1w90k o1jneadIYzWQBytjP2x7IwZcnWT7Z4Afcdmny+BPK+sxdPNwEJQPUf88Ux3/eZqMfmJ+7Q9Jg1 mYU8jBmAAtTtbj/D7Oqn7900l70KauEzgvhrYJ+aDQt2fVJmKo1/ZfkR2/ISM3oV4J8+d2aNVg Vl4= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:21:00 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 14/17] btrfs: move ffe_ctl one level up Date: Wed, 11 Aug 2021 23:16:38 +0900 Message-Id: <7b764125432c7f9fc95eb8eddb4c481b6a4ac296.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We are passing too many variables as it is from btrfs_reserve_extent() to find_free_extent(). The next commit will add min_alloc_size to ffe_ctl, and that means another pass-through argument. Take this opportunity to move ffe_ctl one level up and drop the redundant arguments. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 162 ++++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 74 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index ac367f1dc4e6..1daa432673c4 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3476,6 +3476,7 @@ enum btrfs_extent_allocation_policy { */ struct find_free_extent_ctl { /* Basic allocation info */ + u64 ram_bytes; u64 num_bytes; u64 empty_size; u64 flags; @@ -4130,65 +4131,62 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info, * |- If not found, re-iterate all block groups */ static noinline int find_free_extent(struct btrfs_root *root, - u64 ram_bytes, u64 num_bytes, u64 empty_size, - u64 hint_byte_orig, struct btrfs_key *ins, - u64 flags, int delalloc) + struct btrfs_key *ins, + struct find_free_extent_ctl *ffe_ctl) { struct btrfs_fs_info *fs_info = root->fs_info; int ret = 0; int cache_block_group_error = 0; struct btrfs_block_group *block_group = NULL; - struct find_free_extent_ctl ffe_ctl = {0}; struct btrfs_space_info *space_info; bool full_search = false; - bool for_treelog = (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID); - WARN_ON(num_bytes < fs_info->sectorsize); - - ffe_ctl.num_bytes = num_bytes; - ffe_ctl.empty_size = empty_size; - ffe_ctl.flags = flags; - ffe_ctl.search_start = 0; - ffe_ctl.delalloc = delalloc; - ffe_ctl.index = btrfs_bg_flags_to_raid_index(flags); - ffe_ctl.have_caching_bg = false; - ffe_ctl.orig_have_caching_bg = false; - ffe_ctl.found_offset = 0; - ffe_ctl.hint_byte = hint_byte_orig; - ffe_ctl.for_treelog = for_treelog; - ffe_ctl.policy = BTRFS_EXTENT_ALLOC_CLUSTERED; + WARN_ON(ffe_ctl->num_bytes < fs_info->sectorsize); + ffe_ctl->search_start = 0; + /* For clustered allocation */ + ffe_ctl->empty_cluster = 0; + ffe_ctl->last_ptr = NULL; + ffe_ctl->use_cluster = true; + ffe_ctl->have_caching_bg = false; + ffe_ctl->orig_have_caching_bg = false; + ffe_ctl->index = btrfs_bg_flags_to_raid_index(ffe_ctl->flags); + ffe_ctl->loop = 0; /* For clustered allocation */ - ffe_ctl.retry_clustered = false; - ffe_ctl.retry_unclustered = false; - ffe_ctl.last_ptr = NULL; - ffe_ctl.use_cluster = true; + ffe_ctl->retry_clustered = false; + ffe_ctl->retry_unclustered = false; + ffe_ctl->cached = 0; + ffe_ctl->max_extent_size = 0; + ffe_ctl->total_free_space = 0; + ffe_ctl->found_offset = 0; + ffe_ctl->policy = BTRFS_EXTENT_ALLOC_CLUSTERED; if (btrfs_is_zoned(fs_info)) - ffe_ctl.policy = BTRFS_EXTENT_ALLOC_ZONED; + ffe_ctl->policy = BTRFS_EXTENT_ALLOC_ZONED; ins->type = BTRFS_EXTENT_ITEM_KEY; ins->objectid = 0; ins->offset = 0; - trace_find_free_extent(root, num_bytes, empty_size, flags); + trace_find_free_extent(root, ffe_ctl->num_bytes, ffe_ctl->empty_size, + ffe_ctl->flags); - space_info = btrfs_find_space_info(fs_info, flags); + space_info = btrfs_find_space_info(fs_info, ffe_ctl->flags); if (!space_info) { - btrfs_err(fs_info, "No space info for %llu", flags); + btrfs_err(fs_info, "No space info for %llu", ffe_ctl->flags); return -ENOSPC; } - ret = prepare_allocation(fs_info, &ffe_ctl, space_info, ins); + ret = prepare_allocation(fs_info, ffe_ctl, space_info, ins); if (ret < 0) return ret; - ffe_ctl.search_start = max(ffe_ctl.search_start, - first_logical_byte(fs_info, 0)); - ffe_ctl.search_start = max(ffe_ctl.search_start, ffe_ctl.hint_byte); - if (ffe_ctl.search_start == ffe_ctl.hint_byte) { + ffe_ctl->search_start = max(ffe_ctl->search_start, + first_logical_byte(fs_info, 0)); + ffe_ctl->search_start = max(ffe_ctl->search_start, ffe_ctl->hint_byte); + if (ffe_ctl->search_start == ffe_ctl->hint_byte) { block_group = btrfs_lookup_block_group(fs_info, - ffe_ctl.search_start); + ffe_ctl->search_start); /* * we don't want to use the block group if it doesn't match our * allocation bits, or if its not cached. @@ -4196,7 +4194,7 @@ static noinline int find_free_extent(struct btrfs_root *root, * However if we are re-searching with an ideal block group * picked out then we don't care that the block group is cached. */ - if (block_group && block_group_bits(block_group, flags) && + if (block_group && block_group_bits(block_group, ffe_ctl->flags) && block_group->cached != BTRFS_CACHE_NO) { down_read(&space_info->groups_sem); if (list_empty(&block_group->list) || @@ -4210,9 +4208,10 @@ static noinline int find_free_extent(struct btrfs_root *root, btrfs_put_block_group(block_group); up_read(&space_info->groups_sem); } else { - ffe_ctl.index = btrfs_bg_flags_to_raid_index( + ffe_ctl->index = btrfs_bg_flags_to_raid_index( block_group->flags); - btrfs_lock_block_group(block_group, delalloc); + btrfs_lock_block_group(block_group, + ffe_ctl->delalloc); goto have_block_group; } } else if (block_group) { @@ -4220,31 +4219,31 @@ static noinline int find_free_extent(struct btrfs_root *root, } } search: - ffe_ctl.have_caching_bg = false; - if (ffe_ctl.index == btrfs_bg_flags_to_raid_index(flags) || - ffe_ctl.index == 0) + ffe_ctl->have_caching_bg = false; + if (ffe_ctl->index == btrfs_bg_flags_to_raid_index(ffe_ctl->flags) || + ffe_ctl->index == 0) full_search = true; down_read(&space_info->groups_sem); list_for_each_entry(block_group, - &space_info->block_groups[ffe_ctl.index], list) { + &space_info->block_groups[ffe_ctl->index], list) { struct btrfs_block_group *bg_ret; /* If the block group is read-only, we can skip it entirely. */ if (unlikely(block_group->ro)) { - if (for_treelog) + if (ffe_ctl->for_treelog) btrfs_clear_treelog_bg(block_group); continue; } - btrfs_grab_block_group(block_group, delalloc); - ffe_ctl.search_start = block_group->start; + btrfs_grab_block_group(block_group, ffe_ctl->delalloc); + ffe_ctl->search_start = block_group->start; /* * this can happen if we end up cycling through all the * raid types, but we want to make sure we only allocate * for the proper type. */ - if (!block_group_bits(block_group, flags)) { + if (!block_group_bits(block_group, ffe_ctl->flags)) { u64 extra = BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1_MASK | BTRFS_BLOCK_GROUP_RAID56_MASK | @@ -4255,7 +4254,8 @@ static noinline int find_free_extent(struct btrfs_root *root, * doesn't provide them, bail. This does allow us to * fill raid0 from raid1. */ - if ((flags & extra) && !(block_group->flags & extra)) + if ((ffe_ctl->flags & extra) && + !(block_group->flags & extra)) goto loop; /* @@ -4263,14 +4263,15 @@ static noinline int find_free_extent(struct btrfs_root *root, * It's possible that we have MIXED_GROUP flag but no * block group is mixed. Just skip such block group. */ - btrfs_release_block_group(block_group, delalloc); + btrfs_release_block_group(block_group, + ffe_ctl->delalloc); continue; } have_block_group: - ffe_ctl.cached = btrfs_block_group_done(block_group); - if (unlikely(!ffe_ctl.cached)) { - ffe_ctl.have_caching_bg = true; + ffe_ctl->cached = btrfs_block_group_done(block_group); + if (unlikely(!ffe_ctl->cached)) { + ffe_ctl->have_caching_bg = true; ret = btrfs_cache_block_group(block_group, 0); /* @@ -4293,10 +4294,11 @@ static noinline int find_free_extent(struct btrfs_root *root, goto loop; bg_ret = NULL; - ret = do_allocation(block_group, &ffe_ctl, &bg_ret); + ret = do_allocation(block_group, ffe_ctl, &bg_ret); if (ret == 0) { if (bg_ret && bg_ret != block_group) { - btrfs_release_block_group(block_group, delalloc); + btrfs_release_block_group(block_group, + ffe_ctl->delalloc); block_group = bg_ret; } } else if (ret == -EAGAIN) { @@ -4306,46 +4308,49 @@ static noinline int find_free_extent(struct btrfs_root *root, } /* Checks */ - ffe_ctl.search_start = round_up(ffe_ctl.found_offset, - fs_info->stripesize); + ffe_ctl->search_start = round_up(ffe_ctl->found_offset, + fs_info->stripesize); /* move on to the next group */ - if (ffe_ctl.search_start + num_bytes > + if (ffe_ctl->search_start + ffe_ctl->num_bytes > block_group->start + block_group->length) { btrfs_add_free_space_unused(block_group, - ffe_ctl.found_offset, num_bytes); + ffe_ctl->found_offset, + ffe_ctl->num_bytes); goto loop; } - if (ffe_ctl.found_offset < ffe_ctl.search_start) + if (ffe_ctl->found_offset < ffe_ctl->search_start) btrfs_add_free_space_unused(block_group, - ffe_ctl.found_offset, - ffe_ctl.search_start - ffe_ctl.found_offset); + ffe_ctl->found_offset, + ffe_ctl->search_start - ffe_ctl->found_offset); - ret = btrfs_add_reserved_bytes(block_group, ram_bytes, - num_bytes, delalloc); + ret = btrfs_add_reserved_bytes(block_group, ffe_ctl->ram_bytes, + ffe_ctl->num_bytes, + ffe_ctl->delalloc); if (ret == -EAGAIN) { btrfs_add_free_space_unused(block_group, - ffe_ctl.found_offset, num_bytes); + ffe_ctl->found_offset, + ffe_ctl->num_bytes); goto loop; } btrfs_inc_block_group_reservations(block_group); /* we are all good, lets return */ - ins->objectid = ffe_ctl.search_start; - ins->offset = num_bytes; + ins->objectid = ffe_ctl->search_start; + ins->offset = ffe_ctl->num_bytes; - trace_btrfs_reserve_extent(block_group, ffe_ctl.search_start, - num_bytes); - btrfs_release_block_group(block_group, delalloc); + trace_btrfs_reserve_extent(block_group, ffe_ctl->search_start, + ffe_ctl->num_bytes); + btrfs_release_block_group(block_group, ffe_ctl->delalloc); break; loop: - release_block_group(block_group, &ffe_ctl, delalloc); + release_block_group(block_group, ffe_ctl, ffe_ctl->delalloc); cond_resched(); } up_read(&space_info->groups_sem); - ret = find_free_extent_update_loop(fs_info, ins, &ffe_ctl, full_search); + ret = find_free_extent_update_loop(fs_info, ins, ffe_ctl, full_search); if (ret > 0) goto search; @@ -4354,12 +4359,12 @@ static noinline int find_free_extent(struct btrfs_root *root, * Use ffe_ctl->total_free_space as fallback if we can't find * any contiguous hole. */ - if (!ffe_ctl.max_extent_size) - ffe_ctl.max_extent_size = ffe_ctl.total_free_space; + if (!ffe_ctl->max_extent_size) + ffe_ctl->max_extent_size = ffe_ctl->total_free_space; spin_lock(&space_info->lock); - space_info->max_extent_size = ffe_ctl.max_extent_size; + space_info->max_extent_size = ffe_ctl->max_extent_size; spin_unlock(&space_info->lock); - ins->offset = ffe_ctl.max_extent_size; + ins->offset = ffe_ctl->max_extent_size; } else if (ret == -ENOSPC) { ret = cache_block_group_error; } @@ -4417,6 +4422,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, struct btrfs_key *ins, int is_data, int delalloc) { struct btrfs_fs_info *fs_info = root->fs_info; + struct find_free_extent_ctl ffe_ctl = {0}; bool final_tried = num_bytes == min_alloc_size; u64 flags; int ret; @@ -4425,8 +4431,16 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, flags = get_alloc_profile_by_root(root, is_data); again: WARN_ON(num_bytes < fs_info->sectorsize); - ret = find_free_extent(root, ram_bytes, num_bytes, empty_size, - hint_byte, ins, flags, delalloc); + + ffe_ctl.ram_bytes = ram_bytes; + ffe_ctl.num_bytes = num_bytes; + ffe_ctl.empty_size = empty_size; + ffe_ctl.flags = flags; + ffe_ctl.delalloc = delalloc; + ffe_ctl.hint_byte = hint_byte; + ffe_ctl.for_treelog = for_treelog; + + ret = find_free_extent(root, ins, &ffe_ctl); if (!ret && !is_data) { btrfs_dec_block_group_reservations(fs_info, ins->objectid); } else if (ret == -ENOSPC) { From patchwork Wed Aug 11 14:16:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB2D1C43216 for ; Wed, 11 Aug 2021 14:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD32D61058 for ; Wed, 11 Aug 2021 14:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232565AbhHKOVe (ORCPT ); Wed, 11 Aug 2021 10:21:34 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:64262 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232579AbhHKOVZ (ORCPT ); Wed, 11 Aug 2021 10:21:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691662; x=1660227662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8w4RAOjUPA20HScXK3Yt59VVSfPX0uMg0+X+awM1CjY=; b=G0ar5I2xkAjpA/0PfrQPe3K3YIpu2mwEOex262e8GtnVHa8xa/wAsP5j R97AncCQuZ6qbrg19VKgs7oivrx+fbzvepZPO4H4cpNj5K4WmIZRJlhPL zWqrkDcRg5ZafABodBvsp4V0PbStj9Rvh0/38jEr64Hc6sm+4fqnTp1Fc /KIqq9Db7UgUQejh3WbqyumnWhk2Yv2riwUIclwrXkpXyJJG/+IUN9yf7 i1d04nfal8nsD6uiKFOnoueajeDrSlbqCO+BP2HSLxqkeZBCp1wfGO+A6 asqKf8cOuuJNq6zvB33TFR++Djxrwla2bIxuiW+ohvAXaBd6XX3a9+8wy g==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="288506682" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Aug 2021 22:21:02 +0800 IronPort-SDR: L/uxX8YFl+X6M4cVO6ezdq2bfaCAZoEdynoQO3O1JmSlRohvbIR+Da42BjrRtFSiBVwLcsqxeO LGNul078h1ORhiA/5WZOGQEhIPj25TMxPg/nfoRob6He9m/NpkJNoxh4mTM5gREj8ADqxT2xl7 3nKcxntwuWyjpbGasVPWPAmf9UtLRFGCx/1dw3IAufTd4ZE7LEOfjStx5cLnTdc/BZJ81WDTtT x5FM6+s2TgtQ/r+0ifor6rsJY99eqTIlEH0H03kfI5ZcPYt04Lr8bZoXA6tSyKyzWnJUlEYj74 lk1hP2WgyX9lRlSTH/iWQ1p1 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:32 -0700 IronPort-SDR: /nzF8WDgotykZS466CLiYMtHCbeMuePed09il8f6TQTkzeSUUoS1g2CJ/bP+sKYFN2D6hTTPep znJmwDCZb7JhEVzQa6JAHHvyv6XnvhtqWRB0rtUgjV6RDy1j6EMq0Zk/zEfB9g7YEI2hl2eSZn Tu/Zn8foTyPNgTGYCkDCRy5+uLufxkRTIDQwuBMk+o1CNVfG2kFrPR8xwNxBxhiPWUPgKxK8wL dI7xCDX1grPXDUrNdIwEsVcpdGL3SzFD+fQZMpOHD6tt99rph35wXQLtCsUKJvZtf2sfM1J537 Hw8= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:21:01 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 15/17] btrfs: zoned: avoid chunk allocation if active block group has enough space Date: Wed, 11 Aug 2021 23:16:39 +0900 Message-Id: <088da5a824e90055b7171b4c47e7c42d073c050d.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The current extent allocator tries to allocate a new block group when the existing block groups do not have enough space. On a ZNS device, a new block group means a new active zone. If the number of active zones has already reached the max_active_zones, activating a new zone needs to finish an existing zone, leading to wasting the free space there. So, instead, it should reuse the existing active block groups as much as possible when we can't activate any other zones without sacrificing an already activated block group. While at it, I converted find_free_extent_update_loop() to check the found_extent() case early and made the other conditions simpler. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 27 ++++++++++++++++++++------- fs/btrfs/zoned.c | 32 ++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 8 ++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1daa432673c4..b11097f557f8 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3478,6 +3478,7 @@ struct find_free_extent_ctl { /* Basic allocation info */ u64 ram_bytes; u64 num_bytes; + u64 min_alloc_size; u64 empty_size; u64 flags; int delalloc; @@ -3946,18 +3947,29 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, ffe_ctl->have_caching_bg && !ffe_ctl->orig_have_caching_bg) ffe_ctl->orig_have_caching_bg = true; - if (!ins->objectid && ffe_ctl->loop >= LOOP_CACHING_WAIT && - ffe_ctl->have_caching_bg) - return 1; - - if (!ins->objectid && ++(ffe_ctl->index) < BTRFS_NR_RAID_TYPES) - return 1; - if (ins->objectid) { found_extent(ffe_ctl, ins); return 0; } + if (ffe_ctl->max_extent_size >= ffe_ctl->min_alloc_size && + !btrfs_can_activate_zone(fs_info->fs_devices, ffe_ctl->index)) { + /* + * If we have enough free space left in an already active + * block group and we can't activate any other zone now, + * retry the active ones with a smaller allocation size. + * Returning early from here will tell + * btrfs_reserve_extent() to haven the size. + */ + return -ENOSPC; + } + + if (ffe_ctl->loop >= LOOP_CACHING_WAIT && ffe_ctl->have_caching_bg) + return 1; + + if (++(ffe_ctl->index) < BTRFS_NR_RAID_TYPES) + return 1; + /* * LOOP_CACHING_NOWAIT, search partially cached block groups, kicking * caching kthreads as we move along @@ -4434,6 +4446,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, ffe_ctl.ram_bytes = ram_bytes; ffe_ctl.num_bytes = num_bytes; + ffe_ctl.min_alloc_size = min_alloc_size; ffe_ctl.empty_size = empty_size; ffe_ctl.flags = flags; ffe_ctl.delalloc = delalloc; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index f3c31159fb2e..850662d103e9 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1865,3 +1865,35 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group) return ret; } + +bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, + int raid_index) +{ + struct btrfs_device *device; + bool ret = false; + + if (!btrfs_is_zoned(fs_devices->fs_info)) + return true; + + /* Non-single profiles are not supported yet */ + if (raid_index != BTRFS_RAID_SINGLE) + return false; + + /* Check if there is a device with active zones left */ + mutex_lock(&fs_devices->device_list_mutex); + list_for_each_entry(device, &fs_devices->devices, dev_list) { + struct btrfs_zoned_device_info *zinfo = device->zone_info; + + if (!device->bdev) + continue; + + if (!zinfo->max_active_zones || + atomic_read(&zinfo->active_zones_left)) { + ret = true; + break; + } + } + mutex_unlock(&fs_devices->device_list_mutex); + + return ret; +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 2345ecfa1805..ade6588c4ccd 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -71,6 +71,8 @@ struct btrfs_device *btrfs_zoned_get_device(struct btrfs_fs_info *fs_info, u64 logical, u64 length); bool btrfs_zone_activate(struct btrfs_block_group *block_group); int btrfs_zone_finish(struct btrfs_block_group *block_group); +bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, + int raid_index); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -216,6 +218,12 @@ static inline int btrfs_zone_finish(struct btrfs_block_group *block_group) return 0; } +static inline bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, + int raid_index) +{ + return true; +} + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Wed Aug 11 14:16:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58D71C43214 for ; Wed, 11 Aug 2021 14:21:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BD0B61058 for ; Wed, 11 Aug 2021 14:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232613AbhHKOVe (ORCPT ); Wed, 11 Aug 2021 10:21:34 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:64262 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232569AbhHKOV0 (ORCPT ); Wed, 11 Aug 2021 10:21:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691663; x=1660227663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DCMYMtqFpDFyOOdJko3C5IjxZKrtDPP8ckrvlJCHExk=; b=f/G3xtx5aG189/YxGzDFhhf1qPJbo39tHk0iDk9FTihz6cA82l+eMqpm fZc+y0T+Qv5Bz93LBTsR+TJomQBATfWQ7dIwoojqn+9FQGehY8Nd1zEbX u+tzJEK+PSUib9+OFfWZoYSXV9OJ4y4+vMDs00fPqb1QidzKGOyw/GRnM eNqzoCoMBoWGvHAgfln339aGvRZbGdYgCxvgmeuT+5e2bkZB9Tck4kN0K u3tPmNNNIzHTwUMiwa0oDDrcOhq/f2kbLSyYy9lt6lrMLI3/BXg7709u9 Gj2QDY1cE9mTXBDDx6unjtEtyzGH0o65PKPZ6EQpkCgrIMim+uFoQDvKj Q==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="288506685" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Aug 2021 22:21:03 +0800 IronPort-SDR: Z4KJZGKySDA6nMkIJ++nVyYDsxwjvmjmAO6Z7J36+G62zrAIH8S6+z9x/83A02ndeDuPdpUa6p 2CzZfRNsw9FTPgfiFOFppnh3gZHE8Z3vQTPdPLaKF2FR/B1fJCNSI56amNUJYitpfBhkmFT6Xm zXRvVZ3O/UlKo3WkGObxpnxVIkWUZA5xfNk6WAGtPN+FZ+1NwQJyJS/YBAqJ6+TwOziXlbsB35 Pojii/lYyh04SBX1QCUuDQqMD/B/o0/o12dTRPybomeJ5wfyVkqresBnxJ/ZY7g/Q1OnFKcyrJ FUKFroNz0uvs5amu5+IMR+88 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:33 -0700 IronPort-SDR: HGTQvSz72Jp4ri404OHS16CASgA/Mm2p85o77y+Wt1p0lqpVwt/09pkXQIQ44C99cs8YjDt2sn b5uxgXS4H0NS0s/o8e8BzJ+TU2GxpSZfLVddx2/O0jGUVHmy8HpEFicRDPqALy8+kJxopxfjdk 4vll1x5KKvjopQ1RlGscg3fdtVYl/6dB2l0Uga3pjapE6u/oevvfPb3gOvtY4jidiRY4lEC9Vj Ysuj+mpSydocp9V07Tq4dRV0rXtjwOhAVa31PxH9pxEHvcIuAOBgInfeyO3CSz5E30sE6/ilJ6 emc= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:21:02 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 16/17] btrfs: zoned: finish fully written block group Date: Wed, 11 Aug 2021 23:16:40 +0900 Message-Id: <59c069e3890f3cbc7fa425cdcf756d241a8bfc92.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we have written to the zone capacity, the device automatically deactivates the zone. Sync up block group side (the active BG list and zone_is_active flag) with it. We need to do it both on data BGs and metadata BGs. On data side, we add a hook to btrfs_finish_ordered_io(). On metadata side, we use end_extent_buffer_writeback(). To reduce excess lookup of a block group, we mark the last extent buffer in a block group with EXTENT_BUFFER_ZONE_FINISH flag. This cannot be done for data (ordered_extent), because the address may change due to REQ_OP_ZONE_APPEND. Signed-off-by: Naohiro Aota Reported-by: kernel test robot Reported-by: kernel test robot --- fs/btrfs/extent_io.c | 11 ++++++++- fs/btrfs/extent_io.h | 1 + fs/btrfs/inode.c | 6 ++++- fs/btrfs/zoned.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 8 ++++++ 5 files changed, 82 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index aaddd7225348..c353bfd89dfc 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4155,6 +4155,9 @@ 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); @@ -4756,8 +4759,14 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc, free_extent_buffer(eb); return ret; } - if (cache) + if (cache) { + /* Impiles write in zoned btrfs*/ btrfs_put_block_group(cache); + /* 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); + } ret = write_one_eb(eb, wbc, epd); free_extent_buffer(eb); if (ret < 0) diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 53abdc280451..9f3e0a45a5e4 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -32,6 +32,7 @@ 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/inode.c b/fs/btrfs/inode.c index afe9dcda860b..1697f745ba5c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3010,8 +3010,12 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) goto out; } - if (ordered_extent->bdev) + /* Non-null bdev implies a write on a sequential zone */ + if (ordered_extent->bdev) { btrfs_rewrite_logical_zoned(ordered_extent); + btrfs_zone_finish_endio(fs_info, ordered_extent->disk_bytenr, + logical_len); + } btrfs_free_io_failure_record(inode, start, end); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 850662d103e9..dd92e48b7f56 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1897,3 +1897,61 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, return ret; } + +int 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; + int ret; + + if (!btrfs_is_zoned(fs_info)) + return 0; + + block_group = btrfs_lookup_block_group(fs_info, logical); + ASSERT(block_group); + + if (logical + length < block_group->start + block_group->zone_capacity) { + ret = 0; + goto out; + } + + spin_lock(&block_group->lock); + + if (!block_group->zone_is_active) { + spin_unlock(&block_group->lock); + ret = 0; + 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); + 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) { + ret = 0; + 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); + +out: + btrfs_put_block_group(block_group); + return ret; +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index ade6588c4ccd..04a3ea884f3b 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -73,6 +73,8 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group); int btrfs_zone_finish(struct btrfs_block_group *block_group); bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, int raid_index); +int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, + u64 length); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -224,6 +226,12 @@ static inline bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, return true; } +static inline int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, + u64 logical, u64 length) +{ + return 0; +} + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Wed Aug 11 14:16:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12431343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 896EDC19F35 for ; Wed, 11 Aug 2021 14:21:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F7A261058 for ; Wed, 11 Aug 2021 14:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232619AbhHKOVf (ORCPT ); Wed, 11 Aug 2021 10:21:35 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:64262 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232589AbhHKOV2 (ORCPT ); Wed, 11 Aug 2021 10:21:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1628691664; x=1660227664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IXGcHTvcO8/97MMlcg6RC9p5lmMrS0EvWusxl5o2mPo=; b=RodUagJlVrx5D5cENy9LMEp7YcQYsAkVx6eQMN2Qq2zS7oTrUGk/q7TL KK3Z83V06CbaC7n4QcLyQmRKt3xFVXckSrIhJe7jcMnZAKnfgcRim9qrG kADk/IRR5IN+NgUJTFIUJOnJ1aAzp8jMJa1Bc5tJOfIhPuA2Nr0RjIygA AdUDy9YgC9Bp50ZmWN+6U7gUcTMakMiLqKngrMphSRk5VYm1JthFhLuR8 WFj5iV/JW+9T8Gy19U/wxLWhCdAoCc2uVMn+3pWwRm+NBmpwjhCRmZCF/ 7NkULO3t9wISaY+PpTH6pHNWZdpsd3x6ocpijv8erZuZ3HXk6DmPgJ4QD A==; X-IronPort-AV: E=Sophos;i="5.84,313,1620662400"; d="scan'208";a="288506686" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Aug 2021 22:21:04 +0800 IronPort-SDR: zqmdcPOKnagUIrzbkniSCvNZlmsYy4dfopJ4NR7duF50Nc+CKa9j0lP6U19p+jqsFjHXgpN3r4 9y9+y/ujeNCtBg/hux2EVbzE9aLsHg4BZhrN7p27JqsPV21tuIQBHqkSm58iOurGbBBegSCdPT 8iM1faf480dXc8jJBxvXNY/deiECmh9ntaKQOJxyW3x90m7Mq2mAV/y4nIDQpDV+rBm3etp4PY /ciG3SqAG7OFnYByH4L46naXm0zLgiIxlLGWeqwuYkGIL8/hBMwZ86qjqJEx60iHJ7ZHU2Q3Xs m8VuIlq7wVfm6mMMSrz0MGBl Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 06:56:34 -0700 IronPort-SDR: sdwbAEqzWLXkmuiau7TrmMwCpVKn+Cjb1m+gdUymCvtVQ4XURUhIzf8rCQnbtmMjBj5u5NGNtA IL5svIeUsKEmABwqOh1o6ZFwXNm+VuqR/LmLcb5ZlrGBo3W1PCocgUQR3PcPWgPI6cgYt7yYNc RTpuxF4xtjeYUOWrlEgatE0hF5/U5v6gZyF33ndNPSVelM1+yUt4B29Eck6NPAMmucJRckFBUn 1Ioa72zEtz2/hzmDlku1STj5coW+/+FLr+LFj7Frk/jQXvugY45slIagCDYyLwTPKzKT9cPRyO qy8= WDCIronportException: Internal Received: from ffs5zf2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.58.251]) by uls-op-cesaip01.wdc.com with ESMTP; 11 Aug 2021 07:21:03 -0700 From: Naohiro Aota To: Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 17/17] btrfs: zoned: finish relocating block group Date: Wed, 11 Aug 2021 23:16:41 +0900 Message-Id: <0abc5803aae3b4be8fdb3c74d7c4e9b4199b0257.1628690222.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We will no longer write to a relocating block group. So, we can finish it now. Signed-off-by: Naohiro Aota --- fs/btrfs/relocation.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 914d403b4415..63d2b22cf438 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -25,6 +25,7 @@ #include "backref.h" #include "misc.h" #include "subpage.h" +#include "zoned.h" /* * Relocation overview @@ -4063,6 +4064,9 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) rc->block_group->start, rc->block_group->length); + ret = btrfs_zone_finish(rc->block_group); + WARN_ON(ret && ret != -EAGAIN); + while (1) { int finishes_stage;