From patchwork Thu Nov 18 08:58:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12626345 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C09CCC433EF for ; Thu, 18 Nov 2021 08:58:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAAAC60295 for ; Thu, 18 Nov 2021 08:58:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244965AbhKRJBu (ORCPT ); Thu, 18 Nov 2021 04:01:50 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:58261 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244902AbhKRJBf (ORCPT ); Thu, 18 Nov 2021 04:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637225915; x=1668761915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dOSKCxK1aH8xJIGccwj2MgufmxoL2N8c9WFbiBk9+wA=; b=fEimCknF3syxTFW2GyLLs7T7RyAfQ4JdQf/tZ/gFN5mrSxoJ3iZ0R0IB lRBPPo2wznYi6Jj90DaMaO93S9yCApYWh9L8DhC4giiqT7Q2Zu85zP/Wa CxuwpbavR4K6QsAZuTKMh3sTqzfjl/W4vgErQwrRErl9dAiewECoEW34Q ZvWjGDc+NbXhBizY1sE/v06PTQP382Jf4FaiK4W6JYZam+QcKe6eeG33J p4CgnGhecu328Yy/aCOGtzngbf/OEzKpIhDYE7QdDCyVCMALpfoAIAqQR yy7a49qmZnXR2Y3RyYomFf4KZvLWaIMqN2KI/lfIhUI7vzfcjgYLkqAhs A==; X-IronPort-AV: E=Sophos;i="5.87,244,1631548800"; d="scan'208";a="297759025" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 18 Nov 2021 16:58:27 +0800 IronPort-SDR: NS1DM0EHIwihAAn6R4+yoebFK0iXnLJSJAItK9+yTWyjikrmCqNF3pQk9L9JfOrmrJ3nGem1zE i8Y5FOgh5Vs8R+m3hILWmwggNuBpB9okGi3EvzKlSNuVjP7/y+h890ovHPCcrm37bTjpnA5vC8 mgfRHBxmmO2tr0ySsOLYg61LP1BZavEGFFek39ZkLPqIWv2g4UhVxkHzQ2NfXsroSWAX6ItCRP KlsiZjrcCk0dT1dr8zqimSrqmPs0/7wpLc4BzVDCkgPbsD7jseAzv/3TPOsYbyR0hsOckuxUkC 5uaMXlNZND7ePX9I0GshJXPd Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2021 00:33:28 -0800 IronPort-SDR: YeZsRl6IBZ/lg+ufIwmmjyUVS+2H3op1VEfif37JDOMe0/0y5m1607BVa4I8xn9fDDiobh8KlW tew+PljqihTjtbi4YlpoPTcKbh+BWMW4rQkSc6tGRUdMDGm+UqwK/7IduWuDFoLDaBwS88tJfR xNqu14v9Oudg0+d8ENUyRHTxJeGpsFLDfeVqQrGXek0Lr4+fvURxLAbhe7Pofnyn9gkhFT1+uR DDgYV/pWspPi5Vch5ZLXKS2Atcmi7fLXw8JwVNFJ5UUocfJY1P4+HLlM06qLHg2TQuAp4POSTw GKY= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Nov 2021 00:58:25 -0800 From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Naohiro Aota , David Sterba , Johannes Thumshirn Subject: [PATCH for-5.15.x 1/6] btrfs: introduce btrfs_is_data_reloc_root Date: Thu, 18 Nov 2021 17:58:13 +0900 Message-Id: <04ade7dd079c065161302c626045a8a88d089d8d.1637225333.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org commit 37f00a6d2e9c97d6e7b5c3d47c49b714c3d0b99f upstream There are several places in our codebase where we check if a root is the root of the data reloc tree and subsequent patches will introduce more. Factor out the check into a small helper function instead of open coding it multiple times. Reviewed-by: Naohiro Aota Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.h | 5 +++++ fs/btrfs/disk-io.c | 2 +- fs/btrfs/extent-tree.c | 2 +- fs/btrfs/inode.c | 19 ++++++++----------- fs/btrfs/relocation.c | 3 +-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index c0cebcf745ce..5b990881052c 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3842,6 +3842,11 @@ static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info) return fs_info->zoned != 0; } +static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root) +{ + return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID; +} + /* * We use page status Private2 to indicate there is an ordered extent with * unfinished IO. diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 6965ed081346..f63d8a7e6dae 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1500,7 +1500,7 @@ static int btrfs_init_fs_root(struct btrfs_root *root, dev_t anon_dev) goto fail; if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID && - root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) { + !btrfs_is_data_reloc_root(root)) { set_bit(BTRFS_ROOT_SHAREABLE, &root->state); btrfs_check_and_init_root_item(&root->root_item); } diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0ab456cb4bf8..45e020c9fdc9 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2376,7 +2376,7 @@ int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset, out: btrfs_free_path(path); - if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) + if (btrfs_is_data_reloc_root(root)) WARN_ON(ret > 0); return ret; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7c096ab9bb5e..85663bccde8a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1151,7 +1151,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * fails during the stage where it updates the bytenr of file extent * items. */ - if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) + if (btrfs_is_data_reloc_root(root)) min_alloc_size = num_bytes; else min_alloc_size = fs_info->sectorsize; @@ -1187,8 +1187,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, if (ret) goto out_drop_extent_cache; - if (root->root_key.objectid == - BTRFS_DATA_RELOC_TREE_OBJECTID) { + if (btrfs_is_data_reloc_root(root)) { ret = btrfs_reloc_clone_csums(inode, start, cur_alloc_size); /* @@ -1504,8 +1503,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, int *page_started, unsigned long *nr_written) { const bool is_space_ino = btrfs_is_free_space_inode(inode); - const bool is_reloc_ino = (inode->root->root_key.objectid == - BTRFS_DATA_RELOC_TREE_OBJECTID); + const bool is_reloc_ino = btrfs_is_data_reloc_root(inode->root); const u64 range_bytes = end + 1 - start; struct extent_io_tree *io_tree = &inode->io_tree; u64 range_start = start; @@ -1867,8 +1865,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, btrfs_dec_nocow_writers(fs_info, disk_bytenr); nocow = false; - if (root->root_key.objectid == - BTRFS_DATA_RELOC_TREE_OBJECTID) + if (btrfs_is_data_reloc_root(root)) /* * Error handled later, as we must prevent * extent_clear_unlock_delalloc() in error handler @@ -2207,7 +2204,7 @@ void btrfs_clear_delalloc_extent(struct inode *vfs_inode, if (btrfs_is_testing(fs_info)) return; - if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID && + if (!btrfs_is_data_reloc_root(root) && do_list && !(state->state & EXTENT_NORESERVE) && (*bits & EXTENT_CLEAR_DATA_RESV)) btrfs_free_reserved_data_space_noquota(fs_info, len); @@ -2532,7 +2529,7 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, goto mapit; } else if (async && !skip_sum) { /* csum items have already been cloned */ - if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) + if (btrfs_is_data_reloc_root(root)) goto mapit; /* we're doing a write, do the async checksumming */ ret = btrfs_wq_submit_bio(inode, bio, mirror_num, bio_flags, @@ -3304,7 +3301,7 @@ unsigned int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset, u64 file_offset = pg_off + page_offset(page); int ret; - if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID && + if (btrfs_is_data_reloc_root(root) && test_range_bit(io_tree, file_offset, file_offset + sectorsize - 1, EXTENT_NODATASUM, 1, NULL)) { @@ -4005,7 +4002,7 @@ noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, * without delay */ if (!btrfs_is_free_space_inode(inode) - && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID + && !btrfs_is_data_reloc_root(root) && !test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) { btrfs_update_root_times(trans, root); diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 914d403b4415..2e4f109723af 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4386,8 +4386,7 @@ int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, if (!rc) return 0; - BUG_ON(rc->stage == UPDATE_DATA_PTRS && - root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); + BUG_ON(rc->stage == UPDATE_DATA_PTRS && btrfs_is_data_reloc_root(root)); level = btrfs_header_level(buf); if (btrfs_header_generation(buf) <= From patchwork Thu Nov 18 08:58:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12626347 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AE51C433EF for ; Thu, 18 Nov 2021 08:58:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3592560EE5 for ; Thu, 18 Nov 2021 08:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244946AbhKRJBx (ORCPT ); Thu, 18 Nov 2021 04:01:53 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:58233 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244894AbhKRJBg (ORCPT ); Thu, 18 Nov 2021 04:01:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637225916; x=1668761916; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f67i5tw2IJcDT7x6fHn5SmVXV11kjkCfeem7XCCsBeo=; b=WG/kjicyhkqMMrUaLqKUs2c4jUIFeVd18IsCJZp5OXIpW5i2wCpS3Vvg Gbx3DWfiFr2Kk33UaTQ0JyS+mRAJW5xoz8uSrrNhO01lZWIpRpA1dI9sy KOrIfhPe8MiujOSHhNcepHuW4w4D5N1VFOmZqNF7QH2X6NWhTigF4XbV6 UiC/2tSDRJAg94d15FZiR4iG4HeiwTk1GxxQc5nhI8U7knQknwClo5rGz H0oQE4JLFkSnxAmAcAWy84HqRyIoOMubfUYsxFfzFcWwbce7zEr10HEub 2T2xlI5bfdE+OgzDZLC0pTLWLuPWfUqR+l9U3iWBmF7QjvM/5OHDYLR7y A==; X-IronPort-AV: E=Sophos;i="5.87,244,1631548800"; d="scan'208";a="297759033" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 18 Nov 2021 16:58:31 +0800 IronPort-SDR: YpEFt323M9EFFEj0NelzJUX7t3HPnP+PyEMkOSQV+XaR9DkrQUCh2RUf18O+uKc8PeCQ866AjS gJ4xaDMDcZeAnklDWx/1ft82ot8rXHl2nGQJw19+4rdpsJapIqvjJrOWqh+x7VGusDN6acsvtS TjiSq8gIArmvl0dyOd0HFnL5jwuMEzebvzGmD3vJc+02gGRZeM7jVcu8G/8Rx3jT6yeKdkhYt4 4VnNxh02GAgMpvvsUBgRN4e2Zq8+ch65Hp8NaPXCVFgfc9rr+mUIAfMs00bOxXN2zRav9DVbtC JRKEJ5mL6ozY42yweX36yP1L Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2021 00:33:29 -0800 IronPort-SDR: RLy0tWTrSwu8E4O7HkUhlslm9QdL70GjVNfieiKHXaovxJvwnhkcBlvLDOtPl56tkfWpbd0BPY j8n7lORQ0FzgHXsccZ4pn7ZUK0k6K9YydV16ipx8zKghwznIBMKg9qj2s4w3J4mNIJPHRCBsMA /PsK1JNKJingAvqGC06xDamsNcTdGv3/w0MquarnsT8Q00XOc/ZLdRatxSwfmC9zekvb9l5xVQ 7aqy8F4+kcJBvKvOLi3ZSWq7S3+CD6GZyLeWdgOvn1RhlUjcmyCIyGwSKQNQhHDWYQYE6exg5X KZk= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Nov 2021 00:58:27 -0800 From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Naohiro Aota , David Sterba , Johannes Thumshirn Subject: [PATCH for-5.15.x 2/6] btrfs: zoned: add a dedicated data relocation block group Date: Thu, 18 Nov 2021 17:58:14 +0900 Message-Id: <65b0ea66b418feb236d42410795d024a516eb843.1637225333.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org commit c2707a25562343511bf9a3a6a636a16a822204eb upstream Relocation in a zoned filesystem can fail with a transaction abort with error -22 (EINVAL). This happens because the relocation code assumes that the extents we relocated the data to have the same size the source extents had and ensures this by preallocating the extents. But in a zoned filesystem we currently can't preallocate the extents as this would break the sequential write required rule. Therefore it can happen that the writeback process kicks in while we're still adding pages to a delalloc range and starts writing out dirty pages. This then creates destination extents that are smaller than the source extents, triggering the following safety check in get_new_location(): 1034 if (num_bytes != btrfs_file_extent_disk_num_bytes(leaf, fi)) { 1035 ret = -EINVAL; 1036 goto out; 1037 } Temporarily create a dedicated block group for the relocation process, so no non-relocation data writes can interfere with the relocation writes. This is needed that we can switch the relocation process on a zoned filesystem from the REQ_OP_ZONE_APPEND writing we use for data to a scheme like in a non-zoned filesystem using REQ_OP_WRITE and preallocation. Fixes: 32430c614844 ("btrfs: zoned: enable relocation on a zoned filesystem") Reviewed-by: Naohiro Aota Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn --- fs/btrfs/block-group.c | 1 + fs/btrfs/ctree.h | 7 ++++++ fs/btrfs/disk-io.c | 1 + fs/btrfs/extent-tree.c | 54 ++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/zoned.c | 10 ++++++++ fs/btrfs/zoned.h | 3 +++ 6 files changed, 74 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index a3b830b8410a..a53ebc52bd51 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -902,6 +902,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, spin_unlock(&cluster->refill_lock); btrfs_clear_treelog_bg(block_group); + btrfs_clear_data_reloc_bg(block_group); path = btrfs_alloc_path(); if (!path) { diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5b990881052c..ae06ad559353 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1017,6 +1017,13 @@ struct btrfs_fs_info { spinlock_t treelog_bg_lock; u64 treelog_bg; + /* + * Start of the dedicated data relocation block group, protected by + * relocation_bg_lock. + */ + spinlock_t relocation_bg_lock; + u64 data_reloc_bg; + #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 f63d8a7e6dae..e00c4c1f622f 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->relocation_bg_lock); rwlock_init(&fs_info->tree_mod_log_lock); mutex_init(&fs_info->unused_bg_unpin_mutex); mutex_init(&fs_info->reclaim_bgs_lock); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 45e020c9fdc9..87c23c5c0f26 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3495,6 +3495,9 @@ struct find_free_extent_ctl { /* Allocation is called for tree-log */ bool for_treelog; + /* Allocation is called for data relocation */ + bool for_data_reloc; + /* RAID index, converted from flags */ int index; @@ -3756,6 +3759,7 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, u64 avail; u64 bytenr = block_group->start; u64 log_bytenr; + u64 data_reloc_bytenr; int ret = 0; bool skip; @@ -3773,13 +3777,31 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, if (skip) return 1; + /* + * Do not allow non-relocation blocks in the dedicated relocation block + * group, and vice versa. + */ + spin_lock(&fs_info->relocation_bg_lock); + data_reloc_bytenr = fs_info->data_reloc_bg; + if (data_reloc_bytenr && + ((ffe_ctl->for_data_reloc && bytenr != data_reloc_bytenr) || + (!ffe_ctl->for_data_reloc && bytenr == data_reloc_bytenr))) + skip = true; + spin_unlock(&fs_info->relocation_bg_lock); + if (skip) + return 1; + spin_lock(&space_info->lock); spin_lock(&block_group->lock); spin_lock(&fs_info->treelog_bg_lock); + spin_lock(&fs_info->relocation_bg_lock); ASSERT(!ffe_ctl->for_treelog || block_group->start == fs_info->treelog_bg || fs_info->treelog_bg == 0); + ASSERT(!ffe_ctl->for_data_reloc || + block_group->start == fs_info->data_reloc_bg || + fs_info->data_reloc_bg == 0); if (block_group->ro) { ret = 1; @@ -3796,6 +3818,16 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, goto out; } + /* + * Do not allow currently used block group to be the data relocation + * dedicated block group. + */ + if (ffe_ctl->for_data_reloc && !fs_info->data_reloc_bg && + (block_group->used || block_group->reserved)) { + ret = 1; + goto out; + } + avail = block_group->length - block_group->alloc_offset; if (avail < num_bytes) { if (ffe_ctl->max_extent_size < avail) { @@ -3813,6 +3845,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, if (ffe_ctl->for_treelog && !fs_info->treelog_bg) fs_info->treelog_bg = block_group->start; + if (ffe_ctl->for_data_reloc && !fs_info->data_reloc_bg) + fs_info->data_reloc_bg = block_group->start; + ffe_ctl->found_offset = start + block_group->alloc_offset; block_group->alloc_offset += num_bytes; spin_lock(&ctl->tree_lock); @@ -3829,6 +3864,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, out: if (ret && ffe_ctl->for_treelog) fs_info->treelog_bg = 0; + if (ret && ffe_ctl->for_data_reloc) + fs_info->data_reloc_bg = 0; + spin_unlock(&fs_info->relocation_bg_lock); spin_unlock(&fs_info->treelog_bg_lock); spin_unlock(&block_group->lock); spin_unlock(&space_info->lock); @@ -4085,6 +4123,12 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info, ffe_ctl->hint_byte = fs_info->treelog_bg; spin_unlock(&fs_info->treelog_bg_lock); } + if (ffe_ctl->for_data_reloc) { + spin_lock(&fs_info->relocation_bg_lock); + if (fs_info->data_reloc_bg) + ffe_ctl->hint_byte = fs_info->data_reloc_bg; + spin_unlock(&fs_info->relocation_bg_lock); + } return 0; default: BUG(); @@ -4129,6 +4173,8 @@ static noinline int find_free_extent(struct btrfs_root *root, struct btrfs_space_info *space_info; bool full_search = false; bool for_treelog = (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID); + bool for_data_reloc = (btrfs_is_data_reloc_root(root) && + flags & BTRFS_BLOCK_GROUP_DATA); WARN_ON(num_bytes < fs_info->sectorsize); @@ -4143,6 +4189,7 @@ static noinline int find_free_extent(struct btrfs_root *root, ffe_ctl.found_offset = 0; ffe_ctl.hint_byte = hint_byte_orig; ffe_ctl.for_treelog = for_treelog; + ffe_ctl.for_data_reloc = for_data_reloc; ffe_ctl.policy = BTRFS_EXTENT_ALLOC_CLUSTERED; /* For clustered allocation */ @@ -4220,6 +4267,8 @@ static noinline int find_free_extent(struct btrfs_root *root, if (unlikely(block_group->ro)) { if (for_treelog) btrfs_clear_treelog_bg(block_group); + if (ffe_ctl.for_data_reloc) + btrfs_clear_data_reloc_bg(block_group); continue; } @@ -4408,6 +4457,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 flags; int ret; bool for_treelog = (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID); + bool for_data_reloc = (btrfs_is_data_reloc_root(root) && is_data); flags = get_alloc_profile_by_root(root, is_data); again: @@ -4431,8 +4481,8 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, sinfo = btrfs_find_space_info(fs_info, flags); btrfs_err(fs_info, - "allocation failed flags %llu, wanted %llu tree-log %d", - flags, num_bytes, for_treelog); + "allocation failed flags %llu, wanted %llu tree-log %d, relocation: %d", + flags, num_bytes, for_treelog, for_data_reloc); if (sinfo) btrfs_dump_space_info(fs_info, sinfo, num_bytes, 1); diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 47af1ab3bf12..18ee85e1c9a2 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1530,3 +1530,13 @@ struct btrfs_device *btrfs_zoned_get_device(struct btrfs_fs_info *fs_info, return device; } + +void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg) +{ + struct btrfs_fs_info *fs_info = bg->fs_info; + + spin_lock(&fs_info->relocation_bg_lock); + if (fs_info->data_reloc_bg == bg->start) + fs_info->data_reloc_bg = 0; + spin_unlock(&fs_info->relocation_bg_lock); +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 4b299705bb12..70b3be517599 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -66,6 +66,7 @@ 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); +void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -199,6 +200,8 @@ static inline struct btrfs_device *btrfs_zoned_get_device( return ERR_PTR(-EOPNOTSUPP); } +static inline void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg) { } + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Thu Nov 18 08:58:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12626339 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A672EC433FE for ; Thu, 18 Nov 2021 08:58:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9315C61B3E for ; Thu, 18 Nov 2021 08:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244899AbhKRJBk (ORCPT ); Thu, 18 Nov 2021 04:01:40 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:44972 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244876AbhKRJBb (ORCPT ); Thu, 18 Nov 2021 04:01:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637225911; x=1668761911; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WHh1r8k5Jz7DDZe8TDskDHhXcZyN863quRTci8bgnPY=; b=V7JeI4pxdW3/wAqjFSeW5GxwrTA+vXAabRUjBRG7euK+kNFZSSL1wkAD j3QABwaDAluMJLSjqbrkEFlTzdZdA05/O+hD+lcv/0puvNEmkL7Mj7suX 5N2gqbYb991NLGnQMvueinRns+OoO8iVxPlUHpMQKuXuUmgPTW/afXL0n PhxOottQN2J7IiP7McDAnun+lpoJqMFKohJq5iFMVdt/EL5FvcrC/EYso 5xcJrnIzC2PvTjbNBshEOuAXNWIHsLQV6mIQ4msxYtFKgn0uB94D7bYGx DVQkNLjcEGcB+cFGonxNFDU7Sx+zN9bm/IoJiT+iOR2q8ctxTaJ22fjeE Q==; X-IronPort-AV: E=Sophos;i="5.87,244,1631548800"; d="scan'208";a="185939017" 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; 18 Nov 2021 16:58:29 +0800 IronPort-SDR: MccmnFJvMRUkMhrrQsQqUJP0ojxeQnfkSa65lhFBTuRJt2E5Ti0sPdU8wSSvdKsk2m4SuFgwxC QHXknO+GEHKbaY4Xol8zandLJ4HY53SpWYlrt4bqLiywrWVlsxC0csxGPmR7/T7oiZYrAfJ6xf qA9ykXsXtsNNy+qBMMWqmAGYkLO7wuaTD/pEHzSfOOiMlSryUH6p0FYXpm5801pDYHhNwOzowq 7aDl+y7xPJy3oKRao0Lef4joj6eio4FdTPIvhKqL/veX3l+/HRgkDrJzi2HDTG+zcu+pt4eq9+ pjtHZ1SKIOYCZs7qISYhqve6 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2021 00:33:30 -0800 IronPort-SDR: hAfTts7uAoFAjp0Nk/5qiO/I/0O41ZAol3r4IarHc1XwMFeuC3nezYPI7CRXqo8dL637/Ax2++ QjmjX/xcbXHz8z/mNSbnX2TuPBFw+LvKryLGUYRWUKRFltMuMdBqEpWFuCPJ/p/F6g4LUKDHNA xx1EZSMA1IE/y3lwPy8V3R0HDjQp00r7J9pSjwysaS8jjyltobwYoK3sEh3JQDudUV/1wPcwZE FdmrzA5QeXZIGR7mDaW7BKBXOZK4F0WGHgSzc0kORA69QkRoN4rWpftEajNOauMcadDzNZmdVG hxs= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Nov 2021 00:58:28 -0800 From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Naohiro Aota , David Sterba , Johannes Thumshirn Subject: [PATCH for-5.15.x 3/6] btrfs: zoned: only allow one process to add pages to a relocation inode Date: Thu, 18 Nov 2021 17:58:15 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org commit 35156d852762b58855f513b4f8bb7f32d69dc9c5 upstream Don't allow more than one process to add pages to a relocation inode on a zoned filesystem, otherwise we cannot guarantee the sequential write rule once we're filling preallocated extents on a zoned filesystem. Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index aaddd7225348..a40fb9c74dda 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -5120,6 +5120,9 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end, int extent_writepages(struct address_space *mapping, struct writeback_control *wbc) { + struct inode *inode = mapping->host; + const bool data_reloc = btrfs_is_data_reloc_root(BTRFS_I(inode)->root); + const bool zoned = btrfs_is_zoned(BTRFS_I(inode)->root->fs_info); int ret = 0; struct extent_page_data epd = { .bio_ctrl = { 0 }, @@ -5127,7 +5130,15 @@ int extent_writepages(struct address_space *mapping, .sync_io = wbc->sync_mode == WB_SYNC_ALL, }; + /* + * Allow only a single thread to do the reloc work in zoned mode to + * protect the write pointer updates. + */ + if (data_reloc && zoned) + btrfs_inode_lock(inode, 0); ret = extent_write_cache_pages(mapping, wbc, &epd); + if (data_reloc && zoned) + btrfs_inode_unlock(inode, 0); ASSERT(ret <= 0); if (ret < 0) { end_write_bio(&epd, ret); From patchwork Thu Nov 18 08:58:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12626341 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 625EEC433F5 for ; Thu, 18 Nov 2021 08:58:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4636B60E53 for ; Thu, 18 Nov 2021 08:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244947AbhKRJBn (ORCPT ); Thu, 18 Nov 2021 04:01:43 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:44975 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243644AbhKRJBb (ORCPT ); Thu, 18 Nov 2021 04:01:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637225911; x=1668761911; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bbkWWi0qrIYwJrDg5z1r0cP32UMmMABKlS7CI2fNsCE=; b=bk0+nD9/ocCQRuBb8jCVdWvblWtJp/f+YJJ64VQfr28rfqlxJ+EOWYDm PO39K9GkmGT6HqU//gcropDP6pboTc4so3xbmRvXDQqK+Qf85K8O5LeZR r4i8LztQ0zFlrCOnpgqdc0gw83AFphXk4WaWTHJq9PlUHOzdWW95wIXky V1uDNn9h6YZF9SXyIhryElz17A/JTqogrJ4+2IHhgMGdBKY8B1+Z3ZfHX qebKz2l0+2p6f3vQC0tA4FLiPe97sk+dTkj8VRaGV3R+SsjvC7kLZpsYj LpqzSdg2zW1gPG+DzrOkom6tM5HnOE9iKDpgCE7KshCdCaMEDu/LR7VuU g==; X-IronPort-AV: E=Sophos;i="5.87,244,1631548800"; d="scan'208";a="185939021" 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; 18 Nov 2021 16:58:30 +0800 IronPort-SDR: 9Xmc9rbSk/ZaU+5fXPE1jjXvwYF+OJZKkQnMqZv9UZa1khO1c2ypYhiXTBSMCcwX73/sO2Y9X9 yZ0Y0syJZJnEbJ/DkE9ry4FuFmg56D7lQcSUXj/uBl4O0lIIBoqUsmgfEX0ev7kXl17my8ZTcW so251CMgSDyNr6xG5b+5Rl8V8B5eq/cdiWBLJDu9JGJbqQPWLoeLw/ZBV+OuA9tmtg22MXj5N7 StWSNIoLyyzyQYzzhIvynfr7UWMHrwf4bvqPJfa67lChDGzFCy6oaUuwwu5/DIZWETt7wvEhA7 wNyiVN2zzzYmQDc5jGMaqb6h Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2021 00:33:32 -0800 IronPort-SDR: lSbRxrVTqC75rOiJeOalKdojepFnFA2bklOfAPFiU0/Zitt0KN6hYpXQR/hQTeGgI1XJOlWmfz yHWCXJ/1nLqDiWofvU9aDH3ETTpB8BbvmuqV9P6uJIb2Ydv7h6/Qn3tQS1g19Um75vLriCXN0G FHZp8e6bpFONTiAQbwk+BnZCun9/qYraO2Ew0GYHXVYSFVHGT8ar9UdDxmInAL/k3rhVqk6ucL EJlEFEU80424iwqFmcKpMIX+tqzpkAGdbCtXf0FRiPU0WJUkMJal00WQN4BsRy2VkjENpMq+cT kDk= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Nov 2021 00:58:30 -0800 From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Naohiro Aota , David Sterba , Johannes Thumshirn Subject: [PATCH for-5.15.x 4/6] btrfs: zoned: use regular writes for relocation Date: Thu, 18 Nov 2021 17:58:16 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org commit e6d261e3b1f777b499ce8f535ed44dd1b69278b7 upstream Now that we have a dedicated block group for relocation, we can use REQ_OP_WRITE instead of REQ_OP_ZONE_APPEND for writing out the data on relocation. Reviewed-by: Naohiro Aota Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn --- fs/btrfs/zoned.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 18ee85e1c9a2..5672c24a2d58 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1304,6 +1304,17 @@ bool btrfs_use_zone_append(struct btrfs_inode *inode, u64 start) if (!is_data_inode(&inode->vfs_inode)) return false; + /* + * Using REQ_OP_ZONE_APPNED for relocation can break assumptions on the + * extent layout the relocation code has. + * Furthermore we have set aside own block-group from which only the + * relocation "process" can allocate and make sure only one process at a + * time can add pages to an extent that gets relocated, so it's safe to + * use regular REQ_OP_WRITE for this special case. + */ + if (btrfs_is_data_reloc_root(inode->root)) + return false; + cache = btrfs_lookup_block_group(fs_info, start); ASSERT(cache); if (!cache) From patchwork Thu Nov 18 08:58:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12626343 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CE67C433EF for ; Thu, 18 Nov 2021 08:58:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6210F60E53 for ; Thu, 18 Nov 2021 08:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244957AbhKRJBq (ORCPT ); Thu, 18 Nov 2021 04:01:46 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:51867 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244892AbhKRJBe (ORCPT ); Thu, 18 Nov 2021 04:01:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637225914; x=1668761914; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E2JkQrCaOvVejULm/4ROclZwcEoidXyYpOrhDUep9+o=; b=YDB7ubmg5vmt9u8KM96NP6slo1aFt5ha2rRC1tK2VR8XvZQ1k/11LGKM utZlxWyfcONhbKTOcLN6pv/0/w0Zm1WMQSiK+67qkmksAeIoiD0EIW4TA 2olP6VcOqRaHlYxI9Dvece2ANM1LJakhO1pPla0GE137PB8fKHWdMq4SF 5DlSY4MAER8EJIsxyx9CYHGALbrZ4uRZ8yxQiy2v1oYik0IReV/LPcMVM pvRfTjqayYrZb7IIE1VqTedyowJvsy3o4Z7FXWMtv749jxl/8w6CamCxl U2CknljhIbZZhdrL50UMIMk6pPlgSo6tVl9ZQqaGdu7R/thwpsBwOsN0i w==; X-IronPort-AV: E=Sophos;i="5.87,244,1631548800"; d="scan'208";a="289876573" 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; 18 Nov 2021 16:58:32 +0800 IronPort-SDR: 4G3kPnXoi6I6fhYSVVEiFoH5mOguSKmxXNX87/CxCw9leSffmIz4VHjc3l5iTttKYsjFVxl9Zk UOD9pO2+bD7VZkHvYL8wRsi/x//+NQETKJ65JzD4kPUcoetCSPmWj7/yUzkteVvVFhwV7jSseM 9bIDYuNtJtjJG67MaixteTu0PX5c1EQNVEK9UKwsJeBWiiUgqD7KPLA8tGmfnPOckIhT/89VX/ Vw8QWfFqcLUYx+5Zkz7EoEZyfROLGuuG79kQnXEmaQSAl+xXwcT/xB+jOGST3SEzEKzv3MiuSn YexkkGKcXmPXq9GoQhLGEbL5 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2021 00:33:33 -0800 IronPort-SDR: L7UwQ1fS4zq4scqfSxrx8+Mz4mYl3RVYEcfBLBe1beFJpACVIXhIayJaCgDmSSpcRWszhPhazM v7v/KWfDDM/ouh0UjBAqLhXM14LbaUF56X0CNCd5oEk6YXvnQIbUk2HJr7Xrx981FiwQ3qtNRC VzeI+8R+K8ZHcZ5OzDR6LWeev/4UG2OyNhJN9NAnxlT1GUmp62awjFms/QBeOUiSAc0fr+JDuY 8gipubVjAe9XgV6uDu14G0Rbn8rjt94r69azkugkHFtZ7PEyzA39FZuSql4SRQkQPcGJiluMxp RFY= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Nov 2021 00:58:31 -0800 From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Naohiro Aota , David Sterba , Johannes Thumshirn Subject: [PATCH for-5.15.x 5/6] btrfs: check for relocation inodes on zoned btrfs in should_nocow Date: Thu, 18 Nov 2021 17:58:17 +0900 Message-Id: <2b57613ad55081ae305f66db17dec297f84c04ca.1637225333.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org commit 2adada886b26e998b5a624e72f0834ebfdc54cc7 upstream Prepare for allowing preallocation for relocation inodes. Reviewed-by: Naohiro Aota Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn --- fs/btrfs/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 85663bccde8a..61b4651f008d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1945,7 +1945,15 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page const bool zoned = btrfs_is_zoned(inode->root->fs_info); if (should_nocow(inode, start, end)) { - ASSERT(!zoned); + /* + * Normally on a zoned device we're only doing COW writes, but + * in case of relocation on a zoned filesystem we have taken + * precaution, that we're only writing sequentially. It's safe + * to use run_delalloc_nocow() here, like for regular + * preallocated inodes. + */ + ASSERT(!zoned || + (zoned && btrfs_is_data_reloc_root(inode->root))); ret = run_delalloc_nocow(inode, locked_page, start, end, page_started, nr_written); } else if (!inode_can_compress(inode) || From patchwork Thu Nov 18 08:58:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12626349 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E361EC433EF for ; Thu, 18 Nov 2021 08:58:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC1C860295 for ; Thu, 18 Nov 2021 08:58:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244968AbhKRJBz (ORCPT ); Thu, 18 Nov 2021 04:01:55 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:5639 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244889AbhKRJBg (ORCPT ); Thu, 18 Nov 2021 04:01:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1637225916; x=1668761916; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wu2mkK4/Z0F4flcQj1uMXgMl1r5L0y+zLwmcRny/fy4=; b=p7U/xkZCZ5EPwWBcU9b/2H3E+0Vp/0oenZMxZq7X++0H/89tFb3agDRO krOU8/AkvVN4nI8AFfnn/M/QoAWB9UCJ8jn2grDx+N1/rkaRXeHXcpG36 sh8Ieouow7hgn9i7diEXxFoxJJXpK+bfne7xjGZ7ejTFX1OI42sPzPwkN yU8V8G/EqodvoOFyuU3KC8QlBB8Mrf5CJsuNGL2Xdm+g0O6IyY8qryW0i C045VtH5GS8Y3gZ/HPgNaF6knFziAF9tUlaGdDzchSqVH06QbacS7KCgj EceTph8gKuIu6XAit4sb3hZPCYUP7o0RviVuVMK4kzMh1364BoxugWBu+ w==; X-IronPort-AV: E=Sophos;i="5.87,244,1631548800"; d="scan'208";a="190749233" 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; 18 Nov 2021 16:58:35 +0800 IronPort-SDR: Uc3iC6tkv5qANKHZurNBsTz83hXrizF+tVQwvgw2D0ctQrrYfg7yy1Jnftwn18dxRNLHOHG5+w NiWUE/rOSFJOs6MEn3HRlBjCeUdIozhtTitD7gvVI2VJyRK97QVyPD4CXjzfNUng5icXlaL3WZ RRi8ucoaU0k7/d+Sp9p8LfoNTjvNwZ+1cdTXSUuGA9O+hRHthrCa3+hxOTPMJ2deLLVLPdDZzc fFjLqA21Hejg/wFb19qSAXFRZZKAIPSNMHA9qs9SiKKUiS+izXXBWc/nsjB/LyaeHx6fcxosE9 WgB/0dvFqQ3SujGyKkkkjQaC Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2021 00:33:35 -0800 IronPort-SDR: a+ACesNdo6aT5hgn6ZymbZqFIY9ebIZiuhT6TTa+CaH5OD6QiDdsacQSeNu+7oAJlpHKabKS6b ULZDJCiuL5gW2GrBksLKTjCoWbpSZTU7s5Z4nos6TetO3Rj2AcC3vggD9Y+2a8+J8/T0h3teEu 7NumzHqbnr3QoE5alKn3+TtZr7Qr7NA3ByTRDynOLVkbhILO/BhVapqH4tCE/pqzFRB2qD7yR7 KcfsUJ7ej68I70LU65tzfDAtFY4zSLLKdVjqqF+zuqLCmFnj7KlfiQiy7qlXfvMhHgbFV+7rOx Atg= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 18 Nov 2021 00:58:33 -0800 From: Johannes Thumshirn To: Greg Kroah-Hartman Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Naohiro Aota , David Sterba , Johannes Thumshirn Subject: [PATCH for-5.15.x 6/6] btrfs: zoned: allow preallocation for relocation inodes Date: Thu, 18 Nov 2021 17:58:18 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org commit 960a3166aed015887cd54423a6589ae4d0b65bd5 upstream Now that we use a dedicated block group and regular writes for data relocation, we can preallocate the space needed for a relocated inode, just like we do in regular mode. Essentially this reverts commit 32430c614844 ("btrfs: zoned: enable relocation on a zoned filesystem") as it is not needed anymore. Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Johannes Thumshirn --- fs/btrfs/relocation.c | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 2e4f109723af..d81bee621d37 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2852,31 +2852,6 @@ static noinline_for_stack int prealloc_file_extent_cluster( if (ret) return ret; - /* - * On a zoned filesystem, we cannot preallocate the file region. - * Instead, we dirty and fiemap_write the region. - */ - if (btrfs_is_zoned(inode->root->fs_info)) { - struct btrfs_root *root = inode->root; - struct btrfs_trans_handle *trans; - - end = cluster->end - offset + 1; - trans = btrfs_start_transaction(root, 1); - if (IS_ERR(trans)) - return PTR_ERR(trans); - - inode->vfs_inode.i_ctime = current_time(&inode->vfs_inode); - i_size_write(&inode->vfs_inode, end); - ret = btrfs_update_inode(trans, root, inode); - if (ret) { - btrfs_abort_transaction(trans, ret); - btrfs_end_transaction(trans); - return ret; - } - - return btrfs_end_transaction(trans); - } - btrfs_inode_lock(&inode->vfs_inode, 0); for (nr = 0; nr < cluster->nr; nr++) { start = cluster->boundary[nr] - offset; @@ -3084,7 +3059,6 @@ static int relocate_one_page(struct inode *inode, struct file_ra_state *ra, static int relocate_file_extent_cluster(struct inode *inode, struct file_extent_cluster *cluster) { - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); u64 offset = BTRFS_I(inode)->index_cnt; unsigned long index; unsigned long last_index; @@ -3114,8 +3088,6 @@ static int relocate_file_extent_cluster(struct inode *inode, for (index = (cluster->start - offset) >> PAGE_SHIFT; index <= last_index && !ret; index++) ret = relocate_one_page(inode, ra, cluster, &cluster_nr, index); - if (btrfs_is_zoned(fs_info) && !ret) - ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); if (ret == 0) WARN_ON(cluster_nr != cluster->nr); out: @@ -3770,12 +3742,8 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, struct btrfs_path *path; struct btrfs_inode_item *item; struct extent_buffer *leaf; - u64 flags = BTRFS_INODE_NOCOMPRESS | BTRFS_INODE_PREALLOC; int ret; - if (btrfs_is_zoned(trans->fs_info)) - flags &= ~BTRFS_INODE_PREALLOC; - path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -3790,7 +3758,8 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, btrfs_set_inode_generation(leaf, item, 1); btrfs_set_inode_size(leaf, item, 0); btrfs_set_inode_mode(leaf, item, S_IFREG | 0600); - btrfs_set_inode_flags(leaf, item, flags); + btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS | + BTRFS_INODE_PREALLOC); btrfs_mark_buffer_dirty(leaf); out: btrfs_free_path(path);