From patchwork Wed Mar 16 14:09:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12782728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D499C433FE for ; Wed, 16 Mar 2022 14:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351602AbiCPOKl (ORCPT ); Wed, 16 Mar 2022 10:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352804AbiCPOKi (ORCPT ); Wed, 16 Mar 2022 10:10:38 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 268FA4D623 for ; Wed, 16 Mar 2022 07:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1647439764; x=1678975764; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+jZp1mel7Nc/JPEAlj08v7gIYU1Um1djZWu1JJgWLI8=; b=kLfJtMSpAJs+1gedp6UhVWR+VXHF+MqY5aPlX7nbbeTewAlFyr4yPjtV nrLMLxrftEnr4COR2+WiYzJyaFrueJqZ3zRAWkkeT7IsUwmHfh59REbO/ TWbtothsSDNgJVfSeZ5MKLofPH7E/MjBviqb96jN+XWkZWYuh6ymrorOe WEzzFKjB/riWu+f5uAfIuQ3bfI+bRGhlf2e5czhN5K0xH4HOmafyoUre6 Eub0wdtHGthNROPvT6KJbQu5wlM3euitk2ucNF/PrzuYsDaGGXGKttLrz uylDJ+hI4RtJUOPaf+P0wtMQAyOz9gk6okjK+5YciJS7HD9Iy+ndpR7CW A==; X-IronPort-AV: E=Sophos;i="5.90,186,1643644800"; d="scan'208";a="196448087" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2022 22:09:24 +0800 IronPort-SDR: j0jXG9Au0KcdfQUWt8j54ut27RLRJq10oEjYqVw+jng6OH9NtEafiSXN/YHYz2cZFoDuskZIZf 1MK3Rbv4avZwbDaXGx60xRDpJN3u/RL1VD3UU+scFko3osPj6yFkDkStkzoaMTpDJxpXPKKEoi iDqjohkXPIJZ/k1cRP+/DAqJzZXLUEpZ7qydbWBdDTYMOUQvTx4MzarUctkSiEG0FeVDJFf5MT E1ikAnnc+wIQdEHCpGXdJX2X/76x9w6FGYIypm5bLk2WU/Pp7Hw4j+ZybEo0zCKN/FDw9R2lMD Jx7OnOR327b1VkMx/+5iHve2 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 06:40:28 -0700 IronPort-SDR: rL807EC4zy4Jdtu1IvGZV3IjNJR3iDtofX93QiTjJapy42iMT+i0/iM2IX5CZ62HsqtuS++zdg e866HFtWYoqMOVWe/7cjQ7VigF/xsKUFY38klZafP6RJQGC0eC9Iy+kbT3AWVZMKjaeXn8YgJm RGSzMYMJq+ZYM6YjGilHbAOnKcJuU37c4re3DUyLaQK99iYMYcs4QRE11hFI1i0duRjL/sN6Cq MiFRI9LeKUi5kiwmaJ9dsXSnQT9KnJoRsd9YVeI17ihPwoyeJX3ZuoW4zuNERa6j2i7Ja4zXHE 5ZM= WDCIronportException: Internal Received: from d2bbl13.ad.shared (HELO naota-xeon.wdc.com) ([10.225.55.209]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Mar 2022 07:09:21 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, Naohiro Aota Subject: [PATCH 1/2] btrfs: return allocated block group from do_chunk_alloc() Date: Wed, 16 Mar 2022 23:09:11 +0900 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Return the allocated block group from do_chunk_alloc(). This is a preparation patch for the next patch. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 59f18a10fd5f..d4ac1c76f539 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -3433,7 +3433,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type) return btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE); } -static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags) +static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags) { struct btrfs_block_group *bg; int ret; @@ -3520,7 +3520,11 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags) out: btrfs_trans_release_chunk_metadata(trans); - return ret; + if (ret) + return ERR_PTR(ret); + + btrfs_get_block_group(bg); + return bg; } /* @@ -3635,6 +3639,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, { struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_space_info *space_info; + struct btrfs_block_group *ret_bg; bool wait_for_alloc = false; bool should_alloc = false; int ret = 0; @@ -3728,9 +3733,14 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, force_metadata_allocation(fs_info); } - ret = do_chunk_alloc(trans, flags); + ret_bg = do_chunk_alloc(trans, flags); trans->allocating_chunk = false; + if (IS_ERR(ret_bg)) + ret = PTR_ERR(ret_bg); + else + btrfs_put_block_group(ret_bg); + spin_lock(&space_info->lock); if (ret < 0) { if (ret == -ENOSPC) From patchwork Wed Mar 16 14:09:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12782729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A4EAC4332F for ; Wed, 16 Mar 2022 14:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354106AbiCPOKo (ORCPT ); Wed, 16 Mar 2022 10:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354903AbiCPOKj (ORCPT ); Wed, 16 Mar 2022 10:10:39 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F964ECDD for ; Wed, 16 Mar 2022 07:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1647439766; x=1678975766; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YGGA3WV+ACAzE/i4Wh0P3/Zt9F2O8ZlzJG8QRg4M+vI=; b=cNQ9dHjWM4DiJTuqacPVzJyf4mlgwoSW3qqurDgTZWII2dX+997GnZAe Qgv1yPoLWIlb5NlXmQfpIr0QlvjaMDnRzarEJ0ixb5tJBGIkXs5UsXEbN wYDJxrbFNj/C8UbAs5wTtVldZG8aL2z4Ub2xMMcvfqrfXHC90BzDfMycC mYkJbC0IXwKBNsjRcSG3LKoDZJnkzBTyY1CQt8ErpwFQ4sSsUYreOEdq4 CcBxIN5DH7DsddBEx5BVr7zzZ2Tk1Nwx0y9VCit1poded4b4V4Tu14VU4 tiqiqNQam6p0neda5NgLXnVUiWC10iQu8gvLj8A/eny2seju5or7SZ2/I g==; X-IronPort-AV: E=Sophos;i="5.90,186,1643644800"; d="scan'208";a="196448088" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2022 22:09:24 +0800 IronPort-SDR: GVvM7i21KL4PL8P1Vilr7y9dz6/GFucEcTBQ8tbUkRXTYNrzNqkVJbl+EFbqGtvYY2aJSfKUZN npXRrhmfJu1DZwqilOLH5yHz69S+evqf1E9U/3XIuRkqvj55NhdEyAq/5FVfqrf3MFG6baMZO2 tYrahDhGRJ/jKFFLyE97eFcfXTWdLMAY83GGtohpj0CZD41P45aJASse/i3rOtaDdHi2Fpamz2 AToL9mmLnM4D7vQ+xmCZj+oYXsRqxEMLTpM5VuFh5CTHowlQ+p94Z4GHLtvCtcYB/QGDy9m0uh pPbs6uQuJj6X0oovZNc16cHd Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 06:40:28 -0700 IronPort-SDR: ecWt+dxxtw9A0afd3Crn1e8R4/JeBd7FHKqzH4V74vCn2SatjlTssCEgS7L4KlCtT5k5aRdBFM w13/N14BXUuoZpp9AKgMtjyMV+SRWvLfaUJCPUZBsCJMD1NyMtPejHTXmROCy2Jxe+Tk58+05m tr3l8yrxnoGpmLGnoEVeNqWRVmkQccp9iysKPor3vvlufPGuIe8FMyXPiNDSIY8wVqM5j0iZEr CZnEESz5T00EaHdl3FYMO+x+LB9lHtliKWnsLyJIzvX3dpHAO3I1z6ZD8mXcvVcjx5uSV681mk LIo= WDCIronportException: Internal Received: from d2bbl13.ad.shared (HELO naota-xeon.wdc.com) ([10.225.55.209]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Mar 2022 07:09:22 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, Naohiro Aota Subject: [PATCH 2/2] btrfs: zoned: activate block group only for extent allocation Date: Wed, 16 Mar 2022 23:09:12 +0900 Message-Id: <186ca14c007ed18db3221bb883df19d3f0fcd8e8.1647437890.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In btrfs_make_block_group(), we activate the allocated block group, expecting that the block group is soon used for allocation. However, the chunk allocation from flush_space() context broke the assumption. There can be a large time gap between the chunk allocation time and the extent allocation time from the chunk. Activating the empty block groups pre-allocated from flush_space() context can exhaust the active zone counter of a device. Once we use all the active zone counts for empty pre-allocated BGs, we cannot activate new BG for the other things: metadata, tree-log, or data relocation BG. That failure results in a fake -ENOSPC. This patch introduces CHUNK_ALLOC_FORCE_FOR_EXTENT to distinguish the chunk allocation from find_free_extent(). Now, the new block group is activated only in that context. Fixes: eb66a010d518 ("btrfs: zoned: activate new block group") Cc: stable@vger.kernel.org # 5.16+: c7d1b9109dd0: btrfs: return allocated block group from do_chunk_alloc() Cc: stable@vger.kernel.org # 5.16+ Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 24 ++++++++++++++++-------- fs/btrfs/block-group.h | 1 + fs/btrfs/extent-tree.c | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index d4ac1c76f539..6caa86c8eb12 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2481,12 +2481,6 @@ 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 */ @@ -3642,8 +3636,14 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, struct btrfs_block_group *ret_bg; bool wait_for_alloc = false; bool should_alloc = false; + bool from_extent_allocation = false; int ret = 0; + if (force == CHUNK_ALLOC_FORCE_FOR_EXTENT) { + from_extent_allocation = true; + force = CHUNK_ALLOC_FORCE; + } + /* Don't re-enter if we're already allocating a chunk */ if (trans->allocating_chunk) return -ENOSPC; @@ -3736,9 +3736,17 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, ret_bg = do_chunk_alloc(trans, flags); trans->allocating_chunk = false; - if (IS_ERR(ret_bg)) + if (IS_ERR(ret_bg)) { ret = PTR_ERR(ret_bg); - else + } else if (!from_extent_allocation) { + /* + * New block group is likely to be used soon. Try to activate + * it now. Failure is OK for now. + */ + btrfs_zone_activate(ret_bg); + } + + if (!ret) btrfs_put_block_group(ret_bg); spin_lock(&space_info->lock); diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 93aabc68bb6a..9c822367c432 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -40,6 +40,7 @@ enum btrfs_chunk_alloc_enum { CHUNK_ALLOC_NO_FORCE, CHUNK_ALLOC_LIMITED, CHUNK_ALLOC_FORCE, + CHUNK_ALLOC_FORCE_FOR_EXTENT, }; struct btrfs_caching_control { diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f477035a2ac2..6aa92f84f465 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4082,7 +4082,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, } ret = btrfs_chunk_alloc(trans, ffe_ctl->flags, - CHUNK_ALLOC_FORCE); + CHUNK_ALLOC_FORCE_FOR_EXTENT); /* Do not bail out on ENOSPC since we can do more. */ if (ret == -ENOSPC)