From patchwork Thu Aug 19 12:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447025 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 3B73EC432BE for ; Thu, 19 Aug 2021 12:27:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2267E610FF for ; Thu, 19 Aug 2021 12:27:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237181AbhHSM1q (ORCPT ); Thu, 19 Aug 2021 08:27:46 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbhHSM1p (ORCPT ); Thu, 19 Aug 2021 08:27:45 -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=1629376028; x=1660912028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f6BxxfhE6yJfXIxYSIJEVj9WicS6L5jJXwSNgqrmtjI=; b=RILnBUQJNC+LtfQxIlqvVzdGdTk3JdfLACcsidi8KdFx5WwpC4NlooR6 l1GkX1eKsjX3ALCb7U2SEKMpQ8AXpJp61Zqk2ZwIjJj8x4zA8k+lp0Zvz CdCNLrGKHYd7tdOaXbdcshjtatjK4W5qT5NLeyFLvBxQGX5NN347JJHaA hBEVeXn0C0u4KVkiur9F/YXxLO5zG1VV7TsjpsoMJi5gD7igdJPcy0vo8 MFikml9r2D4Rl5tEyH08NvjbQ24BCPFemLBb2s3vkRH3+em2uoGWL+pHI 5X3EVXHQsgj/wXXGi1G7WnNw7ex6twV8TmtMYhDcpdNLz1JDlNfDz9m6V A==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773521" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:08 +0800 IronPort-SDR: vcx2gXll197pPwCZsmZ5J3zpXsrBiSqCJYuBsGhHSjU0Qcp9xmmtO7cl+cp53NV08KG8GKUAIU vsvtHoBk91V0sJUicdUISXeMgIFr+E5si1N3U5D85qQYE1YkSYPQ3zfAgGUKIemJxa04hLiA9e 9zFHXDShPXTK+GD3ejfTu+S/DXOJxX7iBCgRTBmGNmFqBpheK03yPlMz0rCN9IHoLvcLge7O6V wSuD7GxygS5lVJUVldlpwTKeQJP+akxLnyGxGsJ/+3dZxBc06tFJvMyc3oLeRd+G56IW1v6bQ4 gd+08FFA3M94FDr8+zBGrdl+ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:16 -0700 IronPort-SDR: 3h9WQSmutzbKX9IyUZ77MkcJ/0IOZ7RVUjIpsXeU1+Tqe70HtQRaXZ84CurAPTSu/L5X+eCL+9 CZvD7PqEB+IBtGIJJ1pO9c7cAxb5L4kvn3b7hvVrF0jSH6VeVsx/GaHMlEl9mBqLOD+KrAG/Pl 1BbFlJEI8+Imxn8AlAd9+x6FbQ7l5P9fD2kVLyr0+E7hI+FpNeHrgSCJfRaJZa9iaankOp9LhU DyGs4b20Jl6drVlGER96Ym2CXtP5xkPtkr3uqZFbxsRS0bvhFkRDa6v75zumiqxnEUQ0n7i+3i 620= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:08 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 01/17] btrfs: zoned: load zone capacity information from devices Date: Thu, 19 Aug 2021 21:19:08 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 Reviewed-by: Johannes Thumshirn --- 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 Thu Aug 19 12:19:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447027 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 3FEAEC4338F for ; Thu, 19 Aug 2021 12:27:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2252961130 for ; Thu, 19 Aug 2021 12:27:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237873AbhHSM1r (ORCPT ); Thu, 19 Aug 2021 08:27:47 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbhHSM1q (ORCPT ); Thu, 19 Aug 2021 08:27:46 -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=1629376030; x=1660912030; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=La+dvmN1ehrQvyoiJaDHLq9VrKqIQQ51COnMnaS7eWA=; b=qty4BEl1p7v115qoR1UYC3lLfjDz2eZoT6WgTEsjaONkPybeeXVewXKb 65IYJiJNx9oRk4Fe+lARfX98/PDowX1Zy6QEiTlgK9tpOjjYN9z5aK849 3u1AXcUGOX5noQ/Lyr2IQFJi2mBmUfsfXTsNmTfeJIB6u89AGL4AAxEKX w2/QG6gPi2HvsZ9uHwySMxbwWfPyeau57GwGqYkNyyEg6pNMOHkzOlD4m W8r+TcqFCBVX7VoSBriiIqgEExcSfaRASKWwfKi3M6hZRyA8OS/Bs7g/0 rLQQBLBlxYxvMY0ZvbppCARpPD1wbytxdNQIeGV86/BuAHS985JArK80d w==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773528" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:09 +0800 IronPort-SDR: oB9Od+J705u7Ip31V9ja3Qd2BIZ1hUJVjj4pb0RELzvJfWv9tvJaUwH3zXCTq9F0e42C0ASSrs Tlgr13zvLdRiyTR+VLEdDl0iMKgFEZQ1jXgA/Py4QazaEb+2/koyVIWuH0hNgchpoPEeoPhMAx ZIq0gd0A9boMYokmV+syugw9/CzeEzTokQ1JiHEP6YaI6jRNU1MsSgqRnFdVUy7GAVbaMwzzkL YDkGDuVyvItM1jAapdpAbx2dTsBe+zc6gkMSYVMwsDPPRzSgKA2m8ZecHVf/eoDSc3kZsGeV8W aZtlH8ZsacQsqpnXrJ9dXyXE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:17 -0700 IronPort-SDR: YPA+yBjz5C7O8Nbyd03R6sD4O5eNyL93s7xO1PJVoiMy68BPskZZ0ZAe0esDD7F9KZ13DoOMM/ 3e4MYAjuZ7HqMUBmqozNzPf0xZhs7dPYrotuI8He61/8ciY8AEA52fQI0IMK1tg75XL8xCcAsx /HdOyJKvqAYG5VLCpjvBMzZ3ItEHi4umYDc7+d32GgvTIyu7Z3Dex9/bewF/og5KGLUmdQ7IrP /4XT1qU1GUr708MUtZLvZrI5tZinrlvREWouw9m573i6cC9CozFsMII8eFRnHf/Y28sfru5NTb QRw= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:09 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 02/17] btrfs: zoned: move btrfs_free_excluded_extents out from btrfs_calc_zone_unusable Date: Thu, 19 Aug 2021 21:19:09 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 Reviewed-by: Johannes Thumshirn --- 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 Thu Aug 19 12:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447029 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 041D3C4320A for ; Thu, 19 Aug 2021 12:27:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB8C66113B for ; Thu, 19 Aug 2021 12:27:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238208AbhHSM1s (ORCPT ); Thu, 19 Aug 2021 08:27:48 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbhHSM1r (ORCPT ); Thu, 19 Aug 2021 08:27:47 -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=1629376031; x=1660912031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HAT/VgPluIB3gFUuzNyb0ZUhdezpOQr+dsUpmUXU3hE=; b=M/SAYDR7zj+IT+N5Y0qm/Yw6ivDkWurmX6I9sLccQEXJQjGvIgE432uH MsIQ+oBeyFWka1AP2Ue7PRekLHE3yK306m9BbjeCXDeW4b+zKtfQPQyG8 OLwnTsmRDykBajG47rTciU+nm4dmSEEgoxQAQAFLrwtvz2IybMtx3Abdc iIIOdTV+W7d4+yrF/jT9c4KDOl6hYitSK5clcx57mw1vX7gwpwOx8SXqV FQvybLfZ8v0fMDpLCCv/P8adFLDtGA/3PUv/1AZkhIYESd0a6iTkai5A/ yq7H+rSonm3Eo5Bs7l3u3g6z5NZY7NOdqGski/dxq73GTJSiEqf8GiKuH Q==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773537" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:10 +0800 IronPort-SDR: PbJhzGdK+ry9kCtXPLckYGWLinBPpNOanEe4ZI7FSObi2EFg8uljcZEcOZPbOdwJAd1fs6JdW4 g6yQ5CkhJ8G6fJNdCLI06OiMr60JCIwpgjSPibHT3pxGlUu0Z6SndWsGLgnuxbD3WXL4OHjxmf 3H8WYOZJX2Lspd2L7peTdCu63O5pT43GUWYqBeBoswyM4kG0kDTKaTPwryInISoI1xJqpmhCSW S1xeMHmgrbsQquXNWyZvc3uP9Z8A0TxtJ/EHyPgj3a+2kdToqyOyzROkIcfVdZNDBGNAThhhMA QaZ83lf3BRFvCl/VoHkB2p9S Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:18 -0700 IronPort-SDR: 6hkz2LnmoR/l89TNvueBD6fZ+XP1+6WPe3Y0XJRPDCq75eLH3eKk+rsSpHrv+y21j+eowSt0HW zNt5gVjyorMZ3pfsCReOBNU6Wcj7PGYDRboFFGnGBT3Ixk+402XFQosexzGW/GFz8VpAsPDYLn q9eniNrB4jujAu8NhMZqlvxv6wA8iXc91ZSncURa9hRywts4aTHmNguv3Tpux6MTlYLFrHsJSH 08RDny1mdVeaI9QjpIE1WW9xvLC+00aZOSu62iMxHwQKJbpD34Pv0vxiwEI1bGQU5YCWy2yhWW Le0= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:10 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 03/17] btrfs: zoned: calculate free space from zone capacity Date: Thu, 19 Aug 2021 21:19:10 +0900 Message-Id: <03bf2db22301fcc6706d489dab1dc3ed6ac54a8e.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Reviewed-by: Johannes Thumshirn --- 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 Thu Aug 19 12:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447031 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 EE7A3C432BE for ; Thu, 19 Aug 2021 12:27:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB87861130 for ; Thu, 19 Aug 2021 12:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238398AbhHSM1t (ORCPT ); Thu, 19 Aug 2021 08:27:49 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbhHSM1s (ORCPT ); Thu, 19 Aug 2021 08:27:48 -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=1629376031; x=1660912031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9ygmk8frqqRLA+R0ay5h/OXXHb75Rhv1gfiXwm49eok=; b=k80kRhvFZMC4f129FHjemA05Rgn67zmzmnmjMRsWn0wnnf7llGKbNL+S YJ/b+9yumh44GE03oKs2/ZCjOVL0XRngcqmfiV3LuSwWYLFjcnATyIW3Q i9FhS4jO4KlL+OBRgV9k/pfT0iYQNaWCNbhwCsyzbchHYzRsOW2+trBy2 5flKY457nRVsIkrLsgF95+kaHCu7L86lMcP4S/4z1dvDRIxRpeRWXJ0F2 10RmPd893Js+rLTYKWzGnszZB7zr440vV+33sEYhdGU9a0chmPadOyrU7 d5gQGaoC4tWVpki3luOHVmymNw4HSZB1XE8Kk7D2XiCIbV3krl8rn9N4Y w==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773545" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:12 +0800 IronPort-SDR: MzHXS4qZRjUUX47jalDoRIiA3slKyE7vd8F6ey1V29XrIxGJ+6wwymWzVdKk+K48PY60506Min mQJfbLdXISEz0UJx95QgzlVSCm/+8FS37BEAF0d9eqvJFJhcltTQIdQui4XQCuXcn+1lX5ns5u 3Kfc/LJMeTSZ7TzaFhWSWm+DE/SCqWdf0Zs8yM3hJmG442rVPCfVZETs0ns2gLc+Uxzm0ReDP0 qtTIPZ7TxoEAWMZmk5Vg8qiONl8lf9cQOjvwXVJNtf6lZXAxhR9DEpkIV7yDZ1gxa+0FqLM3AF EY1dNOKQrvj4GwF4EhZf+KOQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:19 -0700 IronPort-SDR: iJ0EfRfsn9R4+omtMG7bEOb0TBxQaCyU0/rzpKy1OXVVTwAYlwUq4wBYxbNHzIQFVWjS9X6VMk 8sFRZgY9Z7bjASP18i9WrPjWc7gMLciaOINKhteuj6/tvmUbc6N+E4Zj+95huDqurs6ilQn1o0 ht6h9gjlcOmSvCmkvSMrB2DEJ+lrH/8wnHINfYhHeNOBqPPrqG7at2VE8DyHtDzC11tuwx3+p4 hcDF23vfnVJjT4iI59icddAHJyx04krmOMq9LxYPsHSSxWSkM2FYwZOZSlaSkJjR8IPz+L5Yk5 zRg= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:11 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 04/17] btrfs: zoned: tweak reclaim threshold for zone capacity Date: Thu, 19 Aug 2021 21:19:11 +0900 Message-Id: <7af8015000f794f3481a2a36a25391dea0d8124f.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Reviewed-by: Johannes Thumshirn --- 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 Thu Aug 19 12:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447033 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 0B82DC4338F for ; Thu, 19 Aug 2021 12:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E47EF610FF for ; Thu, 19 Aug 2021 12:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238818AbhHSM1u (ORCPT ); Thu, 19 Aug 2021 08:27:50 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbhHSM1t (ORCPT ); Thu, 19 Aug 2021 08:27:49 -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=1629376032; x=1660912032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NvhEHYRf6v9MLv00R1539/6EIQsm/kkL5qMr7mYZfuw=; b=n4AFHGV2qudguRv8NE0xuD1uPh/rozwgaBakza+ssJBScyOpphZv5yd3 LGbet0ArCgqrVQSqye1YtS7EGMSxZSFNMcfmhZed66ZRwotnNi3+wl0oo phKZyORDUr2dYTqlgnsAr7xCko4RZbqO80Bh/O92fGR3kIzisDehMriHW R4rv53AU+fixcZDVYV3dRo5tQrfmeTtr263pve6cXeasKwJGbWkaK6JEJ ZrOAM8v6gEP6wpqWwmx2pKRElD4hypqvuVT+Y+TwW0zUFIzEU0XtqaoK8 jTuTCTI7cYlaWKtCdRVcOLX8KnmaPNExMFJ6/IOwH3ZO2S2G4OSHPHQCx w==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773553" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:12 +0800 IronPort-SDR: EPABFxRaWILz5cAH1QH+1ufdOSkvH4tRxfObvoTjb3hdxRDQamZJ7LXMdnq8QbBtUlC7/kd0T1 Tbgsmvl5cvbrao5xR1fxZiB8s6chpONt4ARL0nYQ6I04pgszcfrVhT9DPSOIP+MVAogWWQGsEp zSMddwGftiheQPbexo4RYCclHDTFHazJsXGG9WzVggaba2lBQ7/UM842tOl7N5/XJC3RdRzbWj zOcc1T0hv8/+bNcXGH4R1hu5x1HYjasZfNFdhB8eMm7QLFCOQPlehlLGIf0ixuvja9yv8JuhwA zIHKbBAc2sx2b/cJOIcQDCjS Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:21 -0700 IronPort-SDR: nOrJ2Hg3qzL+nlbs9xGMtsDAf6byYNXdvF9WrGbFLTFF9UWCL/4BgkRvTFF/n5RhJrSWTBvqwh A/aB7x82DeRIMQLYkUc4FFTZK21qnC4ekOco606SEHcXE0FeWnful9Ok8x2h8kmPcgXE4CfZl/ 95Otep7Lk3Fi/PxS7WQ8TX1aQGb0zlk21K7gAk8GuiqCeQCx3jSyq6w+CxbzZkMQpNeZAFNGG+ CWdDxaatr+EqWvnJBOKzGzpuBLCe+DkbUQRTzvyMW2R7oczMObnle7ZvEhhtxEVoSRnB+58o+R 4Qo= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:12 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 05/17] btrfs: zoned: consider zone as full when no more SB can be written Date: Thu, 19 Aug 2021 21:19:12 +0900 Message-Id: <7b3768a49229cf41cd86c654d58863cbdaec783e.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Reviewed-by: Johannes Thumshirn --- 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 Thu Aug 19 12:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447035 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 DB8D5C432BE for ; Thu, 19 Aug 2021 12:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE91B6113E for ; Thu, 19 Aug 2021 12:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238916AbhHSM1v (ORCPT ); Thu, 19 Aug 2021 08:27:51 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238878AbhHSM1u (ORCPT ); Thu, 19 Aug 2021 08:27:50 -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=1629376033; x=1660912033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r50VGNZnDSTv3Op3HS5vNfZct0dafhEDRNdXuDHct28=; b=Az6ysMzd2NCC/j9fTUldrdEWmmuoIDFBOmg2Bjq0g213dO6oyu+UNJBE aZOaplVjSc7hYoBkO0EJjooUOfyVjXN1/GiO9w2+6ZgGxoV1jJk/rchqy VymupPV0X6NPWggyNFOOVh11Z5raPpLIxNvLX9OFkvxKUBEsDgFnyZyls TXkazC/TX3Mnfb2vzmOnO0kvTByMDLr+fVASeKbVK/eUqY7lQnBCY1k9O /gXxU8ECgBFPmDEwTP5OGEpQUYSGkaijpmmAhmeW3f2rlLeIoq3X868cj dxQA2zczZc/6+58D9yaDWqiz+G2bL1Qq0hp7UqyCDYJgmMffP61RXZMJ8 g==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773559" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:13 +0800 IronPort-SDR: vpMy3wEt04JgyLMwNe6xPedJRcp8gK5uxTkv8GReBnwsnelAC0nA7OmHsWoaMnICojAsZz6Lwi mjxRv+Od9oANdmN9xnfZZ1ClxK1l7ppu/V6AzR3fOQBMJTUfT8mqLvJxRFKGYc78hmAp7j+jzk Xue5Zl5G+WRH3RQnX86hQ4oxfPj6+DJUYo+vrAo9nx+xG7eeV/Df1mi8C2H2rCnGBTZrctaI90 EHmghgMT78lA8GG9ieNASrAlNeR6wuS9uvANCcE/nbTxb2Yu1ki3wWW9hsIgXOCJ/LgBMYotec xNLs9zOCrWNfQMSUI8iDc010 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:22 -0700 IronPort-SDR: FA519rt2vDcK+0MjzzDHZfkIyfgKVjKO43U6yuNi/MpIctSvyx0rznFa/820/0lmKUeRsiVZfD hKIpMuvaaJXaAGXmAgkLPDId07GxC6+3cupOsst13sXpCx4ibXR2mc/34cQ3bNGJtddF/wsFDU ntLPHCg5itTSxtxCh0Xda1N1F+9CSMZ7kDg97zMeU+o8nFOuJPibXLPrD34+lri+mxN99t9l7j 4eEltewqwtEX9k+qN2dj5SHnovGXIp/ACzYpJmc/rROip68GZgsG6yw3QF4c9wWKQhJ0RO+iL1 52k= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:13 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 06/17] btrfs: zoned: locate superblock position using zone capacity Date: Thu, 19 Aug 2021 21:19:13 +0900 Message-Id: <98720a3c02feebaaa8810ad3dbfde1717bd1acfa.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Reviewed-by: Johannes Thumshirn --- 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 Thu Aug 19 12:19:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447037 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 33487C4338F for ; Thu, 19 Aug 2021 12:27:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A1A16113B for ; Thu, 19 Aug 2021 12:27:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239049AbhHSM1w (ORCPT ); Thu, 19 Aug 2021 08:27:52 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238924AbhHSM1v (ORCPT ); Thu, 19 Aug 2021 08:27:51 -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=1629376034; x=1660912034; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b/Os05JdqmaTF1eNNDNXLOUs4+2MAGe0vT6RQUjKbFw=; b=XI9OXidrNTASZisskYynmXVvqY4x9M/K+FU757eUM0xhnzDoZDFfasQb zLwonv0mZ9RpEoGFIygRAemnPMHv4NzZqOT1v1eQA5gqKXVXXbAKiOH+P nPsWz699R2IjT2E4/J6n/6fcWoELzcnmog38th8kFAPs9GagcveCjeh6y 8U8r4vvlwWVF7lKjyK1WCP9V5UQt1id4ENVSeI0fI5YBfM6J4+W8Qo81l gJSzP3luPsx0cG8VXn0zhdvdjSFc1oASQeItE1TrfsgFMH3MJx9OEiGhu hlTn1cxIr0rb7HbXud2XCLV30PN10IKSvl3YjZgKUkyUXK/xSYo3rh+sb Q==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773567" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:14 +0800 IronPort-SDR: 08rrP1O5SJLE/Lp2UzJQb744E1vRAAxtFrUuXGWSRxv+FwuJSs606MPpXSfv+G9HXPgCPENCx3 kyGXAyHnd9w8VYBkO6rJ7ZZ8xNN02F7e13bLMf51wzUEq0y8gilGHtsitD8ZMR2NWjtbuqv6kG KsSEy0xC3jjVdhTyeZGrjs92J0y3Mcnde+siukVnNc264XDWku6XncF+uTujn65ZMpVvvnafCm dB1ytO7ao/p4MmJrICUOHqLr23ZQkUdZIi5i3mxqlKHeW63RJ/Q4fbjEPL1ozzdQd9uKVSfoPw gL/JxUazvX6Tubae7WJro0mM Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:23 -0700 IronPort-SDR: uVq1BfF0Z78zBBP4cltsmZ6qoHod1XNoGm8d0/cuO2PMW3xR8PdgogSW5u1YDkgurR3HWh1DE+ N/ulTYC30axvN8ujJLS3Bf2VrSWTJAtpRBt/kGoj0lNusn42WtItJi3vazzTEYweMkbnWvjxKa LLfWze+35tEiPolaJ2ehy4qE56tkTDPjEUFNEy6tRmC2MML/gdXToFVACDZhQhKd4t/lNa/X9Y sEAycSzuP1alP2SF1tq11bAD3s17JgtzoJE+Qj1LIPmE1C39gHYTmFG08mtqa8Qx/+WGfoQZZl Z+Q= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:14 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 07/17] btrfs: zoned: finish superblock zone once no space left for new SB Date: Thu, 19 Aug 2021 21:19:14 +0900 Message-Id: <3c81ee7f5399ad41607640d7bcfb93e63288d49b.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Thu Aug 19 12:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447039 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 E8039C432BE for ; Thu, 19 Aug 2021 12:27:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D279C610FF for ; Thu, 19 Aug 2021 12:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239148AbhHSM1z (ORCPT ); Thu, 19 Aug 2021 08:27:55 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238924AbhHSM1x (ORCPT ); Thu, 19 Aug 2021 08:27:53 -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=1629376035; x=1660912035; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ulsfs8LDxywPEITTX6ZnawwnG6LId1HpcIYr6yMfUA4=; b=eVZxlhwJFMzG5IxzaHiw0RSUn9/KykVw6BYCAxrEKjzxCCX4gVzpMfrW qRH58YkxZY/AtzU3scwJjAHaSx5H52f2qy/8tzMQhBi1JLB4i97Kzcye6 HoRzuYQG8pZb2oxta8EfpkZa+D5hdzyejGkAGzIiVoyQ43cWtE4UHUHgs 9GtpxLYv+YpTiELDoKoF45Nromi/jAaL4lxbwwMcaY7ZOk/NeM0N9msQU nJWkKoagteSoDgjlVRPAG6otRd50BSatR0YyfbPX4puOsTv9AGUVtT5Nb utnYwG8DyilZgYJSvx9WDRPT1/aIx03YwrBrnRUhoIg/IoWiAvo6+d7Cn g==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773575" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:15 +0800 IronPort-SDR: Rif52GCP/jgq+46KMsEX+kXepb265SkHppZi68XNw9nGLKhIHMjBGIRfTRwhKHPRjwRQSxuMwO xARaamcQTj/t467t1RNvjuhxpuOgpq4uFrM1DEEvLO2ipVq3w7yPNaRvHFDTCg789218VIYw8p 0LTHT2Jkj0OqdRbkU6oW0A3CsMSAfrIKQLp9cq/QbpMn6eYvEWmg7Sxh3XfcKPJqFubrBWuBLC tbSFcScWuLzX1EuSVXGWLc2lIgl9w2P1WNQvQnXF8eRr9zTMloiYsEbSXnoEfo6y3crhi8SHfN TbaxdMlK6aNNQXhDbjZX2IHx Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:24 -0700 IronPort-SDR: pH2pk/40v9OU7ig181PysbB61qN7buo6cWtpQe+/2GEeSaibhP3cfxAGa/UCA/qLvvdFaYFJua IhRl/HRyRrkINQyqXEnFcpksQpBiZID7qSbZxr1yFn2ZUhTgHodywDK71UZ4vdP61NDsEThnCT chWOKVjQHNlPMSuI3iJorAY3G+sOeljd7TzaVW2vqkpKKOFUEWvqa+NCmjmOpx3JX26Hkm8tYG 51R8/236v61jKQdE8axiIqljqzFOzz1+eJjPI0q8cRGibiLVXbtnE//2D1gDhFestaAe3n/nFD s94= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:16 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 08/17] btrfs: zoned: load active zone information from devices Date: Thu, 19 Aug 2021 21:19:15 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 Thu Aug 19 12:19:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447041 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 2FFBAC4320E for ; Thu, 19 Aug 2021 12:27:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1566761130 for ; Thu, 19 Aug 2021 12:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239248AbhHSM15 (ORCPT ); Thu, 19 Aug 2021 08:27:57 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239094AbhHSM1y (ORCPT ); Thu, 19 Aug 2021 08:27:54 -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=1629376037; x=1660912037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/qY3pxt70FVJ7umAg9Qkna1bXSBTa0ZNsLpgDFaX1E8=; b=Azshr065uroF8v9OPt9UJXhk70g/2F6qUUioTDrFlFEADFpHA8uiU8++ 8K9F8QM4AjxFKQafw64POE13X9DOvlp9kgtQsqov3N/VrPI8YfOCaAQ2d Ak/X1nO+akpjiXrjPH81Zwnde2ycTulQM2eZ19v9dI0L3iDEozwgVHSa1 hZg10xdkajTiBwU/J43CjlRyfV7KYePKjT8Y2a6kl5fqO77c2KfUu3YYB wlufxcsoxZMvKH+5+mrRSGOtCvoCQPvIfmLeFDVU/BI6MLwodVDhdq1PT QLrkDoRCEGPEXahqjxlCSIc/2CPl5AFAUGQB70blZsgvYEhy6ieCd6v+y A==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773581" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:17 +0800 IronPort-SDR: kbPiMg6JL1Z8Z2cuhiky1UZqbOFiySzxbCJNp0RxKkYcuxh4g+r2A+ECrYtYFU4e38YI3Lag0N kEGN+8YidsKnphyaPdAMeWnlHReIKCCvQwfoPuwtRA4qYXZwl7guViKNB6Otz6LcSJiMYeK+fG 8stFGtPbpJyVrKLY8ZZgDzP8CnpAmp3mKN3ec7gzhWJx8Z6FZbZ5jU0JOo25jBYf45/UcUam46 qcGHw672KU1Usglou+QBWUrXvgQPuLsXtBqimci/Sqapz6G1nKWnI7yMki21UicxdCQSwLKpJL 9rJ5Zr4M9lOlDdBUpzr1RMMf Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:25 -0700 IronPort-SDR: kptG92m9+uY8xQ7KmFdn5jqt0DcDmy7k5mblZ/P4jR+qWZ7gorLl7+fNnx2fElZv6O9CElFmWE +JQ/5wflxUy5zSQ/RpzqIThujEeIQUGamRIm2cqOGMXZrPua5YnqS+JbhUGSBxQ9wPYh4PS9h9 50Ls6fBxVENYodyHF4u8NIeG1VWSKRGyxN5nwxTeYqZKfC/v/NRO6Qdt7stxHJjkbTScyhq6AR GhSHcDoNLyV632Zjl4gNFeBFBV3tAoEltcFlvGAp98pSCyrnfxR/scAyfCJa/DatUUzBqaI50/ Y3k= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:17 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 09/17] btrfs: zoned: introduce physical_map to btrfs_block_group Date: Thu, 19 Aug 2021 21:19:16 +0900 Message-Id: <2b5e458e2e77a4cc29d081d859d7002d07fc4b9e.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Thu Aug 19 12:19:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447043 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 2F76FC43216 for ; Thu, 19 Aug 2021 12:27:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1237F61158 for ; Thu, 19 Aug 2021 12:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238924AbhHSM16 (ORCPT ); Thu, 19 Aug 2021 08:27:58 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239119AbhHSM1z (ORCPT ); Thu, 19 Aug 2021 08:27:55 -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=1629376038; x=1660912038; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W8Zx90FsXTJTDOlv9VhEwcSL4QpU+W8RsjzxPBoEm10=; b=lS40pTgbnbtJxl6poOyqiDx3UspZQVmajiD874QhC3j2X29Ma0w5g+8j UcIu2zNiX6SCnlCxosrMPrwgQfBNJT61mjAjgMJpF6OxAddB05RGWYgCn gPQ3NzYDia6JscMAUfMYlmIcJOY3g9raHVVy8pV2rrz2883DCQzlEbbAt Zsu3KqrOjWl0WIC+MiS/n5zGFOEITgok4n7C0NhruLvEdL8h/NWwWjmr2 vCVmqQ+E6b0lhw4x5/M4PXtNpv5O2x+uCXBfGfy+Ec1hAkMEwcqOOqW9v 4bH1GihiQhyeqIC/PBm8xQtz2Z+coChFbotGd1y+67XzLEnzwi/IEaVrV w==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773588" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:18 +0800 IronPort-SDR: kXLTx4tYiuIjRk6HZqwT4tDpghwAKu6nEqPxJxrL1s03N7eHGFmu0c+CY6kNhVCg0r3cQIs6VH GaVSnc50yoagXYEeQ6Bnw2RwNin/EfvB3jc8wjJQB3Ec1P5r+eKfPBzZK7Lpj66Ev+ScO0QtM6 z5r9y7UAWgfaUNHHu2MH3cmOTM+jKqUX0nTVBubzeUHYHUo7tIqyPGYtF9CqdFCCpkp201ECnT RmIEk7SzOLzjU8le6c5WiWSxP/r0jCsbmE0ApkgHotS8F7ZlNfe8zcXF/NP6CYD3qxstSpztKO IX8Dk6qRsLxWW8tQZWAX8voW Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:26 -0700 IronPort-SDR: ruTnPWwsJ183Jjkz5YOaw46D1Rg8gSYkTS1U45mo9983dUI8elRJYGkfJX3vcALcVnDYFT+Q8b qcmlMBX0ZTG3NEax83yxQBGbGviWtgGRSXKsjVyT7miWug0vmkQ3ITL+9fS/dj2Y7MM3DIzqr6 k5TYEGnjqyzeqx38UyEgY8fakVa1fdChLKZj3PjI5Pp71pcyRk+ZYX95SplxtBhAvFPbbSQuQI y5T1j8Z8/Ee+AVH9p1NyfITzemAf1824ucweMXdrA62P7moq4grIVOTU4fPNXLB+rb6MdXvKmy mNA= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:18 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 10/17] btrfs: zoned: implement active zone tracking Date: Thu, 19 Aug 2021 21:19:17 +0900 Message-Id: <1fcaf6061182e0ad2242849ad8f52bbbb823359d.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 | 196 ++++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 12 +++ 7 files changed, 229 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 f07c82fafa04..9b6416ee081a 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..f28685898df4 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,163 @@ 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); + + /* + * Bail out if someone already deactivated the block group, or + * allocated space is left in the block group. + */ + if (!block_group->zone_is_active) { + spin_unlock(&block_group->lock); + btrfs_dec_block_group_ro(block_group); + return 0; + } + + if (block_group->reserved) { + spin_unlock(&block_group->lock); + btrfs_dec_block_group_ro(block_group); + return -EAGAIN; + } + + 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 Thu Aug 19 12:19:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447047 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 454B1C432BE for ; Thu, 19 Aug 2021 12:27:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FE94610FF for ; Thu, 19 Aug 2021 12:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239342AbhHSM2A (ORCPT ); Thu, 19 Aug 2021 08:28:00 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46871 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239164AbhHSM14 (ORCPT ); Thu, 19 Aug 2021 08:27:56 -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=1629376039; x=1660912039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=31udtkov2l5e2UqXWR9Bp322TvmelSlrcJ16q2ILMR4=; b=mQ0vroIg1/MN5r42873qlmroF8J2KE1nLutYOoSBUD92iwJXtFypRifY 2tiwZXeXpXPUiMZpZ74Ir3qPpiI/QYzp+UJ3dBNwAcTOK/rkI9O+y8amr S0/c6h/xvu1TDQZ11jm6ERiQM2zR9bvxdINRZvnuFh24OhyIE5eQ9d3WY VKGsZ9H0m7EiOFCkaRREgveVWwtuesNiCxqVIW7l5ZkVAilScihUEmueB M6AJ+/1zvm4llKLOqmiBpEhkdbCrFwKCH80KxoVRva2iqWL3nvgtZHQKI 0kf1jgZtNkktYyLVItyt8eFkdkB5cpVmtOC+8/KRKxHNjQQinI1U3HWL/ g==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773597" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:19 +0800 IronPort-SDR: DMvOVFLLkQRSREDKNr8S2hgESi2PYbppjqDgZhEfIVXDo7aV2F/QrqVdc3qXLANKL2Cs2M8E0V jQt3JnVpjHKLp8oCpY84h58lxwXHbnS1tHx+kTmBs4KqjA6NnJYvBXDN2xwld/Irh2//l8KvLd 6gt7tz+8fZT8H8ZSS4jT8mcD4dOHizgsJf86/VDbumCkrVVjPtZcL3f12ScXGeFF0UcuNgOU4c 0Mgiwsv0AtKOiS5X8z3ShAFporOM7wlWmJgDSki1+LgoRDJXhG7OuBJwtm1FN60Q8gqK2SrbBV XAoFX73Ee5Em3b8ragbgp6e9 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:27 -0700 IronPort-SDR: hwErjTpQT4CDp5j2ZTPq/O401rCevGiymTS5gaI7w2lTWGiQwxT2/HOP3AbLk/+7M/glMATkxb KFIM6etEGm2Vm/B0gZ7RP2tYmWtMcZbjQK3EsH7oXQIzJeFrgn8tgbgAZe9N07ni9zZTCgRrWk PmAsPdJB9DPDXqx/KvgAHTk60/aK3KX4fE8j85oWAbf+lOnuXN5gJtZIIWxwyt6s1dbeMA5KGP s1x0Btqqi10LNJpBB/T1awFTAYZok0msoxYFOHjeXbwxs0iBOX5uyDlBN2ab+9N6I+e7YPT+Oo CD0= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:19 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 11/17] btrfs: zoned: load active zone info for block group Date: Thu, 19 Aug 2021 21:19:18 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 f28685898df4..441cdd4c507f 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 Thu Aug 19 12:19:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447045 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 5557CC4320A for ; Thu, 19 Aug 2021 12:27:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4321861152 for ; Thu, 19 Aug 2021 12:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239221AbhHSM2B (ORCPT ); Thu, 19 Aug 2021 08:28:01 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46901 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239212AbhHSM15 (ORCPT ); Thu, 19 Aug 2021 08:27:57 -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=1629376041; x=1660912041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=83QfKnRnxoXJ8jTUCFN0cJc2MTrBHcWtC29a2k/ApN0=; b=qb0na0ZPxJ8AnXMd1loutXnItHDFNEYI4aNAD3JX2gftzUKFCuqPAvzK 8nggwsHl5ydE2jS2n+CkO26fCX6IRKdXdCOIReK+fdceYi1RYhsmhaSKY 2HnHdVY86VidfQjYa1dZMnCRzvYDAQ7RyUxJOIR11z1ZCHAiijav5Ziu5 qxXJ10TQjCWZj6vyfRC+uUMesfKWhTKn+FlcSQjfLNFZAZrzGmTtfaMrE EKI0CScZ6IWWCB6A40gbOHGIAZyJ2PfC1nus7RHyclBUs1dFFS6dqU1uY 8PXnsZbNbARrP5Gy3kfsWapNvgLxKVAeYUG88TUHDPOu9Ntocku/O3knc A==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773603" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:20 +0800 IronPort-SDR: dfGaTe7+4Zl0vm58PA2qHHmLcq71SNlbzwPvL0kqbaYJbUmawofcHT8NDH7Npng3l2Y1rfw7R0 iVgAOJUot5WkKdVqN8vK5Ku23xqASQ3POthGs/AxZWZ5i3WZekmYKeULUtKljR215W3leVCjBl KG+8LfRAfZsrX9Wc5FDsod9CPry76Xr/QLVttsws0gI9SsPHPQlPf7OpXX3eSJI7898Drb8HAd yIarglg4mcY/zdYu6ZTZottRbPYu0kVdur14FCG+r67abrSSJ57LEru+gLKnt7GZa6DkGA65Ji Kl7hnsUp+Rwc8PwjmmvWq27F Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:28 -0700 IronPort-SDR: h6JeO2w25Xc0lpj89UGXOxdfIvm3O06bYyMj0SahfbheJt3we24NKf6NWeU0qN24BM/aHH0cX2 QO3NDFPTNbII7j4oDTw8oqgI3ZiEzh8+lCjwYLcdhy0sG1ZENg+zdVcHNHVJj5o/l/vrIgsE1t uqW9LSaaBduTlH0XUEixQkYVjr43CHVCxcRg4R+jG9AIISJn9IDra9Tl85gykvTyQlz29pJbr7 vvE8R98GEr/uo7AGNqm1KhHuJ3OG2AG4uoLoFoSy2vCwf06GalkxsiZFb9AyrxIu9OVxv/xeW8 2K4= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:20 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 12/17] btrfs: zoned: activate block group on allocation Date: Thu, 19 Aug 2021 21:19:19 +0900 Message-Id: <246d2f2a36c906e1aa35555c5e63cd1945b852c7.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Thu Aug 19 12:19:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447049 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 0EF10C4338F for ; Thu, 19 Aug 2021 12:27:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC4BD6113E for ; Thu, 19 Aug 2021 12:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239449AbhHSM2D (ORCPT ); Thu, 19 Aug 2021 08:28:03 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46903 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239271AbhHSM16 (ORCPT ); Thu, 19 Aug 2021 08:27:58 -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=1629376041; x=1660912041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2JTgZ+t51DrzBD/054qtVi6rG7eyH6kwOLyaq/fxBxc=; b=B8FwRkEA0iAChkEIyrmfU8V0s5vUQLYRD+4MouOG1q5cbHSp4UIGLNxT 2w2dw5mKkoNyzf03gL1u/oq3T8Ilxa64ih59aYL2Mkf00WZAKmTd6DmIA kBc9aR8WrtGE4Q8usB5C9wYPPR5Wwm8nUQAMoX3G9JelgQ/y6EsgzEwZd 5j1sHjLS/tjfdxRjw+SBrF4hfqwOgbXyiRPXPyPchaP6bt5GdrZuikMvM bjNvi5ZzA4B7C3wW/774m+a3ZUo63AuRGzzD3Ycotm3WkowqglwfWVghQ wKhxe6C/Z5L1Y8CdC53dR8ZaAhXArJxHrQ6XMGk/Qjdb7uwSqT2bEWNpI A==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773616" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:21 +0800 IronPort-SDR: LrigAq+ClKFY2T3PgonuuhtXGm0/B/FiF7H4Thps+oBwdz2AhC5Ezw/4y5svvrv5ijOMo1kTP8 /gCuZK9vNtIJ/KCRDEWeFoBnf79dxjWbGFAO46ULz+M9RbN4RBTRo+M8AQ9kuQ1LYZo5bkY1Bs rGjvTJwqNZIDg9k8E68M+BcYch2QftcyoFuIBsudF6iHYFj4kiF1rjbsKtpVenyGM0omjrhNpo +Em88bqJ/CP/EYmuUuuv//nRKTKfhODwfgWChNABcueSHECUEM5f1aklIQXkTe2pfm+V7wIIGv jSz+9CzC1F36lBo6/8CuHj6D Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:29 -0700 IronPort-SDR: pMah6UjPyJ3klcn88YH9VQO7rDniFe1wPHbPm7UqM0aHpXPpm3h54wsh0fr0hpy3pX/D0AlNG2 hGnqJatSEHPro1fRrevBdtDBzmfU802o4uieiP7agJ2acxVO4e4ArwcMUbPu1jcWqiX+kLZnGB DATBpP5hN7i1qQwSapYHMWDuRr3GVk/VmmkJpz7lOggk0k18P8BTsJB3A7yMOKVmlPr9WtS7Ds eSffZRh+PtqRWalixkMQFwJbGiwGlErM1nfGSf3AVlAIeujyfZ67FgrmUfW3/uQmWBd1EdcyVF pcQ= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:21 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 13/17] btrfs: zoned: activate new block group Date: Thu, 19 Aug 2021 21:19:20 +0900 Message-Id: <4c886c670310905a4ac104b735f5a4d4a216ed78.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 Thu Aug 19 12:19:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447051 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 82B03C43216 for ; Thu, 19 Aug 2021 12:27:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B67061130 for ; Thu, 19 Aug 2021 12:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239457AbhHSM2D (ORCPT ); Thu, 19 Aug 2021 08:28:03 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46903 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239300AbhHSM17 (ORCPT ); Thu, 19 Aug 2021 08:27:59 -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=1629376042; x=1660912042; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r+yBiCHH0RJUPqMJSVdG/DUzX9BJvRhPFwnlxQHbAQY=; b=MIGPCGG7LtVm/SAv1VrR+0rtuN51q0/s18Cdr4MoSiXMZdGdQnl9FTB6 nneXK2pCPmF3m6sy1oCjCn9JFfZRI85HwKyLhuZ7P6vgVV9NFtygq07SY BIDLhAXIE9i6sFMyJTUgLWx0RcPJcwG6Nj1XfnUQ7v6SGzhLWphLXnXgw aa56vifozQZPjAcGagpUNCWU1o0Lg1+7oxo8eaupF9yIDIyJAkdXIt7fJ 0K3XAkRstABP7BblS3nyrftDGqSZCBCzwrDGzUko8ueq5puYO1aYarRWS PRWgyU+1VXb70ni+WI18kEhD17dq05XMLuJtwDdjnmAaJREuC6Oo74+NA w==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773623" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:22 +0800 IronPort-SDR: SNRtshvUMoZvqU3uaM9YfiipGvygucFuOP51vkutBcs3ps45MzOOU8wMjYIM9BLwvi5PdTrE+m Q9GTqAQgH1E6lVO6xQrmiYP783Dott1cSzhlSOL4H6hI6+fNNlE3v7WAGnMZfLBU6ZnGVNB+lI xlICqBxqhWkmU9JaFB/xf+NAdigQ9fbYWJLA1szuGHdU32Uens3AvI/vbkQclNZLIcUHGTvbSt GRpfzCr9bo0DlYbRixpTEwMFw5yX+Zx1aoKPgUS47D3aqpc7nFZZcxpO7y74BrZMbPIZpcYpCb IBT+bkhLS3kfe9uoGkxribWU Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:30 -0700 IronPort-SDR: +t4sdP/+OmE42HyZGppFBmwKQ4GGykRDZktNtc57s9wTd4+wofP9u8GtwnHJJontpwOBrezfEj QZr1+RW06zqkjzOo/AMDquGXbjFVTD94b7hAW8U1S35Pg8ZsPIHI9C3gygSqVYNqmgZ8+vn2+x H+nYLoXgvJiNxt3g/gd3x7MYNCmF8A6ayTCoNjqzyZeIfU/RqKO2+7FrUcpI+nzwNL6GZeP4Fi nMgzlaeqL7xH/I+4XTD7LaSZ03tn2pp0R64E9AcvzWlu2IF+b6cZ4VcFpempsfrp6mELmSn2p6 rcs= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:22 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 14/17] btrfs: move ffe_ctl one level up Date: Thu, 19 Aug 2021 21:19:21 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 Thu Aug 19 12:19:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447053 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 2FF8EC43214 for ; Thu, 19 Aug 2021 12:27:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C4DD610FF for ; Thu, 19 Aug 2021 12:27:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239463AbhHSM2F (ORCPT ); Thu, 19 Aug 2021 08:28:05 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46903 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239425AbhHSM2A (ORCPT ); Thu, 19 Aug 2021 08:28:00 -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=1629376044; x=1660912044; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cj6mvTNy0HkoJyN6EDUTxpktbYOs0GV/xjub79eZZfM=; b=NW2x/TVEf24zVpk0Uco9JGIXI0VCJkgj5WJNFcZEdzRS7a3UYO5cb+Z0 AO5GLKzIef7yqgHt/uHS88tZOiazuBgPuCFEtIP/sHr5uyb5mNoq+LwQE nojGqKgiNcld9MOZ8cKB8PvgBt+iXwpHJHK2/L9+J5PdWNm31ddyffF85 tIMrzVdPbARZ1x83o3YQfj2yGdJAx8L9OPRCje6w/+kjUkGMxgdf2Zwkm PDEc54I++t8NRS+rMoCnWCRuMLSIBDIYA/F+Vnf9MfGYUZnqD89svU5RN 12PAxnb/m9d6v9ynzMhEUORcnuBod7J0jKwfPmpsb0K33IO5FKo2ubW4f Q==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773629" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:23 +0800 IronPort-SDR: IzbT9km28V4WjstqPNhsiwv4X/fWqlwy2PFaaxBFvRRaG4E+miIWwlkf3Wmk0QVPZdadr2Sr6N lVVP7FyHROgudxsMcE3Qx/LDIokwdZpJ/fXWChe62stSj4Ytn15iKjDy1tOixDZtuyk3WHTwu7 JpfEC0JB/ZSg5WVnXZ87rm+ItTW9Ef4dRbfnFwnmoQjIh/pHDUTFwlOY8ovyMMGjjNCuMGuYIU EGC/DKkwZUJ9vOEa6MJgnyDN2j02JZwr5aPpPxJ8aK+zwF9ACKmEY6C9CWSeon8M6vGwr8TRqn MBh7nW1eBo9gPk2KMWcsWcQP Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:31 -0700 IronPort-SDR: laQiiwnxQajqwjQW1akqUmP9VcknluBy1bssuYaUCKAnPnPCluya4IcMD3GVtdr4uYSmSB7SRA q8X3Iqa44fLQ35Y7281X5nplWw99MrdnY989Mr4sP9yFifhGcTOVXO6brvswtJGWzkvlGnq/OO Gw5A5MD2YcpQX2OA9a7k4GYatZ7ecqpcCqZYCID0lO166T2cmhrILZQzXBJkhXW9pkHqFXGNWw 4YrAoY+lCz2A3vMHrQT+60Ql61E5Os2tog98ij41OuQIT5crvLpNZsDwwxz/2eAhXgkR/e+yLX k/A= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:23 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 15/17] btrfs: zoned: avoid chunk allocation if active block group has enough space Date: Thu, 19 Aug 2021 21:19:22 +0900 Message-Id: X-Mailer: git-send-email 2.33.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 441cdd4c507f..74f98d38abcc 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1878,3 +1878,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 Thu Aug 19 12:19:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447055 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 C1ACDC4320A for ; Thu, 19 Aug 2021 12:27:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF1666113E for ; Thu, 19 Aug 2021 12:27:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239474AbhHSM2F (ORCPT ); Thu, 19 Aug 2021 08:28:05 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46903 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239438AbhHSM2B (ORCPT ); Thu, 19 Aug 2021 08:28:01 -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=1629376045; x=1660912045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sv9X4xoExeqETaSflvJF1lYEUrvqKjq1BuN8b6U+ZIM=; b=N4gVHIg8wZXiqZUxVbKBwcAbfcTPXKNJwGC7WN6ovWq6kUYuqRDhTjv1 UtanOs6ft56UcXPr+zB0zva2w3VzCXZaeB4k3LB+ffR6qXUGKzbmTmG5n CqFHx7/E1wtujaTAtSz5IUWreHAgQx0fgBY3ErPgGvWSpgGf3u+6imEYB +G6ygXUyJO5L6g8s2kHGlsfMEK9ZFqX/8Jn99gZAbalc5HvV9Ahqlg6jU i0q7K1CjgASccPbitv4DQh0soJcmxV1G63wRJ0+aOe76mJgOZ0/sCsNPN L1hRQggkPq6WI1KgTVHjLGNaa82GNFHzIT2JZZiSoatq8E68imMWSw/r0 Q==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773633" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:25 +0800 IronPort-SDR: zx1ZrWHuIQ5yoNpvs+IVN0JtnkukrbRSfSZFamTNo2UvfdsgMBj5707w+PZ6cVss9U5i+S6nlE h1d6fzrQybBLxPENfuvk8ALZ1E5BXPdVdPDqOXSBOrSI92X+oioPM7/XIx4o1ou5kN9DOdoIDu 107Ud2zDrdCRe71K4mmRBMNNDTB7ZFrkpsOIaHZWyaavwUZQzTR4m1ohIEMDpU9N/Flir09Ceh jy7I7CbW90toU2twm/wEagSAYLcmmALWd2S4t4RmqA05BnAzf9HJQPWjub2ICx1L3y5+lW0Y/Z 4gamb81QO/9QKG3Tcq4hhO1B Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:33 -0700 IronPort-SDR: q8KJ36jmwUBfUirJN7D+nSgPSWO5qPXhXdVfkNK/MFwdkIzZJ54ARCnF3DPWLXYluhCEuaSKYf BlHzFBnqP9F1FhPiCLtvkGPzLqKDisr2oAD+CrOR4jhNEghBz76Pl6HzS1jlSQogC78bnaf3qv lNpZfnU2/vuZPPNGtYbOIXSNQ9IhFYkM+cRmmuVzHU2qPI2tSDYlJRNFeSyT2AfFKrOrWk6I4d ANmXW7VRpEDbDUvbL3F9xPMMiv/kQ/HAiwQw5HSeXxcSegv2pYPHr1Rmgr/qWUZ9EqroOiOsnM 1g4= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:24 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 16/17] btrfs: zoned: finish fully written block group Date: Thu, 19 Aug 2021 21:19:23 +0900 Message-Id: <8ed0671f9a06acdc14dff407ed8009e835a478c4.1629349224.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.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 --- fs/btrfs/extent_io.c | 11 +++++++++- fs/btrfs/extent_io.h | 1 + fs/btrfs/inode.c | 6 +++++- fs/btrfs/zoned.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 5 +++++ 5 files changed, 72 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 2aa9646bce56..a72992c4b88f 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, + ordered_extent->disk_num_bytes); + } btrfs_free_io_failure_record(inode, start, end); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 74f98d38abcc..90dd49def00e 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1910,3 +1910,54 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, return ret; } + +void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, + u64 length) +{ + struct btrfs_block_group *block_group; + struct map_lookup *map; + struct btrfs_device *device; + u64 physical; + + if (!btrfs_is_zoned(fs_info)) + return; + + block_group = btrfs_lookup_block_group(fs_info, logical); + ASSERT(block_group); + + if (logical + length < block_group->start + block_group->zone_capacity) + goto out; + + spin_lock(&block_group->lock); + + if (!block_group->zone_is_active) { + spin_unlock(&block_group->lock); + goto out; + } + + block_group->zone_is_active = 0; + /* We should have consumed all the free space */ + ASSERT(block_group->alloc_offset == block_group->zone_capacity); + ASSERT(block_group->free_space_ctl->free_space == 0); + btrfs_clear_treelog_bg(block_group); + spin_unlock(&block_group->lock); + + map = block_group->physical_map; + device = map->stripes[0].dev; + physical = map->stripes[0].physical; + + if (!device->zone_info->max_active_zones) + goto out; + + btrfs_dev_clear_active_zone(device, physical); + + spin_lock(&fs_info->zone_active_bgs_lock); + ASSERT(!list_empty(&block_group->active_bg_list)); + list_del_init(&block_group->active_bg_list); + spin_unlock(&fs_info->zone_active_bgs_lock); + + btrfs_put_block_group(block_group); + +out: + btrfs_put_block_group(block_group); +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index ade6588c4ccd..9c512402d7f4 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); +void 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,9 @@ static inline bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, return true; } +static inline void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, + u64 logical, u64 length) { } + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Thu Aug 19 12:19:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12447057 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 4376CC432BE for ; Thu, 19 Aug 2021 12:27:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29AD061130 for ; Thu, 19 Aug 2021 12:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239493AbhHSM2G (ORCPT ); Thu, 19 Aug 2021 08:28:06 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46907 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239212AbhHSM2C (ORCPT ); Thu, 19 Aug 2021 08:28:02 -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=1629376046; x=1660912046; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R2Nna96c4js3hoGzXcDP7F0m3ZA/YEJruB6k/OwVLbI=; b=OwqkngVqU1KSn3edCdsTH1mnrBsR5OFr5LieAELGPFJO/eU/8D6JyN+d Uk6N6tdunOMc+5sRB1fuUgtNQJE7rqXsT1d1gDw7r+8CB77oD15tqCBkA e3ABR5mtJmoD1e8twzL6+6fRJ1VPTRyiMCPSYgRlrS+44OTiOP2LzLe7W v47s7lpezy0hULqVVobkFN4XzX/63rotVMRjNCamGVTS+rQ2IInI1+8XT 9/rOjhkWiRiYwiaTKtgvId2TcH37/GTkxMwmPdYDYimcI/wbAN9e9qMDa R4UfoJRDJCtY0WXztBu5KGfZ6vC5f8qGOQXThvrnw9EAt2+qA8fg8p1Uw Q==; X-IronPort-AV: E=Sophos;i="5.84,334,1620662400"; d="scan'208";a="177773636" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Aug 2021 20:27:26 +0800 IronPort-SDR: WWn35kOZk2ugrGRrucUjfcdLuf8iEpnqSrx3y9i44oiLZjdJCwgMFuIoE8kd7H1Yfct9kht6Tk F6OSZi/Se5qeG2s1+CnAzHC9TSLYy/jhv/ldITodJTgUIUyxbSbJ8J+n/ZafrtuoJyB279PLy6 Uz4aS+7rLEPCXzpJ+9N/HCctyAbfBSKkqqvke3a8KriXA/tgpuAdOmG4qDzG+zCy01hhZ6hbKC Yzk22rpDs9lJecDE31RJfSSnFv5pZ6wfT7eyNYgcZQ+Guo5EHqqUc2nOm5lBHhnztCzEeBsa3U rqU6uSPELv4ZGRM1E7S6qrCH Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2021 05:04:34 -0700 IronPort-SDR: hokmOs3jT+2oxyqCiOi4tY2lO1zGvejeqHcQLDTCgPvP2k9M52PrHFa8Vz5aAkzNXa/102zM6u uQVz3fia9QLghr1I9KgQAmX4k9990O96A2wSqaJ4flkWVCPdnGE+S57vgA6OyT185eWaTbRUY6 A/+G+XbZ9okLbo4Y0xnsScDHlkrKG/RgDp4MWYl8pXoIMRIW1jRIrcviXPHU9el+fRi5pdAjWW Nnpnk4rY2QEAPxGu6dt3uH4hNRpE6LaxKHIRGbbli/KhSSqxj5YT3RfS5iI6pjEWWWbYwHtmGN GiU= WDCIronportException: Internal Received: from gkg9hr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.110]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Aug 2021 05:27:25 -0700 From: Naohiro Aota To: David Sterba , Josef Bacik Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 17/17] btrfs: zoned: finish relocating block group Date: Thu, 19 Aug 2021 21:19:24 +0900 Message-Id: X-Mailer: git-send-email 2.33.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;