From patchwork Mon Aug 7 16:12:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344498 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 9C19EC41513 for ; Mon, 7 Aug 2023 16:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjHGQMt (ORCPT ); Mon, 7 Aug 2023 12:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbjHGQMs (ORCPT ); Mon, 7 Aug 2023 12:12:48 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC205E76 for ; Mon, 7 Aug 2023 09:12:46 -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=1691424766; x=1722960766; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hEywDfmvO3mobl2uiu8JD84L3g+QIR8D8FwM+TiwcvE=; b=iScAW44IErUlJqoxJhscOlnH9yGH+KvEnnVZICWi2B7BZ/5zq01hKdEf PGvrYn4vb1GvWdMqoHL8uNnOhiOZAJsE713bOYGSBOmh/zuPpILT66+8Z tmbQq0vhns7uYnqIybshZKDp+U34b+aGtMwVlr1WXFv/iww+69cr3NTnT NdxhZZmRd2G2J7PyhuHHeQnY4xj2OUg3uQtjEISJ0mjznlpj6vNbdWhQ1 n+fpM/o+xlIPUhscEUMCUpEKXa0MwpzmfYe4shLYUQYCFbsBIfrsxlOcm 8gKfzzH6ZSUad1zpWVThbj2254ucUNS6rp93cKCh1zNcFYwaxgDsr3K21 Q==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240710983" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:46 +0800 IronPort-SDR: aY/BE4pFqEI1c8iQhmWEYQz738Bg64hEogXtwrkgBrSAZvtAP0vrCWWu+n6cBDqo38E/ganuw7 lcO134zfCV6r/k0ICz36OpyOB6KxfRQHX3c/Tve2fKShjXTBj3/AcjFD1VBjiEFOHAQGE8tBuA BZOEn2JhbvTs1N9Dx/j77fsUkDTU6luGU/DDVakyTaku8ejF+MJ16xQv0j6rNP5NuhP2beQ7+W g7K/GyfakEuoDfiYCkAKKTWP2eTQlFYzt6lri51w16es6Xc4ksJrXA8btJiqrBDgTCspsHGkHa TDg= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:14 -0700 IronPort-SDR: nVMXp/mkvL1brcCRlHcet2/qX1q3UniVFgGFYf74WFDa2zmQGqS1St4bC2O5TDxBm4+tsezJgD NFyPpucXv8qXVt6rDMWWg129cI4FIZwYBjijHQMYV3oe4e58wfAD5cWK9ChBamOSZ3pD2MfU/M pLdhMmPDf8x6oTWjfF+A9gvNFgkoWj6fKPyffUVrXPEAuER3A6p6BXXUtxyDDs/sxMm2J414CE 3iXgJhIetYuLZeATsbAL8oa7UVxVwMEq0NvQHJsGuIuxQNDVLjwbPtpFGdjWYR1gCgQBGQ1qMv oFQ= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:46 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Christoph Hellwig , Johannes Thumshirn Subject: [PATCH v3 01/10] btrfs: introduce struct to consolidate extent buffer write context Date: Tue, 8 Aug 2023 01:12:31 +0900 Message-ID: <501942a77f2f0b80705f158cec13ba5e7777be3d.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce btrfs_eb_write_context to consolidate writeback_control and the exntent buffer context. This will help adding a block group context as well. While at it, move the eb context setting before btrfs_check_meta_write_pointer(). We can set it here because we anyway need to skip pages in the same eb if that eb is rejected by btrfs_check_meta_write_pointer(). Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/extent_io.c | 14 +++++++------- fs/btrfs/extent_io.h | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 177d65d51447..5905d2d42aab 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1784,9 +1784,9 @@ static int submit_eb_subpage(struct page *page, struct writeback_control *wbc) * previous call. * Return <0 for fatal error. */ -static int submit_eb_page(struct page *page, struct writeback_control *wbc, - struct extent_buffer **eb_context) +static int submit_eb_page(struct page *page, struct btrfs_eb_write_context *ctx) { + struct writeback_control *wbc = ctx->wbc; struct address_space *mapping = page->mapping; struct btrfs_block_group *cache = NULL; struct extent_buffer *eb; @@ -1815,7 +1815,7 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc, return 0; } - if (eb == *eb_context) { + if (eb == ctx->eb) { spin_unlock(&mapping->private_lock); return 0; } @@ -1824,6 +1824,8 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc, if (!ret) return 0; + ctx->eb = eb; + if (!btrfs_check_meta_write_pointer(eb->fs_info, eb, &cache)) { /* * If for_sync, this hole will be filled with @@ -1837,8 +1839,6 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc, return ret; } - *eb_context = eb; - if (!lock_extent_buffer_for_io(eb, wbc)) { btrfs_revert_meta_write_pointer(cache, eb); if (cache) @@ -1861,7 +1861,7 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc, int btree_write_cache_pages(struct address_space *mapping, struct writeback_control *wbc) { - struct extent_buffer *eb_context = NULL; + struct btrfs_eb_write_context ctx = { .wbc = wbc }; struct btrfs_fs_info *fs_info = BTRFS_I(mapping->host)->root->fs_info; int ret = 0; int done = 0; @@ -1903,7 +1903,7 @@ int btree_write_cache_pages(struct address_space *mapping, for (i = 0; i < nr_folios; i++) { struct folio *folio = fbatch.folios[i]; - ret = submit_eb_page(&folio->page, wbc, &eb_context); + ret = submit_eb_page(&folio->page, &ctx); if (ret == 0) continue; if (ret < 0) { diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index adda14c1b763..e243a8eac910 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -93,6 +93,11 @@ struct extent_buffer { #endif }; +struct btrfs_eb_write_context { + struct writeback_control *wbc; + struct extent_buffer *eb; +}; + /* * Get the correct offset inside the page of extent buffer. * From patchwork Mon Aug 7 16:12:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344500 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 A326BC00528 for ; Mon, 7 Aug 2023 16:12:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbjHGQMu (ORCPT ); Mon, 7 Aug 2023 12:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbjHGQMt (ORCPT ); Mon, 7 Aug 2023 12:12:49 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE2E107 for ; Mon, 7 Aug 2023 09:12:47 -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=1691424768; x=1722960768; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vFF6wf0YB4ZW/uxoji6c4/mJIHKWuQFNRCIjEuQmjzk=; b=RbyishWroGajb1+eXF06FbfJjASs/gK75ZvUdNGiAJmjHTNU4c+eDtdc of/4hIehLMdsQNzx5N8P89oFjmvwIOi850SpYjw3pugq9YVr+V9QL+b5k KZxLrkKoOXZj4ZKjely8mpEC0NqWAZQFxXtcRhjfB/YS5yAB71j9V7A3p MVeFZXM58ZzYp45g46gb57s2jOiF29UA+EEcIDfP+ZeADCEYyOPmoQi9q nJKO0DFbQgaFmOrzGPokWBqzbJTRsKWDLaKMf7wWCHSMqH4RVKx8+FCyJ 65Uendta2mpdRSZ6240O8kUXL1AMv33nvAkmu/ThKK/f4Kfep3JEA0iSm w==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240710986" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:47 +0800 IronPort-SDR: JHeutKy2X9rrlMtT1ZWofP6X8ldNV+1O9NLlsGhXXXDECg6snG7cQrH3b3egTzbc9c+tNxe2Gi sZNc2bxcZNbNA+/nGtd0+PWaZ6HM9IruHaEu2BTrSvDKU7leEtTHMsV4OsozBG7D/xpXGSQCfn Wjc4Kwmpr8O5kei4UffNr7bzG2cNLS7kvyRnS2RyQh6umQYRGEl9ORc3XCYtp4Et8jsCDj8nxW y5r2xcZD/a7HLaBgXCM/CeCjKxIJLRvR6VJLgeIN/PUwqdVESfXHIkSRSf1bTQoiEHFrNuzcz7 j1c= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:16 -0700 IronPort-SDR: TOV83ROXglfpRxshTi8fCEU8s5LiiRYdInmSLXiLevCHZvbWv/2B6vEb6cOT+pWpXlvkR7oSF6 Tzfx8e9Axj9mEspWSN0eqzRz/R+5eWnOezIymxmNq1jFop5WnXSpXH5Pm8A1iVCgptOIBfoZ+/ f77k8sFukY1hpMXtqlvm4yiXJWXYK//8/DBzCXtfys81Px4SWABv2IcIYsmAQAVdKIjabrxnSb 7G1FxiXny9ss+seOduc1D3CoJ/pFsr3XrsHnMy4FR5JqNTM7IcTCvHcqLJs97QnAQ8AGYjEfEa JT8= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:47 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Christoph Hellwig , Johannes Thumshirn Subject: [PATCH v3 02/10] btrfs: zoned: introduce block group context to btrfs_eb_write_context Date: Tue, 8 Aug 2023 01:12:32 +0900 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org For metadata write out on the zoned mode, we call btrfs_check_meta_write_pointer() to check if an extent buffer to be written is aligned to the write pointer. We lookup for a block group containing the extent buffer for every extent buffer, which take unnecessary effort as the writing extent buffers are mostly contiguous. Introduce "zoned_bg" to cache the block group working on. Also, while at it, rename "cache" to "block_group". Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/extent_io.c | 15 +++++++-------- fs/btrfs/extent_io.h | 2 ++ fs/btrfs/zoned.c | 35 ++++++++++++++++++++--------------- fs/btrfs/zoned.h | 6 ++---- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 5905d2d42aab..4a629a7cf478 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1788,7 +1788,6 @@ static int submit_eb_page(struct page *page, struct btrfs_eb_write_context *ctx) { struct writeback_control *wbc = ctx->wbc; struct address_space *mapping = page->mapping; - struct btrfs_block_group *cache = NULL; struct extent_buffer *eb; int ret; @@ -1826,7 +1825,7 @@ static int submit_eb_page(struct page *page, struct btrfs_eb_write_context *ctx) ctx->eb = eb; - if (!btrfs_check_meta_write_pointer(eb->fs_info, eb, &cache)) { + if (!btrfs_check_meta_write_pointer(eb->fs_info, ctx)) { /* * If for_sync, this hole will be filled with * trasnsaction commit. @@ -1840,18 +1839,15 @@ static int submit_eb_page(struct page *page, struct btrfs_eb_write_context *ctx) } if (!lock_extent_buffer_for_io(eb, wbc)) { - btrfs_revert_meta_write_pointer(cache, eb); - if (cache) - btrfs_put_block_group(cache); + btrfs_revert_meta_write_pointer(ctx->zoned_bg, eb); free_extent_buffer(eb); return 0; } - if (cache) { + if (ctx->zoned_bg) { /* * Implies write in zoned mode. Mark the last eb in a block group. */ - btrfs_schedule_zone_finish_bg(cache, eb); - btrfs_put_block_group(cache); + btrfs_schedule_zone_finish_bg(ctx->zoned_bg, eb); } write_one_eb(eb, wbc); free_extent_buffer(eb); @@ -1964,6 +1960,9 @@ int btree_write_cache_pages(struct address_space *mapping, ret = 0; if (!ret && BTRFS_FS_ERROR(fs_info)) ret = -EROFS; + + if (ctx.zoned_bg) + btrfs_put_block_group(ctx.zoned_bg); btrfs_zoned_meta_io_unlock(fs_info); return ret; } diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index e243a8eac910..68368ba99321 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -96,6 +96,8 @@ struct extent_buffer { struct btrfs_eb_write_context { struct writeback_control *wbc; struct extent_buffer *eb; + /* Block group @eb resides in. Only used for zoned mode. */ + struct btrfs_block_group *zoned_bg; }; /* diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 5e4285ae112c..3a763eb535b0 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1748,30 +1748,35 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered) } bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, - struct extent_buffer *eb, - struct btrfs_block_group **cache_ret) + struct btrfs_eb_write_context *ctx) { - struct btrfs_block_group *cache; - bool ret = true; + const struct extent_buffer *eb = ctx->eb; + struct btrfs_block_group *block_group = ctx->zoned_bg; if (!btrfs_is_zoned(fs_info)) return true; - cache = btrfs_lookup_block_group(fs_info, eb->start); - if (!cache) - return true; + if (block_group) { + if (block_group->start > eb->start || + block_group->start + block_group->length <= eb->start) { + btrfs_put_block_group(block_group); + block_group = NULL; + ctx->zoned_bg = NULL; + } + } - if (cache->meta_write_pointer != eb->start) { - btrfs_put_block_group(cache); - cache = NULL; - ret = false; - } else { - cache->meta_write_pointer = eb->start + eb->len; + if (!block_group) { + block_group = btrfs_lookup_block_group(fs_info, eb->start); + if (!block_group) + return true; + ctx->zoned_bg = block_group; } - *cache_ret = cache; + if (block_group->meta_write_pointer != eb->start) + return false; + block_group->meta_write_pointer = eb->start + eb->len; - return ret; + return true; } void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 27322b926038..49d5bd87245c 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -59,8 +59,7 @@ void btrfs_redirty_list_add(struct btrfs_transaction *trans, bool btrfs_use_zone_append(struct btrfs_bio *bbio); void btrfs_record_physical_zoned(struct btrfs_bio *bbio); bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, - struct extent_buffer *eb, - struct btrfs_block_group **cache_ret); + struct btrfs_eb_write_context *ctx); void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, struct extent_buffer *eb); int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length); @@ -190,8 +189,7 @@ static inline void btrfs_record_physical_zoned(struct btrfs_bio *bbio) } static inline bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, - struct extent_buffer *eb, - struct btrfs_block_group **cache_ret) + struct btrfs_eb_write_context *ctx) { return true; } From patchwork Mon Aug 7 16:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344499 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 16D1AC001B0 for ; Mon, 7 Aug 2023 16:12:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230357AbjHGQMw (ORCPT ); Mon, 7 Aug 2023 12:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230152AbjHGQMu (ORCPT ); Mon, 7 Aug 2023 12:12:50 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 852FB9F for ; Mon, 7 Aug 2023 09:12:49 -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=1691424769; x=1722960769; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tCqCEWtdNsdcrbDu/klYMSsyOMKVVYrG/3D0RMsBynA=; b=S7i3xcfQw6rzY1qTv1UY3TRSU8UaW7PwhgalBJj4E02fAQxf7APcgWH5 IR38TkjVNdUvvg+NYFX9Rz/sEdLRzJ9FhU0J1V4voIGHKF5zgX6UPHfyb biUo06mXYOoanOtDqk2uyyRVzeZXycX8SGKQwoYVdViY6xJFR1rUXhpKd 26iEji68aHV6m11N3YhZ5Fj/po6oSzOO8QjIyluXIBk5a635olrhOj07f 4fGeQUK4nmGtQ04AZg72oyfMdCG2LQ/aKWrtaOUOg+P1q4fsGoyXnRtV1 /YRAnUbqiBDio/F94fMt3IjpSIzo1t0QsvjlAu20PGw/bZ3oRK6L5qod8 g==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240710987" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:49 +0800 IronPort-SDR: kxs4REdnYyTBO0H+CkvGMWKZ19uJOO9PKBEJzOFwQkg5gYUov/oXgqL4ylA2UPe/L33ebLBG7N evjZ+GMdMT1nla+SQOgXxQf9uSdVgcmT0FVI7MoRa1ek/3EyVEvDaosVu51ZSDmHn5sY+/oAo2 rB7fF2BQ+KETMZnDQfByzRHGpWZXWTfvXzpzysGoRbYa8s36Wu3ruMxknXCSA2hGkTdEmuLmaj b2xBZ4lpP+IVRZtJ3pI3zxHS1DOQ38m/kGp3ERcAl296N5Qwr1TJsFIQ6cRjqsNSk4x288zRvW 3ec= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:17 -0700 IronPort-SDR: tyrdB2f4L12H8IQGwC67ex/tBlQ6W2ua3Ee6Qaitcbfm0lrI5TfsvbtNccN4TBZhDhj+nAjlpX OYLqeMRT1KF2TBQbojYYLhaYoTozClqYfnYkFGZgHPEe5+L9iYZIe3evay6Jn2eINoBiFJtP4i oOuzPpvpR327zhVq5Rak1uraNZFYapXAHlYlQAyqcB7EJ2UlHHDhwVn41Cp+knL35lUBKCPiAj ajoR5fNnMN9EQESvGbir+t4R7nZZ5gHDkNhUGeJMMn+ohKYBDVB10dUQqJ0F0rfdDcTQBUiFKB bs8= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:49 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Christoph Hellwig , Johannes Thumshirn Subject: [PATCH v3 03/10] btrfs: zoned: return int from btrfs_check_meta_write_pointer Date: Tue, 8 Aug 2023 01:12:33 +0900 Message-ID: <0e8fe9f690ef9aa146df3021fd8a60531693ed0a.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have writeback_control passed to btrfs_check_meta_write_pointer(), we can move the wbc condition in submit_eb_page() to btrfs_check_meta_write_pointer() and return int. Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/extent_io.c | 11 +++-------- fs/btrfs/zoned.c | 30 ++++++++++++++++++++++-------- fs/btrfs/zoned.h | 10 +++++----- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 4a629a7cf478..f6c47e24956a 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1825,14 +1825,9 @@ static int submit_eb_page(struct page *page, struct btrfs_eb_write_context *ctx) ctx->eb = eb; - if (!btrfs_check_meta_write_pointer(eb->fs_info, ctx)) { - /* - * If for_sync, this hole will be filled with - * trasnsaction commit. - */ - if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync) - ret = -EAGAIN; - else + ret = btrfs_check_meta_write_pointer(eb->fs_info, ctx); + if (ret) { + if (ret == -EBUSY) ret = 0; free_extent_buffer(eb); return ret; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 3a763eb535b0..beaf082c16c0 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1747,14 +1747,23 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered) } } -bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, - struct btrfs_eb_write_context *ctx) +/* + * Check @ctx->eb is aligned to the write pointer + * + * Return: + * 0: @ctx->eb is at the write pointer. You can write it. + * -EAGAIN: There is a hole. The caller should handle the case. + * -EBUSY: There is a hole, but the caller can just bail out. + */ +int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, + struct btrfs_eb_write_context *ctx) { + const struct writeback_control *wbc = ctx->wbc; const struct extent_buffer *eb = ctx->eb; struct btrfs_block_group *block_group = ctx->zoned_bg; if (!btrfs_is_zoned(fs_info)) - return true; + return 0; if (block_group) { if (block_group->start > eb->start || @@ -1768,15 +1777,20 @@ bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, if (!block_group) { block_group = btrfs_lookup_block_group(fs_info, eb->start); if (!block_group) - return true; + return 0; ctx->zoned_bg = block_group; } - if (block_group->meta_write_pointer != eb->start) - return false; - block_group->meta_write_pointer = eb->start + eb->len; + if (block_group->meta_write_pointer == eb->start) { + block_group->meta_write_pointer = eb->start + eb->len; - return true; + return 0; + } + + /* If for_sync, this hole will be filled with trasnsaction commit. */ + if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync) + return -EAGAIN; + return -EBUSY; } void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 49d5bd87245c..c0859d8be152 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -58,8 +58,8 @@ void btrfs_redirty_list_add(struct btrfs_transaction *trans, struct extent_buffer *eb); bool btrfs_use_zone_append(struct btrfs_bio *bbio); void btrfs_record_physical_zoned(struct btrfs_bio *bbio); -bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, - struct btrfs_eb_write_context *ctx); +int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, + struct btrfs_eb_write_context *ctx); void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, struct extent_buffer *eb); int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length); @@ -188,10 +188,10 @@ static inline void btrfs_record_physical_zoned(struct btrfs_bio *bbio) { } -static inline bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, - struct btrfs_eb_write_context *ctx) +static inline int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, + struct btrfs_eb_write_context *ctx) { - return true; + return 0; } static inline void btrfs_revert_meta_write_pointer( From patchwork Mon Aug 7 16:12:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344501 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 0856BC001DB for ; Mon, 7 Aug 2023 16:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjHGQMx (ORCPT ); Mon, 7 Aug 2023 12:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjHGQMv (ORCPT ); Mon, 7 Aug 2023 12:12:51 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DA4A107 for ; Mon, 7 Aug 2023 09:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1691424770; x=1722960770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DMIzB+rUZKL3+Uf9qDuNv+xyvyf6jcW5vTMmpArf4JA=; b=NfnZuwMWS1Jtz21BUsxxxNI8TP7mK035EqXFr0DJreIVXc1b4koaTsMg DPTdjuMcnRy2SChKdJFpIv8Js1jUuLATXDqgOTIibKND0VB7ZHnGPybPG SIrzAdyHVDqNgkUpdwfi7VH7MkO5HV+Ke1AVGN7Rsx8x6sB//Snnd7MbF EaBWBVSTvX2pbg0pNowI/OQD0x8ZVfF7YQ3Z4RUOIUstT9rh2v0R1SByG VQdXVjKSrjaK0BHuca22vKNA5LL8Gn/vFfpeAAtRaWxTvcSBnM+7m8MMl SVDLOl/Ojns5i90OhDte8lPnjsOs8GMz143+yQ8wM9X43uHzC18SXLQSg w==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240710992" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:50 +0800 IronPort-SDR: XSatE76gCb+ZO81q9oKaK0GlhjkiWJDJqznqpGwtDit6m/DsTvWIL3yE9MdbkES+K/cbhJ+WbR riYYPbbvEWSBj8aq0RSHvfkcAglfiSPZfDxnPdnIErSXucqRyjTwnSOeC+vIkFu2yNlYH8M6Mn 9UxMhYJzYj9ZdP4eGHVNqn251N8COKWWRKU9Fkg4qZiG3P0tpC6fmMXy0hesHqR1dkTauZ1OnN QLUy+FFwsIzu/5GanXaB8sKiR5JZGj1J3sWSpIngKFX9F3dUV8kKplTbjF4uXr3N/LOSfMXs/5 MtQ= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:18 -0700 IronPort-SDR: Uf/B6gePHS0NtZVvc0RAhwh5psU0QzuYRMZGsOHJm+pKSKsjFKts5huLHEOe5pkw5+fahw1n24 Scu+S8efdJXI0WNMKYLREgW3Haw7qzLy7lUynUeUWmEfCqzah3AWU63VMsJeuH/daWI1MxHJkW 8Dkx2f7xYqwM4bG9kuVdOMWfq80MUrFfULlFrJcLlSgzrd64ujPpYYZSoQZx8xlXNV4cTEHcld LD9y+zHi101LqaymLZ55tMxM/xRSIgmA1n/rOkTlK+Y7YhXI9QLGD5OTRN1tS6+oZEYCjY4fFr n08= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:50 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Christoph Hellwig , Johannes Thumshirn Subject: [PATCH v3 04/10] btrfs: zoned: defer advancing meta_write_pointer Date: Tue, 8 Aug 2023 01:12:34 +0900 Message-ID: <3195b4f2e9417c568e6e27b3c218ff67c6e83745.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We currently advance the meta_write_pointer in btrfs_check_meta_write_pointer(). That make it necessary to revert to it when locking the buffer failed. Instead, we can advance it just before sending the buffer. Also, this is necessary for the following commit. In the commit, it needs to release the zoned_meta_io_lock to allow IOs to come in and wait for them to fill the currently active block group. If we advance the meta_write_pointer before locking the extent buffer, the following extent buffer can pass the meta_write_pointer check, resuting in an unaligned write failure. Advancing the pointer is still thread-safe as the extent buffer is locked. Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/extent_io.c | 8 ++++---- fs/btrfs/zoned.c | 15 +-------------- fs/btrfs/zoned.h | 8 -------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index f6c47e24956a..d1b0a0181aed 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1834,15 +1834,15 @@ static int submit_eb_page(struct page *page, struct btrfs_eb_write_context *ctx) } if (!lock_extent_buffer_for_io(eb, wbc)) { - btrfs_revert_meta_write_pointer(ctx->zoned_bg, eb); free_extent_buffer(eb); return 0; } if (ctx->zoned_bg) { - /* - * Implies write in zoned mode. Mark the last eb in a block group. - */ + /* Implies write in zoned mode. */ + + /* Mark the last eb in the block group. */ btrfs_schedule_zone_finish_bg(ctx->zoned_bg, eb); + ctx->zoned_bg->meta_write_pointer += eb->len; } write_one_eb(eb, wbc); free_extent_buffer(eb); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index beaf082c16c0..3f56604bdaef 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1781,11 +1781,8 @@ int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, ctx->zoned_bg = block_group; } - if (block_group->meta_write_pointer == eb->start) { - block_group->meta_write_pointer = eb->start + eb->len; - + if (block_group->meta_write_pointer == eb->start) return 0; - } /* If for_sync, this hole will be filled with trasnsaction commit. */ if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync) @@ -1793,16 +1790,6 @@ int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, return -EBUSY; } -void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, - struct extent_buffer *eb) -{ - if (!btrfs_is_zoned(eb->fs_info) || !cache) - return; - - ASSERT(cache->meta_write_pointer == eb->start + eb->len); - cache->meta_write_pointer = eb->start; -} - int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length) { if (!btrfs_dev_is_sequential(device, physical)) diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index c0859d8be152..74ec37a25808 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -60,8 +60,6 @@ bool btrfs_use_zone_append(struct btrfs_bio *bbio); void btrfs_record_physical_zoned(struct btrfs_bio *bbio); int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, struct btrfs_eb_write_context *ctx); -void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, - struct extent_buffer *eb); int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length); int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical, u64 physical_start, u64 physical_pos); @@ -194,12 +192,6 @@ static inline int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, return 0; } -static inline void btrfs_revert_meta_write_pointer( - struct btrfs_block_group *cache, - struct extent_buffer *eb) -{ -} - static inline int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length) { From patchwork Mon Aug 7 16:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344502 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 ABB90C04A94 for ; Mon, 7 Aug 2023 16:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbjHGQMx (ORCPT ); Mon, 7 Aug 2023 12:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230152AbjHGQMw (ORCPT ); Mon, 7 Aug 2023 12:12:52 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B626F9 for ; Mon, 7 Aug 2023 09:12:52 -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=1691424771; x=1722960771; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y9F4/2b7B6y7uANBCszkRR+x1t0pFNhnUBGzLLPhKKU=; b=ps0Dcbo29vbZvDbsP31QnJ6P1HjY5fU9W5wf/mTQFv77pBW6rkKrG3Yq RjQFkQs28x7ARxT1XwuoCzILfZ70XpWShfwJeH8m53N7IihijLhnjh/1z nKT3NCPw5BxMwA/731TS8thlJ01b0TAMIKdhuisG1DytPbH4W/jvcLvW1 xbL8mpoWh5sVejbMP6dEgbpz6t9xwAmbaTq2cKVXlkaodNBxPScChpaEm qPdCyHBwHFNKOJWDweCSpp3jvZQt7w+Tcqi4sDPTeYvaxHHtIp8gKoLJI uMz/usN0NecTsYDVFF8F7RRzk2UaAa3X5JMdvdNQkD9QGUHUgv4I7oRBi A==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240710995" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:51 +0800 IronPort-SDR: 0TFohbFnPbqxe4CXMUOozDPxqQRASL3TB7ulS/oiEzCxOLztjrhFRh1ycT8VXgEOZyZsRA7pqK 5WyOt0ZbRTMGMlUPjbU5G3ts47oBvPy2DqK+1ZZuoZ4Nt+IO3IsF0LtlJ+ugW7pM1D30Q1xVOb SvI/8rUKNANBgj6sMAhSp9yWSvVCNxlkdg0l9PJhl8M1xRH6E42iAs5j7Ce4UedTkDCDnXBON3 0Qa6WAqu0jbw2qaIT10Lr8Vnk7UEDPzITf/Xws07TUBPVV0t6UTeHOIeSnC7HTSz/S9++NvU8v HfY= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:20 -0700 IronPort-SDR: WNvew3zBecp8CGMD/dwe2Dk8ZfJ8atpEHj2dVskKXmKcz2cGKwCITQcWa9xt7Tp1oMABPzxfIK vKyZUSChYGXctOzvvaJCNV3yBHer5FpLPlxfLkKSre4Rpi9PeP3MzNekj+bAxiACKJjPOx6T7z NTWVN1c+1nQP2Gyg282i3+cDyJ/ZFTwU/LRfVL2kohqBWfUTmL4BsvA+dBrpjqyozELTmHpDp9 D345eVaQ9lCh8HE+HjeBfMToQ16kk7OUYUSqo33VnNNVcMHacYq7NX3Yggz3Lja/dhctPcc6vO R+E= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:51 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Christoph Hellwig , Johannes Thumshirn Subject: [PATCH v3 05/10] btrfs: zoned: update meta_write_pointer on zone finish Date: Tue, 8 Aug 2023 01:12:35 +0900 Message-ID: <5af45dfa56b6dca2189d2cd03c6a1ff526a155e6.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On finishing a zone, the meta_write_pointer should be set of the end of the zone to reflect the actual write pointer position. Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 3f56604bdaef..fd1458049b18 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -2056,6 +2056,9 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ clear_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags); block_group->alloc_offset = block_group->zone_capacity; + if (block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM)) + block_group->meta_write_pointer = block_group->start + + block_group->zone_capacity; block_group->free_space_ctl->free_space = 0; btrfs_clear_treelog_bg(block_group); btrfs_clear_data_reloc_bg(block_group); From patchwork Mon Aug 7 16:12:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344503 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 DE764C00528 for ; Mon, 7 Aug 2023 16:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbjHGQM4 (ORCPT ); Mon, 7 Aug 2023 12:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbjHGQMy (ORCPT ); Mon, 7 Aug 2023 12:12:54 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3587C9F for ; Mon, 7 Aug 2023 09:12:53 -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=1691424773; x=1722960773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KrpRx4Dl+vqEB9ZfZ/PllrAbwOLAIEFv2A2EzpCDMJI=; b=KRvx22TPs6gq/ahGSeqPNWVtVVLOZ3C7HgLGA4RyG2I6O1ktJmuWn6us 4Fl7gt6P/TuSjcgPVM7f8YYODlXE50rM8SHHL4ej8tASSsJjSxiC8h9M9 eX1MDjWLkjfCMGwcSTa8NFn+QW9I+6KMomiFgfQpiFfso4KCif3iZ3CYd xy/tpl/YFXAwdaPOFnAPSs3IZ7qDjrsnlklGsP9gwnWd/+MGq26x0Miys gxM4C1ZvNO99ak/6Tw5nKed6Xu9lJ3KQu7KhwIkPeTKOOdS86q77GbXU7 VS1nHMvrVT1GNQidxkovfHpiqYYZPHpBNg2NaXcxKEMVevANDpGIoJ3LA w==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240710997" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:52 +0800 IronPort-SDR: cQH9OCnkG29SBhTdVUd6Vs/nTlcePwClq+CPVWX8GEQdvcQyjwi87+ZvibjCYOz+x4+VZSBXHl 4cI1UpCm36gWBi8meg2FWJSvQA0Z8zzlgcKCqZoJPR2hs7H1X/EtcJJ/0dB0m7bnvVH/i8N81D 3/AJRTfYNuC7xTgHyewTxjlVleQW+sE+UvQl1d4ODuOTxjcHc5NKccijK9aduLWF/p8SRrBJXB kwgvCxndNcyJElcupurgK00UeElAhXzpv+vUPuli7g3O3Rbsugj97kmMkQhq+KyP7x6ulJhU+X yG0= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:21 -0700 IronPort-SDR: OwOKK/ps63b9rHoxGZD7VN8RD4j5Ga7nZKeeLbGKKULhoJqpYqdKbUZDXoBXRBvcJpoJVc9VUS u0+Qo5jxQSfB1FdTKz5JQgk92Nd4G6LZDwkH/YYpqtblHqijnJOqIObCIrCRmil44qTGea/qlK uw9m+BlXnfJPovhr8+Od2SKQhN6/ziSxVBJHWd00xuEvfqaKzKJk87bQaMViSJKFKHwFl9PQXw ILkWKUB8tHLAs8/JWHkNLDrE/aXil8YKJgjSxEIDslbg98f1L9vTf372BKFOjLEbhtVEuOCZ/F wJM= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:53 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota Subject: [PATCH v3 06/10] btrfs: zoned: reserve zones for an active metadata/system block group Date: Tue, 8 Aug 2023 01:12:36 +0900 Message-ID: <4e44439e8c082a2f9007a4d23506f0a7e38aa86b.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Ensure a metadata and system block group can be activated on write time, by leaving a certain number of active zones when trying to activate a data block group. Zones for two metadata block groups (normal and tree-log) and one system block group are reserved, according to the profile type: two zones per block group on the DUP profile and one zone per block group otherwise. The reservation must be freed once a non-data block group is allocated. If not, we over-reserve the active zones and data block group activation will suffer. For the dynamic reservation count, we need to manage the reservation count per device. The reservation count variable is protected by fs_info->zone_active_bgs_lock. Signed-off-by: Naohiro Aota --- fs/btrfs/disk-io.c | 2 + fs/btrfs/zoned.c | 97 +++++++++++++++++++++++++++++++++++++++++++--- fs/btrfs/zoned.h | 9 +++++ 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index da51e5750443..471bc20e5397 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3456,6 +3456,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device btrfs_free_zone_cache(fs_info); + btrfs_check_active_zone_reservation(fs_info); + if (!sb_rdonly(sb) && fs_info->fs_devices->missing_devices && !btrfs_check_rw_degradable(fs_info, NULL)) { btrfs_warn(fs_info, diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index fd1458049b18..c9a1732469fd 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1889,6 +1889,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) struct map_lookup *map; struct btrfs_device *device; u64 physical; + bool is_data = (block_group->flags & BTRFS_BLOCK_GROUP_DATA); bool ret; int i; @@ -1910,19 +1911,40 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) goto out_unlock; } + spin_lock(&fs_info->zone_active_bgs_lock); for (i = 0; i < map->num_stripes; i++) { + struct btrfs_zoned_device_info *zinfo; + int reserved = 0; + device = map->stripes[i].dev; physical = map->stripes[i].physical; + zinfo = device->zone_info; - if (device->zone_info->max_active_zones == 0) + if (zinfo->max_active_zones == 0) continue; + if (is_data) + reserved = zinfo->reserved_active_zones; + /* + * For the data block group, leave active zones for one + * metadata block group and one system block group. + */ + if (atomic_read(&zinfo->active_zones_left) <= reserved) { + ret = false; + spin_unlock(&fs_info->zone_active_bgs_lock); + goto out_unlock; + } + if (!btrfs_dev_set_active_zone(device, physical)) { /* Cannot activate the zone */ ret = false; + spin_unlock(&fs_info->zone_active_bgs_lock); goto out_unlock; } + if (!is_data) + zinfo->reserved_active_zones--; } + spin_unlock(&fs_info->zone_active_bgs_lock); /* Successfully activated all the zones */ set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags); @@ -2068,18 +2090,21 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ for (i = 0; i < map->num_stripes; i++) { struct btrfs_device *device = map->stripes[i].dev; const u64 physical = map->stripes[i].physical; + struct btrfs_zoned_device_info *zinfo = device->zone_info; - if (device->zone_info->max_active_zones == 0) + if (zinfo->max_active_zones == 0) continue; ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH, physical >> SECTOR_SHIFT, - device->zone_info->zone_size >> SECTOR_SHIFT, + zinfo->zone_size >> SECTOR_SHIFT, GFP_NOFS); if (ret) return ret; + if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA)) + zinfo->reserved_active_zones++; btrfs_dev_clear_active_zone(device, physical); } @@ -2118,8 +2143,10 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) /* Check if there is a device with active zones left */ mutex_lock(&fs_info->chunk_mutex); + spin_lock(&fs_info->zone_active_bgs_lock); list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) { struct btrfs_zoned_device_info *zinfo = device->zone_info; + int reserved = 0; if (!device->bdev) continue; @@ -2129,17 +2156,21 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) break; } + if (flags & BTRFS_BLOCK_GROUP_DATA) + reserved = zinfo->reserved_active_zones; + switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) { case 0: /* single */ - ret = (atomic_read(&zinfo->active_zones_left) >= 1); + ret = (atomic_read(&zinfo->active_zones_left) >= (1 + reserved)); break; case BTRFS_BLOCK_GROUP_DUP: - ret = (atomic_read(&zinfo->active_zones_left) >= 2); + ret = (atomic_read(&zinfo->active_zones_left) >= (2 + reserved)); break; } if (ret) break; } + spin_unlock(&fs_info->zone_active_bgs_lock); mutex_unlock(&fs_info->chunk_mutex); if (!ret) @@ -2386,3 +2417,59 @@ int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info, return 0; } + +/* + * Check if we properly activated one metadata block group and one + * system block group. + */ +void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info) +{ + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + struct btrfs_block_group *block_group; + struct btrfs_device *device; + /* Reserve zones for normal SINGLE metadata and tree-log block group. */ + unsigned int metadata_reserve = 2; + /* Reserve a zone for SINGLE system block group. */ + unsigned int system_reserve = 1; + + /* + * This function is called from the mount context. So, there + * is no parallel process touching the bits. No need for + * read_seqretry(). + */ + if (fs_info->avail_metadata_alloc_bits & BTRFS_BLOCK_GROUP_DUP) + metadata_reserve = 4; + if (fs_info->avail_system_alloc_bits & BTRFS_BLOCK_GROUP_DUP) + system_reserve = 2; + + /* Apply the reservation on all the devices. */ + mutex_lock(&fs_devices->device_list_mutex); + list_for_each_entry(device, &fs_devices->devices, dev_list) { + if (!device->bdev) + continue; + + device->zone_info->reserved_active_zones = + metadata_reserve + system_reserve; + } + mutex_unlock(&fs_devices->device_list_mutex); + + /* Release reservation for currently active block groups. */ + spin_lock(&fs_info->zone_active_bgs_lock); + list_for_each_entry(block_group, &fs_info->zone_active_bgs, + active_bg_list) { + struct map_lookup *map = block_group->physical_map; + int i; + + if (!(block_group->flags & + (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))) + continue; + + for (i = 0; i < map->num_stripes; i++) { + struct btrfs_zoned_device_info *zinfo = + map->stripes[i].dev->zone_info; + + zinfo->reserved_active_zones--; + } + } + spin_unlock(&fs_info->zone_active_bgs_lock); +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 74ec37a25808..03e140018f29 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -22,6 +22,12 @@ struct btrfs_zoned_device_info { u8 zone_size_shift; u32 nr_zones; unsigned int max_active_zones; + /* + * Reserved active zones for one metadata and one system block + * group. It can vary per-device depending of the allocation + * status. + */ + int reserved_active_zones; atomic_t active_zones_left; unsigned long *seq_zones; unsigned long *empty_zones; @@ -78,6 +84,7 @@ void btrfs_zoned_release_data_reloc_bg(struct btrfs_fs_info *fs_info, u64 logica int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info); int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, bool do_finish); +void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -252,6 +259,8 @@ static inline int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info, return 0; } +static inline void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info) { } + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Mon Aug 7 16:12:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344504 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 9A61FC001DB for ; Mon, 7 Aug 2023 16:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbjHGQNK (ORCPT ); Mon, 7 Aug 2023 12:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbjHGQMz (ORCPT ); Mon, 7 Aug 2023 12:12:55 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D722107 for ; Mon, 7 Aug 2023 09:12:54 -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=1691424774; x=1722960774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Duc/mcLPUOjbTaiSK+ncQxB3AJUf8nWjp7YXHJvgkvY=; b=D7Nt4CxdnCUle5Fu0i5FjKK6b8fYAe+FyB7r+7bvqQl4XrY0GwZklhQo kgmYiowHHwEcaCo57HVLnb4E39T+w4zpaD65eWy3h7/Oi3U/gIdymfEQQ Y2nTwbHggW9fke2uV62z2AuLx+e892OP1Rj210MLdIefNz2BTyQjFrxRJ ugNbz2txPeUCBJR98OqNDckZVx6LlpeiakU1OU5KamzqRGs1PUjPp6/ll g0o+2lEFEMy70fPiFS2qP98kyfe0jjrB+DyRdJyrFuRbymG+419Ef8JuX CxGCVxe1G7jiF941UiQRyWaPPU5hfr3Xx/sQGJwK4OyiKUx2Fbnls44gA A==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240711001" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:53 +0800 IronPort-SDR: IyEOGNZGq75OtsYr2WZwx81u9F7tS9CKgPkQHYWuXWmfrCC5knTwprhV/z02ygBE10XbwlpenN S2pi86O6EE7lp7xZu194vGaZxJIQhZTFpphuqK81Hy1VwvseRPVM5HG8AK0ovsyJK0EPczeJGw llioDK+Gr4BtjwqZ8L1FisN4sGh+SnJIsK5749h1+/jVGqlCQxfDC/Cxb2C9+fkuPRsYXryydm JA20sb6rwS+p6TzI/hp4oP1rn/M+Sd5VclpYoZ/sGfZiMNNysiranr3YgIbCC8Uf5em33Cl91Q JMQ= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:22 -0700 IronPort-SDR: 2Ix3tL/p7/R4j9MPAl4esQi7HJSykuTQBRWOJTxYKXhnecPp6c/AGW4wKLzgDDE8xXo9w/W48W 5I1Npw5wXHgi83MjrZthKqsslvz+KE0lg8FzTPHIer5h7WZat9FgLxnsGnPXD80RnRdn9hkyhR bQXt+VUvZlDWCLv9FMuTvWA+klZys+Y9CKivXHOPS1JUcvpR1SuBHuW010Mc13CdXyfrR2lphw VBPBwDqb6OFGp8KIVXTq0zCJz9VhjdxXS7oNIlKXf24VRqze+ngpgs6E1zSp80Q3fadVR97Czb 8wk= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:54 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota Subject: [PATCH v3 07/10] btrfs: zoned: activate metadata block group on write time Date: Tue, 8 Aug 2023 01:12:37 +0900 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the current implementation, block groups are activated at reservation time to ensure that all reserved bytes can be written to an active metadata block group. However, this approach has proven to be less efficient, as it activates block groups more frequently than necessary, putting pressure on the active zone resource and leading to potential issues such as early ENOSPC or hung_task. Another drawback of the current method is that it hampers metadata over-commit, and necessitates additional flush operations and block group allocations, resulting in decreased overall performance. To address these issues, this commit introduces a write-time activation of metadata and system block group. This involves reserving at least one active block group specifically for a metadata and system block group. Since metadata write-out is always allocated sequentially, when we need to write to a non-active block group, we can wait for the ongoing IOs to complete, activate a new block group, and then proceed with writing to the new block group. Fixes: b09315139136 ("btrfs: zoned: activate metadata block group on flush_space") CC: stable@vger.kernel.org # 6.1+ Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 11 ++++++ fs/btrfs/fs.h | 3 ++ fs/btrfs/zoned.c | 83 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index a127865f49f9..b0e432c30e1d 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -4287,6 +4287,17 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) struct btrfs_caching_control *caching_ctl; struct rb_node *n; + if (btrfs_is_zoned(info)) { + if (info->active_meta_bg) { + btrfs_put_block_group(info->active_meta_bg); + info->active_meta_bg = NULL; + } + if (info->active_system_bg) { + btrfs_put_block_group(info->active_system_bg); + info->active_system_bg = NULL; + } + } + write_lock(&info->block_group_cache_lock); while (!list_empty(&info->caching_block_groups)) { caching_ctl = list_entry(info->caching_block_groups.next, diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index ef07c6c252d8..a523d64d5491 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -770,6 +770,9 @@ struct btrfs_fs_info { u64 data_reloc_bg; struct mutex zoned_data_reloc_io_lock; + struct btrfs_block_group *active_meta_bg; + struct btrfs_block_group *active_system_bg; + u64 nr_global_roots; spinlock_t zone_active_bgs_lock; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index c9a1732469fd..4fa1590f71ac 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -65,6 +65,9 @@ #define SUPER_INFO_SECTORS ((u64)BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT) +static void wait_eb_writebacks(struct btrfs_block_group *block_group); +static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_written); + static inline bool sb_zone_is_full(const struct blk_zone *zone) { return (zone->cond == BLK_ZONE_COND_FULL) || @@ -1747,6 +1750,64 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered) } } +static bool check_bg_is_active(struct btrfs_eb_write_context *ctx, + struct btrfs_block_group **active_bg) +{ + const struct writeback_control *wbc = ctx->wbc; + struct btrfs_block_group *block_group = ctx->zoned_bg; + struct btrfs_fs_info *fs_info = block_group->fs_info; + + if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags)) + return true; + + if (fs_info->treelog_bg == block_group->start) { + if (!btrfs_zone_activate(block_group)) { + int ret_fin = btrfs_zone_finish_one_bg(fs_info); + + if (ret_fin != 1 || !btrfs_zone_activate(block_group)) + return false; + } + } else if (*active_bg != block_group) { + struct btrfs_block_group *tgt = *active_bg; + + /* + * zoned_meta_io_lock protects fs_info->active_{meta,system}_bg. + */ + lockdep_assert_held(&fs_info->zoned_meta_io_lock); + + if (tgt) { + /* + * If there is an unsent IO left in the allocated area, + * we cannot wait for them as it may cause a deadlock. + */ + if (tgt->meta_write_pointer < tgt->start + tgt->alloc_offset) { + if (wbc->sync_mode == WB_SYNC_NONE || + (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)) + return false; + } + + /* Pivot active metadata/system block group. */ + btrfs_zoned_meta_io_unlock(fs_info); + wait_eb_writebacks(tgt); + do_zone_finish(tgt, true); + btrfs_zoned_meta_io_lock(fs_info); + if (*active_bg == tgt) { + btrfs_put_block_group(tgt); + *active_bg = NULL; + } + } + if (!btrfs_zone_activate(block_group)) + return false; + if (*active_bg != block_group) { + ASSERT(*active_bg == NULL); + *active_bg = block_group; + btrfs_get_block_group(block_group); + } + } + + return true; +} + /* * Check @ctx->eb is aligned to the write pointer * @@ -1781,8 +1842,26 @@ int btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, ctx->zoned_bg = block_group; } - if (block_group->meta_write_pointer == eb->start) - return 0; + if (block_group->meta_write_pointer == eb->start) { + struct btrfs_block_group **tgt; + + if (!test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &fs_info->flags)) + return 0; + + if (block_group->flags & BTRFS_BLOCK_GROUP_SYSTEM) + tgt = &fs_info->active_system_bg; + else + tgt = &fs_info->active_meta_bg; + if (check_bg_is_active(ctx, tgt)) + return 0; + } + + /* + * Since we may release fs_info->zoned_meta_io_lock, someone can already + * start writing this eb. In that case, we can just bail out. + */ + if (block_group->meta_write_pointer > eb->start) + return -EBUSY; /* If for_sync, this hole will be filled with trasnsaction commit. */ if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync) From patchwork Mon Aug 7 16:12:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344505 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 76505C001B0 for ; Mon, 7 Aug 2023 16:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231166AbjHGQNL (ORCPT ); Mon, 7 Aug 2023 12:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231160AbjHGQM4 (ORCPT ); Mon, 7 Aug 2023 12:12:56 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED8C9E76 for ; Mon, 7 Aug 2023 09:12:54 -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=1691424774; x=1722960774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MT8GbSa51NXABeciN+cPtvwhbjFI+mpRkrpvIzwAf3o=; b=r7dzaBbZMEngdpMWjMMYk/EyEqkicRqjDlzF6ewAznjYFYWL10vbUyZh g6dy9ecMPdzZNsWFNF8mep819ugu7bqNnasb5xUniVBAQkg5pfNMfVXbO oRdjV8jEixYagx8ZDRJWBuA8mUNC6Pp6s/oXEUYjmG6aAulFuApJ8RgqH KtinO6TpDMqxLHnRxYTJmYx71ueV1qpbhRu8DO02FW4sHKp8mt0vM5Y7z lbWXnNzHvOia3//OrNpSkTCyfjyaqehzXy4zlVdh16335uc4DBf+xCj7W p7/tRAYw4nPa++RwzyDRLWwWCqZy8XuaBQsiM5GoMGePBgEon4ShPTR+9 g==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240711005" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:54 +0800 IronPort-SDR: qsMwD3KnNztvbaqHQRQVP5J8Ex8iGyn1he2UVp6pbhKMpCBuR2u+hCZAj1BS70Joon8VCtPihN 389nDZUvlMgJi5uHG3CobfIWtyaN/9vybGnXFgt4WYaQFoiz2y2W2RmiZT1wIx695Z0GHH+A7Q cCa3OkNGLWBFLJhkPTdchVJ4FQftemqgQxkTSo2tjNe/gAqREDkfsFVbsoE35Ggg1CXiIKHI8O 0VWKKZQ0HHPYId/GZ9G0sYNMOzjAuoh+02tCTd32e09kvfn/hTJOAmT29mrQt9OYvnLfzu5ppt YKk= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:23 -0700 IronPort-SDR: FrZlHUAX8a1Ixo13RedlwmzOr7veU9QRJEwE5D4jJK0Ji+FIl4n5SBTvidCNj31cMpr/cclzWo 3VtDQvd3uLyUnG81sUbKmwJqZ6nxKM+wr2pWibLWDB4lUUjYC5p3qVh/9D2OPVSnHQpdag/e5M N5FkbolLjY7On3C+pTLYRGib5USDSOy76MbnF77PbPT0qkNSgwivHI6m5CblK0qRt922ahOAqo zFQ4nq7PymyOvV1jCysyCu2MdV656Cdr5OtFFSCRP/iHo8F36BEwBZtRdKWUKozsEstjPupNuf 2Zg= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:55 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota Subject: [PATCH v3 08/10] btrfs: zoned: no longer count fresh BG region as zone unusable Date: Tue, 8 Aug 2023 01:12:38 +0900 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we switched to write time activation, we no longer need to (and must not) count the fresh region as zone unusable. This commit is similar to revert commit fc22cf8eba79 ("btrfs: zoned: count fresh BG region as zone unusable"). Signed-off-by: Naohiro Aota --- fs/btrfs/free-space-cache.c | 8 +------- fs/btrfs/zoned.c | 26 +++----------------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index cd5bfda2c259..27fad70451aa 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2704,13 +2704,8 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, bg_reclaim_threshold = READ_ONCE(sinfo->bg_reclaim_threshold); spin_lock(&ctl->tree_lock); - /* Count initial region as zone_unusable until it gets activated. */ if (!used) to_free = size; - else if (initial && - test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &block_group->fs_info->flags) && - (block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))) - to_free = 0; else if (initial) to_free = block_group->zone_capacity; else if (offset >= block_group->alloc_offset) @@ -2738,8 +2733,7 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, 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 && - block_group->alloc_offset) { + if (block_group->zone_unusable == block_group->length) { btrfs_mark_bg_unused(block_group); } else if (bg_reclaim_threshold && reclaimable_unusable >= diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 4fa1590f71ac..957fc76079bd 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1586,19 +1586,9 @@ void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) return; WARN_ON(cache->bytes_super != 0); - - /* Check for block groups never get activated */ - if (test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &cache->fs_info->flags) && - cache->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM) && - !test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags) && - cache->alloc_offset == 0) { - unusable = cache->length; - free = 0; - } else { - unusable = (cache->alloc_offset - cache->used) + - (cache->length - cache->zone_capacity); - free = cache->zone_capacity - 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->cached = BTRFS_CACHE_FINISHED; @@ -1964,7 +1954,6 @@ int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical, bool btrfs_zone_activate(struct btrfs_block_group *block_group) { struct btrfs_fs_info *fs_info = block_group->fs_info; - struct btrfs_space_info *space_info = block_group->space_info; struct map_lookup *map; struct btrfs_device *device; u64 physical; @@ -1977,7 +1966,6 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) map = block_group->physical_map; - spin_lock(&space_info->lock); spin_lock(&block_group->lock); if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags)) { ret = true; @@ -2027,14 +2015,7 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) /* Successfully activated all the zones */ set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags); - WARN_ON(block_group->alloc_offset != 0); - if (block_group->zone_unusable == block_group->length) { - block_group->zone_unusable = block_group->length - block_group->zone_capacity; - space_info->bytes_zone_unusable -= block_group->zone_capacity; - } spin_unlock(&block_group->lock); - btrfs_try_granting_tickets(fs_info, space_info); - spin_unlock(&space_info->lock); /* For the active block group list */ btrfs_get_block_group(block_group); @@ -2047,7 +2028,6 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group) out_unlock: spin_unlock(&block_group->lock); - spin_unlock(&space_info->lock); return ret; } From patchwork Mon Aug 7 16:12:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344507 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 30084C04A94 for ; Mon, 7 Aug 2023 16:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231183AbjHGQNM (ORCPT ); Mon, 7 Aug 2023 12:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231287AbjHGQM5 (ORCPT ); Mon, 7 Aug 2023 12:12:57 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEBF9F for ; Mon, 7 Aug 2023 09:12:56 -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=1691424776; x=1722960776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vS6UpWDau4rkkIX3UvgCeTQWa6nwnKETvvTacCIdFvI=; b=glwqf9aDist8HWsqJ3EHylKTJsj9IVwMSTDhnEpUUEA0DhmozTQlFbgr vXIZ1n690pQRPuHeIXOpQuV6Qocu7cjqxk5OPIRcKJqWXt1gFItpVVZ7C PXZUGA775OtNK+fxRP3HCjZ++pg7BS2i2o+cCvcbBYZi0nVZqrMufoXK2 tx0JR1Tsfp67+5xSTlV90D+ehLv9W+VqUfLAf2WvgxDxlzzCZcCkKRnWl ZhdqEVKuPKNcsvea9nLS2kHnOZN0rbQXBKrwkn6mLVcBdW1HNB1hmme/f yY06lyxuNFVMDZ6cMOWpPsY5Unju3DEo2TmcoIjE1Xx0evrAd67avzxPL g==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240711007" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:55 +0800 IronPort-SDR: M9s1t6FZ9Nzm/3gmDs2Xc4bLQ3RI6nihsYuC52kPmeAD7JZMQshb4EXNHVHFQnHM2bEP95plTB QrtLSl6wHNJSe8eo1KOxf0O8ZI3UQn51biySM4kIG4OSFuUKwowqfVZNZYrueCrg22Oq8Sh9tV H+dN5+XQPbrcvdNUyn6h7tkb4nbVzcY/di9h4IzyzK4DLPMcg4HPPz87qHYCioPgJd+RLW7dL8 OdGd9Fk+EOWPYqFZOitOnddrNpuDt1VrrgemCRlpAGJ6dbJECsYOE70DO4ekuWau8TXAAD1LEo Aq0= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:24 -0700 IronPort-SDR: WSPL5gH14JRSR0y6WHD2nkK46sgpHC9wTRj/2XOf33ljZSVedcitaibcdBubwI3X0bCteYvReQ qtXeyFaabLxWfCDZIRiV0i6NpSp6x1UkGCniRTI2givhv2a61C7Ea8jhjv7vXTW4Rn/sHlQjML XYXfRN1xodSUJ1viBUmdsx79uaeLnCv/fDeFCRYyL3J+dzUt79kpMFKEaTIXrtpd5nBM9CvpcA lGtVSYVefu/DtGnyMFTt0N69rqXFnUg6yHp3AQ2Y/5Ge36g6kBmIzAlC1ptZOXXKwQXMn6ydSg Upg= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:56 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 09/10] btrfs: zoned: don't activate non-DATA BG on allocation Date: Tue, 8 Aug 2023 01:12:39 +0900 Message-ID: <96804a0b3e944ce19a5eb786017db0e49defdbd6.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that, a non-DATA block group is activated at write time. Don't activate it on allocation time. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 2 +- fs/btrfs/extent-tree.c | 8 +++++++- fs/btrfs/space-info.c | 28 ---------------------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index b0e432c30e1d..0cb1dee965a0 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -4089,7 +4089,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, if (IS_ERR(ret_bg)) { ret = PTR_ERR(ret_bg); - } else if (from_extent_allocation) { + } else if (from_extent_allocation && (flags & BTRFS_BLOCK_GROUP_DATA)) { /* * New block group is likely to be used soon. Try to activate * it now. Failure is OK for now. diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 12bd8dc37385..92eccb0cd487 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3690,7 +3690,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, } spin_unlock(&block_group->lock); - if (!ret && !btrfs_zone_activate(block_group)) { + /* Metadata block group is activated on write time. */ + if (!ret && (block_group->flags & BTRFS_BLOCK_GROUP_DATA) && + !btrfs_zone_activate(block_group)) { ret = 1; /* * May need to clear fs_info->{treelog,data_reloc}_bg. @@ -3870,6 +3872,10 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl, static int can_allocate_chunk_zoned(struct btrfs_fs_info *fs_info, struct find_free_extent_ctl *ffe_ctl) { + /* Block group's activeness is not a requirement for METADATA block groups. */ + if (!(ffe_ctl->flags & BTRFS_BLOCK_GROUP_DATA)) + return 0; + /* If we can activate new zone, just allocate a chunk and use it */ if (btrfs_can_activate_zone(fs_info->fs_devices, ffe_ctl->flags)) return 0; diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 17c86db7b1b1..356638f54fef 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -761,18 +761,6 @@ static void flush_space(struct btrfs_fs_info *fs_info, break; case ALLOC_CHUNK: case ALLOC_CHUNK_FORCE: - /* - * For metadata space on zoned filesystem, reaching here means we - * don't have enough space left in active_total_bytes. Try to - * activate a block group first, because we may have inactive - * block group already allocated. - */ - ret = btrfs_zoned_activate_one_bg(fs_info, space_info, false); - if (ret < 0) - break; - else if (ret == 1) - break; - trans = btrfs_join_transaction(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); @@ -784,22 +772,6 @@ static void flush_space(struct btrfs_fs_info *fs_info, CHUNK_ALLOC_FORCE); btrfs_end_transaction(trans); - /* - * For metadata space on zoned filesystem, allocating a new chunk - * is not enough. We still need to activate the block * group. - * Active the newly allocated block group by (maybe) finishing - * a block group. - */ - if (ret == 1) { - ret = btrfs_zoned_activate_one_bg(fs_info, space_info, true); - /* - * Revert to the original ret regardless we could finish - * one block group or not. - */ - if (ret >= 0) - ret = 1; - } - if (ret > 0 || ret == -ENOSPC) ret = 0; break; From patchwork Mon Aug 7 16:12:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13344506 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 B9972C00528 for ; Mon, 7 Aug 2023 16:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbjHGQNM (ORCPT ); Mon, 7 Aug 2023 12:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231446AbjHGQNG (ORCPT ); Mon, 7 Aug 2023 12:13:06 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556EFE76 for ; Mon, 7 Aug 2023 09:13:04 -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=1691424784; x=1722960784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sNbAKAy+kC+Wc23YE/wIUBncRpx21RCAvcHOtTdCSWs=; b=l777dB+pb+PbHHLKoyi5uKqrdN82dJx5u4sNiRn4oPZdprhgFF1Gqard bzKR5mNI1OR63gbclxg7tySinY+BWEB1cIorzWElFGp5eK9qoaJi8V5rl Mm3SO+IGF/90UoCgKoeJUNRH+ZZ6ZjyuelXhndSY3abm+q/6nEYfKJ7f2 /wlEsoLQx3dCBIpzlI+DoVP5dGARjxmLMqSh9fsVuKRPeBjYQEUV5zeWD jzuHK4QwuHOGFNIPBwIOy+myqoTq9xsxR5h90OXr2UrZ3rE0ZJOXPzFaU mC7pnc/JlkCRTNjBrdMBZAARYV0F0gZ5jXFeNcWDu4bGbzxQ2c0doJG41 g==; X-IronPort-AV: E=Sophos;i="6.01,262,1684771200"; d="scan'208";a="240711012" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Aug 2023 00:12:57 +0800 IronPort-SDR: WEPIeEzS0K7saSRN7UcGHJkMMQFVx6BBSaiOj0KWp5kwyUBgiyQzYUCgZDkReiIjLfX2fxjhgU 4aD4PB9WIJNVHFrVTrpH5yjH8gFctL00ahxpBcQ5jLZ3wFiK1bgs+MEKuxZR4cSCxZIqPDyE7n HY9e1fdDkhNaCAfa/k7IOoCRomO9Oy7VCU3J0ypDfXhemqbCWTRrDdwyycMJJ/XXdRgxBriD/j QYpq9IYLEgRMyxqtl8/bwXsJRu8jbX4LDszvH7JlH4nSlkb4yY527VA9IJer7lqZ6wt5vax1L2 fnA= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Aug 2023 08:26:25 -0700 IronPort-SDR: OxVxPwM8VKJEwZsENOuAV40PfZzfZ5Hc77zfXiu91kYgJXtOwu+KsYYT/44FptezOmqlGw9wlm 4Lbzqn+/D8hQ3OdEs/VecgFoIrQQ8GVCVne0YWqvM85BucdRBtre1vNg7aMGPLnzGFm1zrNsLa cnYLryoZ4LsASOICUnzN+w0VO3NcTe1W48oUEhSyp4cvD6+VxMFlL8FdC35NN/As3oFpLcyhhE kCIOd0nkr+ZFvsTv/XeExW7ob4ShTdjEsb0Zfy4u4D40IpnIMR4+YqO9Cmp24YsNr4KOppvmml U5w= WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.46]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Aug 2023 09:12:57 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: hch@infradead.org, josef@toxicpanda.com, dsterba@suse.cz, Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 10/10] btrfs: zoned: re-enable metadata over-commit for zoned mode Date: Tue, 8 Aug 2023 01:12:40 +0900 Message-ID: <57ce9e40808eb46ad1ceff1d3bde4cbd82b2cc2f.1691424260.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that, we can re-enable metadata over-commit. As we moved the activation from the reservation time to the write time, we no longer need to ensure all the reserved bytes is properly activated. Without the metadata over-commit, it suffers from lower performance because it needs to flush the delalloc items more often and allocate more block groups. Re-enabling metadata over-commit will solve the issue. Fixes: 79417d040f4f ("btrfs: zoned: disable metadata overcommit for zoned") CC: stable@vger.kernel.org # 6.1+ Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/space-info.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 356638f54fef..d7e8cd4f140c 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -389,11 +389,7 @@ int btrfs_can_overcommit(struct btrfs_fs_info *fs_info, return 0; used = btrfs_space_info_used(space_info, true); - if (test_bit(BTRFS_FS_ACTIVE_ZONE_TRACKING, &fs_info->flags) && - (space_info->flags & BTRFS_BLOCK_GROUP_METADATA)) - avail = 0; - else - avail = calc_available_free_space(fs_info, space_info, flush); + avail = calc_available_free_space(fs_info, space_info, flush); if (used + bytes < space_info->total_bytes + avail) return 1;