From patchwork Wed Sep 8 16:19:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C3BEC433FE for ; Wed, 8 Sep 2021 16:19:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 735C761154 for ; Wed, 8 Sep 2021 16:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348697AbhIHQUw (ORCPT ); Wed, 8 Sep 2021 12:20:52 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347311AbhIHQUv (ORCPT ); Wed, 8 Sep 2021 12:20:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117982; x=1662653982; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GYpFKNRpd41hqGMfWj37r2AMYvC9qtlunoHuJXbFeGA=; b=iy7OQ7fvQz1APDottisZdHbmFpVXBdjldOkenDtJEBhd/aXSB8KEqCFY qflSZfqmU916EWpIHzeB9uczqkTYOucMNXflHZsNgGBKdV49cRMAtXRV+ SyKZ++Hv11wnGdwxqD4V84rf/B2AyW8WoM0dzt9abhJwyqj0Wf7YBtbUs 9RpPUJRfc9jmtU6NByj8Bnz2q3VdAyqWuo2MUTh23DOQGZhkeStcz9oa1 HYmPKfPp5WM+b6Rq+gxxKSdoFfC62wXuEMdM+zK9BRBEeXmZCK2wO6w31 qXwPa273kYRKzP7/uSs3ura6iMP8kpE4VnJbMGNaVmoXHrTLf0jQ/LNOm w==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493935" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:42 +0800 IronPort-SDR: IDMvioCEgkKC5T+XypvCrIAY0Al9xFL3wLEmPyO6XpsFxDudn9Ma7jTOr/kYoudM97iNiSf6dy hq+NUYx+EuV4/E6Aq2GupLFDtJd916Zn/cKYPfes4ksPDcM/gQvh/jhn7hs5P/WYfnE5VR31bb p0Npcq0wZy2W9pnNcpkQ7BJ5BldhJ12r5qKXBV32vsRictYHDE94Mzn3Odj3qpsFZcbVvNECtq uU8+QGuL/YSx9yms/Sg/3b24f6MEIWR9TjafhyjcQy18JLRfWZQgGf+nL33GfVxnalqtz2Ni3O mxRMX46pykoIr3mxeOODdam4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:40 -0700 IronPort-SDR: x4xUruK5I4s9SmY6jbW6areFNtNR0FCs8lKnAQIfxk/0nbQlwtdgA4DLY2V4+PRk0PQT9e4Ick GIf1uOuQMakrXHKxLDxLoocWu2wOvfs57szJzUy28DdIz8G5eX7IB0CKysam3M1QmOs/h7D1bo cBYZGQRylL334jnfI7ahCk0rccPobWWhiC0KdaiPX7/COpDIrZrRZRMDrOpcO6Ye17XKxX/7+Z XO68CwkQWWn73IFKechDEjCmiOXkQRUQmGUlrLAXb0KkSbrpOH5wYjQc2RGS8pn9sR4zOcyA03 iFY= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:43 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn , Naohiro Aota Subject: [PATCH v2 1/8] btrfs: introduce btrfs_is_data_reloc_root Date: Thu, 9 Sep 2021 01:19:25 +0900 Message-Id: <79cc0b662b3ece2d27b22ba35535ad58b0b0755d.1631117101.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 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. Signed-off-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- 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 | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 38870ae46cbb..8cc0b29e24ee 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3846,6 +3846,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 7d80e5b22d32..d63c5e776a96 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 7d03ffa04bce..239e09f7239a 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 a3ce50289888..e89e16a9c56c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1150,7 +1150,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; @@ -1186,8 +1186,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); /* @@ -1503,8 +1502,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; @@ -1866,8 +1864,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 @@ -2206,7 +2203,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); @@ -2531,7 +2528,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, @@ -3307,7 +3304,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)) { @@ -4008,7 +4005,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 63d2b22cf438..3c9c0aab7fc3 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4391,7 +4391,7 @@ int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, return 0; BUG_ON(rc->stage == UPDATE_DATA_PTRS && - root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); + btrfs_is_data_reloc_root(root)); level = btrfs_header_level(buf); if (btrfs_header_generation(buf) <= From patchwork Wed Sep 8 16:19:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2795C4332F for ; Wed, 8 Sep 2021 16:19:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6B3360F5E for ; Wed, 8 Sep 2021 16:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348380AbhIHQUx (ORCPT ); Wed, 8 Sep 2021 12:20:53 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348763AbhIHQUw (ORCPT ); Wed, 8 Sep 2021 12:20:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117984; x=1662653984; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2/FxjR6XDJ5bZutArlH6O+Su+BwNABwdsCO8gqqA+9A=; b=okI7VQbOySfxWib8GmNqjhcXBloA6LImsioWe1Mg/bfGbJNmPXPWscuY K7gzwxVq3Iqa9+/Oz/YwVdf/iYp9VjSg8xmVpRktcZrzFu6alP97a7Knv esBOgbRkOPCh/HPUmlw/Sg5pdRAwFTg5i8vpuMZulM9jNYIsZ+VDrtMI3 7FBdP1tesQSS8PCH8o7RCAbLNSqvE6CNYJYBeByWWo+7aRmRLF+dAiwWL Vljxjv7RwcvRCtY1BBvUQ9omN27VP0tCQWitlOgjt6CM0VJXjBKpvkO3e MlNPiLLxoATZaawfeo/qCsTwcSULYj5sd26UPn2wBE/nNgEmDpSW52ryS A==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493936" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:44 +0800 IronPort-SDR: 5Uzn1x8hMWkglPBLoGFtsBe7jxG+9ou50ibRDawKGpL83z2PUKd8+u91nd2nafu7geol8KOz7Y RsD4GdnqYZOOt9kzwZUY6kn8W3VTP1eju+eWg+Xp/7L/S99O/YOvHhxk2H6fPjOaXanQrGuvrD cpOb8RXrbUkZyfKTnvTmyOxBqesNm0Aer0pNDj8CrGQNx9jtr0Pb+0TqRlbLpqCQepe+fFSvOZ AI1f6i/iDA/KI7+JII0BX6agBE+gIig7TQo50YlUdecFMWq+9S1O7Tz8ta2k0A0t/md5SOK2dm 6iAOzMHyYKCS06dDkxQxWWGp Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:41 -0700 IronPort-SDR: 9UcqUa/tzRMxbjNOVraLz3VVbaKO5o+/Qhaa83vVDAA7g3zD+judJhTSOHkYJUBl1CWfp3fYUJ GFZ2SMpsVEV8/KlwXKci+3cRKoLGVS6ax57RziDf5A7q0dcod7UCTikIkzjXOmz1uu7fWcPQZc MoG0rPdm1n88PJq+0P5+JJ5G9aTECCBP6N2BwF76g6xRv/dh61GzHYNHUY/2gQFSVfZ/pdJ77q v82zJB3PJ1axZSGzfpe5OoUxxVnOZNim80wQQ4ihFof64vTSSfvWnP3Kbyr0VXGybskcqrmVxI 3No= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:44 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn , Naohiro Aota Subject: [PATCH v2 2/8] btrfs: zoned: add a dedicated data relocation block group Date: Thu, 9 Sep 2021 01:19:26 +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 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 delallocation 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") Signed-off-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/block-group.c | 1 + fs/btrfs/ctree.h | 7 ++++++ fs/btrfs/disk-io.c | 1 + fs/btrfs/extent-tree.c | 51 ++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/zoned.c | 10 +++++++++ fs/btrfs/zoned.h | 4 +++- 6 files changed, 71 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 1302bf8d0be1..46fdef7bbe20 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -903,6 +903,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 8cc0b29e24ee..2e2f87a6c5f4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1018,6 +1018,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; + spinlock_t zone_active_bgs_lock; struct list_head zone_active_bgs; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d63c5e776a96..be382276d24f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2885,6 +2885,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) spin_lock_init(&fs_info->unused_bgs_lock); spin_lock_init(&fs_info->treelog_bg_lock); spin_lock_init(&fs_info->zone_active_bgs_lock); + 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 239e09f7239a..708dc6492f97 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3497,6 +3497,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; @@ -3758,6 +3761,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; @@ -3775,6 +3779,19 @@ 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; /* Check RO and no space case before trying to activate it */ spin_lock(&block_group->lock); if (block_group->ro || @@ -3790,10 +3807,14 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, 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; @@ -3810,6 +3831,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; + } + WARN_ON_ONCE(block_group->alloc_offset > block_group->zone_capacity); avail = block_group->zone_capacity - block_group->alloc_offset; if (avail < num_bytes) { @@ -3828,6 +3859,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); @@ -3844,6 +3878,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); @@ -4112,6 +4149,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(); @@ -4245,6 +4288,8 @@ static noinline int find_free_extent(struct btrfs_root *root, if (unlikely(block_group->ro)) { if (ffe_ctl->for_treelog) btrfs_clear_treelog_bg(block_group); + if (ffe_ctl->for_data_reloc) + btrfs_clear_data_reloc_bg(block_group); continue; } @@ -4438,6 +4483,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: @@ -4451,6 +4497,7 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, ffe_ctl.delalloc = delalloc; ffe_ctl.hint_byte = hint_byte; ffe_ctl.for_treelog = for_treelog; + ffe_ctl.for_data_reloc = for_data_reloc; ret = find_free_extent(root, ins, &ffe_ctl); if (!ret && !is_data) { @@ -4470,8 +4517,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 28a06c2d80ad..c7fe3e11e685 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1954,3 +1954,13 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len out: btrfs_put_block_group(block_group); } + +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 9c512402d7f4..0cec8d4050b4 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -75,6 +75,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, int raid_index); void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length); +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) @@ -229,6 +230,8 @@ static inline bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, static inline void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 length) { } +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) @@ -346,5 +349,4 @@ static inline void btrfs_clear_treelog_bg(struct btrfs_block_group *bg) fs_info->treelog_bg = 0; spin_unlock(&fs_info->treelog_bg_lock); } - #endif From patchwork Wed Sep 8 16:19:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E1A2C433EF for ; Wed, 8 Sep 2021 16:19:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80D9360F5E for ; Wed, 8 Sep 2021 16:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348794AbhIHQUz (ORCPT ); Wed, 8 Sep 2021 12:20:55 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348619AbhIHQUx (ORCPT ); Wed, 8 Sep 2021 12:20:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117985; x=1662653985; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9rLJDhZcRbDxZ4ZZ3Nhb5Je0U7xsXUI1Qhde/gjgbnI=; b=LyHBwQPSIsRs09pGq7NVOHpLqupR4hDOf293LN/lc4ad+ECb9551j4zi y77/w7GLJunM7X+bft0loRGtH+Wuoedp5tEgbGGNGzxU1YhY6HJp9jJ23 S3a26865BIpwT4YYNftXpSInF9RGwckCMi61oiRE5KbrjDffotPtEXJVa tGOOb2eXGAIqQwfud7lru4xi1U4/ldesasABq6WQCIxJCfU8lpZeiMAMH jud+zipfjadkxDOMluN1TeyuHv7G7BGnNx8iMIxnQqobEdQrSMZsh/3ay HSySGOCgoEx4m/KjIniCrWsHFRk7y1N0LXsyUnXUlwH7dK2GSXPJyVMho g==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493940" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:45 +0800 IronPort-SDR: aEcSvgr6gN2g8lVDnseW+SriyASKJHu/hA//JMrGQp5enO1aQTk0b7oZ4GD4GBPWCLp4YxH98u HHsy+xZXeWGQuxFZo7Il0x63zx5UVyGgfb+wEaD0wCP7laKA15pwNkaNy/YQVXQn1Hk3R78SBF qfpy4/s9vmCcoBeZxipq9zTjCigXaYdPa49XDp2jAVZYt4ZkOxHkRstBm3fV4QWLKudLWCqFdZ 3urumj6cb3ZRVj79wialxoeCCwv4JObRfic/8Xv28AXigl1phk9gIIfiACJ59wf02OaMxPgIdN DdlcqP9BR0T50ewQpI4EAvf8 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:42 -0700 IronPort-SDR: +tBr+1TqKv3KbcTSUXVFVYV5zhfOTGBPQrVOtaXeW96dNpRB1krzncc18O+qcVC3SzvrbXuPsf G8qex+pY6dIW9t0EGwN33yGn2953fuXWwgp1qpkBdjVvy3k6AUUhYhoajspM3UqImf9rVu1UMv BAHL0RUKf0H7eBFtBKvxkBlONCtGK5LdayYZC7OeuuVIfV03joRJ4lhBfuYXJBhN3b9aBn6/sQ qpguwzi6kfHY9i+ezxeu0uSzoFAlCBAO2gPKcy7RvIILgek+y8tR0oewh68SRPQMZ21O3Vk1bV ZGc= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:46 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn Subject: [PATCH v2 3/8] btrfs: zoned: only allow one process to add pages to a relocation inode Date: Thu, 9 Sep 2021 01:19:27 +0900 Message-Id: <15fdddfffd14f3338f621ebd3210993ae7a55081.1631117101.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 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 --- fs/btrfs/extent_io.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 8959ac580f46..96ade32cad9b 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -5132,6 +5132,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 }, @@ -5139,7 +5142,11 @@ int extent_writepages(struct address_space *mapping, .sync_io = wbc->sync_mode == WB_SYNC_ALL, }; + 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 Wed Sep 8 16:19:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1B2AC433F5 for ; Wed, 8 Sep 2021 16:19:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5A2761154 for ; Wed, 8 Sep 2021 16:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349039AbhIHQU4 (ORCPT ); Wed, 8 Sep 2021 12:20:56 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349026AbhIHQUz (ORCPT ); Wed, 8 Sep 2021 12:20:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117986; x=1662653986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f5bnL7YNSud7hLrNgtGCkwrCrFlHG5rgQI9w0SAvSSw=; b=SH4WwZTByTNlynE5kZ5nwDQT0xumPaUB0GmboBYT+zIzgWKFb3ew4zXN toPsraoHK+NEcEVc35pfw2zAXfUaVhhNkWJCi1KQiXHi5LzyZIlsoocgc N7t7m4fPPtSmfC4HhJyuVqheMNV5PTrndDXii14+3oGDTZZvhQt/2qhGf P1dn3w1sqHYnXo5ET4z9yf1j1Y5+DTuZrjUlfM7U/KNYWYHqCQAEalTbc /EIvEfRtI3znIzasdSZDEg/kNuH20iLmfLV7kJuvzK+UAXHRA3ITBd0b0 YDoAVFHUjC0GsVgFItXeTTPTqt+FVQWtC/6TbiZw3wlL1ZNRv0c98wYPb w==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493941" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:46 +0800 IronPort-SDR: 8CuLlsbkIoIm/bKn0z9xZvCjBQiJLxR3vm/zyg/aNlR3NqtOc7QbYwLCvKMNhZmnmNUTYc/blS 75k7TZnMzKF4alJxI7+1ab+SuwWz/ndO7IuHf3HYAmvG6e5E8Isdut2ipOUKODGt3l2dRRh7ok jzaCOtQzQdW1Z0hyydeBXqBUDQ29UJ7YS5qg/pclnELAtIWTp97GH2N6YEijivFTLoUn8r52BQ n1hC4kWw1DHi6WpJjiIn23jzQ8HOXYvuCdIb600FM0pWsW7Op9Jv2gpw4gj0D7D4FEt5+VKmVx 9C7yp4y6/7EMF5cWFoUFNWfY Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:44 -0700 IronPort-SDR: h/VuA2cTK7UejJW4QRg/Tj7vaa0eZXuJvwiWAQN66L55iGaAxkXf2CqZSSkidl7hds7usbxKCZ h18SmnUDsU4W1G8sl6b/RDy9PTrF6h0gJXMr602jK8PrH+KtrFoeuZgZwW5njCJvHo0JgMQOFf jAfH+4ibsCPIta2Is0u3zYu5ou+kzpnQb3TIzHfc11nsO5oT158BGis5o1h4kvEdlKZ4jPYNNK So5LfADc6RgFRzZuwFKJxdu0Dscm817tVksEFPP6+W8aBHfJz2M2JVk/60zaoJdO7RadKJvDlR d0Y= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:47 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn , Naohiro Aota Subject: [PATCH v2 4/8] btrfs: zoned: use regular writes for relocation Date: Thu, 9 Sep 2021 01:19:28 +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 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. Signed-off-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/zoned.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index c7fe3e11e685..bfc3a48567a7 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1490,6 +1490,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 an own block-group from which only the + * relocation "process" can allocate and made sure only one process at a + * time can add pages to an extent that gets relocatied, 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 Wed Sep 8 16:19:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53E43C433F5 for ; Wed, 8 Sep 2021 16:19:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C5C461154 for ; Wed, 8 Sep 2021 16:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349188AbhIHQU6 (ORCPT ); Wed, 8 Sep 2021 12:20:58 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349026AbhIHQU5 (ORCPT ); Wed, 8 Sep 2021 12:20:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117989; x=1662653989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d5cX5u9vwWMMNdTUQn+OLlUtTFaftwzMlH81YJ6zSEE=; b=YZQAlRpfwQXVJ18pmUgexXjnDCWGLRSFWh5PZzKQiT/6pFaMmlTATIoA +S+LUU1sjlKxTVsRbI+/czEUjECDrkwbG037hSvEqW429JvieSktoM6nz 7P0lIYKE/LTXLvuv/m5IPe0JP5wSIXT+ywzjK28ECtqkgEK3XAfy1nZo5 yLfRCEA5DCFcE3eZ6sKUAdMj+HaBkaEKDDen3omhOmP1IFMI/RcDrYSVh zskhl44d7PLP9eAPKA+iC6lBZSJsMtjlv11U2S6UFQbpWfzgV6rkvZxab ux9qCKQWgeLabJiqNL7fv/aNLySJeqlus0GRVgBfBmK69j5BGFgJOkbO+ A==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493945" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:48 +0800 IronPort-SDR: aqGDc6jr4T18w2Qw9xEYbAC26cGIayFScJP+IMxB+PCGfTZqzVKRBSkmCblckpHQ7vZ5GZ99Jh jR1FG4QYUwSl9eRu0bSkCy4M5zzOAEl0n1JMWYs251eD5Tizla/mcI01KBha1Yb07ZG4cgngHh cZs8iymKAnhh0LxoOnYWtcN6yLH4dP4IvsneB7x/Qs/NHhkuCx3T5wYc307cJqifpWkD7lKt/d Qi5uHLUGWhezV3F/5yzgeyw1y+u8X9+UGHEP1I5clxPVmidBf6QmExVT5E2LJjgxg/0kIBbboh AwcE2of49OJKUqJWlkNXpmNw Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:45 -0700 IronPort-SDR: NzdMupWaXDmNzqq/V3Q80eREymtVDEmdt/tlvlN8A+6swNN4xRTxYyrlsPNFNTd6ZCj/W7BxLT WH+zJVwr9UQTN5G6dtnaGlIOeD18uK/VIROp3+powsiacNAn09Oxiu5tzMZDB3yAtVTiKOQQTR tXkocEaHZOFN+rdE3/iL+Yj8dQEErGKaZ4Hoc8TyvMtuCzJF0GinydeMpj2A2xbuTC5IGNVNr0 4NjsyHlI0seu3/avnhjQFswsOPlqw4j/HIEb1jpQENKc+tMYCCnUdUaVYskv0Pb6mg2rsTjEvh g1o= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:48 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn , Naohiro Aota Subject: [PATCH v2 5/8] btrfs: check for relocation inodes on zoned btrfs in should_nocow Date: Thu, 9 Sep 2021 01:19:29 +0900 Message-Id: <9facc2896434f78cd72f5147948db55786bf1150.1631117101.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 Prepare for allowing preallocation for relocation inodes. Signed-off-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- 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 e89e16a9c56c..4eb64753382c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1944,7 +1944,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 FS 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 Wed Sep 8 16:19:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48CB0C433FE for ; Wed, 8 Sep 2021 16:19:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30C506115B for ; Wed, 8 Sep 2021 16:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349239AbhIHQU7 (ORCPT ); Wed, 8 Sep 2021 12:20:59 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349076AbhIHQU6 (ORCPT ); Wed, 8 Sep 2021 12:20:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117989; x=1662653989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wLfeO5bWCLkRRy8IvRP5oFdgttxSgpU6ArkEPp/BnLI=; b=M3IUbbJ6i5yDv4RZWNhSFBu92N6nePFD9R+GQlDlwnHy9kady5gl6fkr NrDzNAOxKosiDKa5WZ8j4mq2hLkDhbjN1zTbyvZbtEfE5XhPlC+1Fm0WH FSR7h9be4ObJS+zyIWyN/U5Gvi1MFdSz5aNQrubYbj/R7mGObvGAE6jdi +DGlSTHgLirIW6jeqLRL1aDgc+Cdlu07kJS0LAGk0ovFgBq+628P7LVUg c+DVJei0pf9uuKRl9WkiNLqth+g6LBwIOgnaKLtMw/DOHd8o0w2Ch91Cy e4R60YC8awFln8kVlObg4RRHvXwHUgch/lC9+RPJ79OWpsD9mcqI/LE/D Q==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493949" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:49 +0800 IronPort-SDR: ntOVoq+Vx9WLcmZr69im0RkPSmmpgg27BEKvOWYBFxc82J35Rp/7gH2aupL1K6eQqBWJgwxxdM zujWr+1dhW9bZnuFjX1Hv6Lj5ED05crDohct8/VBR4cn7F2ggleLHraBCrNX/ZkGKDlWJABzSn kBCUo8Ex/jU2ShTRg86ZB3XWJmrsMDz7FO/YXE7QfAldVmHkC9WaAH9c5sb7jzoGVkG+qEVO3U CmYugU12KNvhqo1k5dBBy498bc1srVdNO1M6p/GRYeLCQ3wJTsZh7LEq7nAHLiBMCEGO9ZhU7n u4YajV1vYx4cq6UFoqokQKoi Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:47 -0700 IronPort-SDR: tLueVy95m4Fb4vMK2yBHIUA3UWpxPolpCyIfExjvcj1bcUqYCcEzjE9oAmjkaaHgAoe9s9XFKL E0J4DkJvawHaUsN07sHlb9iH1z2pe8tiIPc1p8WJhvOuhQjB+ZL4IQIRlISMtp7ivtPJMLl/Ro 0ML1rYTka2Ddg0HfohgYYieDPpUrFj5Bgat2feAHKo0OcTrF4Z/VXDcRW457H+CVhiUOy5Or/R zxsikINraaI8tPYg4ktt82fds9lP8cbJYzqaZ6sXlty156ftguszfWvjCWVIC1WO+MGuny9r78 DSI= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:50 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn Subject: [PATCH v2 6/8] btrfs: zoned: allow preallocation for relocation inodes Date: Thu, 9 Sep 2021 01:19:30 +0900 Message-Id: <7610c58a491c87e444f359988cde477783197730.1631117101.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 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 regular btrfs does as well. Essentially this reverts commit 32430c614844 ("btrfs: zoned: enable relocation on a zoned filesystem") as it is not needed anymore. 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 3c9c0aab7fc3..6f668bc01cd1 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2853,31 +2853,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; @@ -3085,7 +3060,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; @@ -3115,8 +3089,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: @@ -3771,12 +3743,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; @@ -3791,7 +3759,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); From patchwork Wed Sep 8 16:19:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96A68C433F5 for ; Wed, 8 Sep 2021 16:19:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AF8F61158 for ; Wed, 8 Sep 2021 16:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349283AbhIHQVA (ORCPT ); Wed, 8 Sep 2021 12:21:00 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349216AbhIHQU7 (ORCPT ); Wed, 8 Sep 2021 12:20:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117991; x=1662653991; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+Ohw8+ybSIjVsjs5LzNsaXBrxLTuHbJ9sIJFja805HI=; b=mJ0qPmYNbs877/7nWX2UZg8mSlgiY4/rLgVw0AjBToDW7yRQ0IdIZsmr EzILKk5ra4Rz97ekITsHRGt+ZqgR91z8tEH7wx5PBj92iYSSnmiH7/4Fh D1G+0VvTWDceLdMRar18hLXlp3Q7ehuDJgL2Dc584XDU78tfrfu7ZtuG7 enXtBA6uoosHHkON2lw9iYfRUMOVHyfHP/lx/TbjNP4Pu6ChqJaVPsVum kk7jI5YH6WUo8FS1tTd3VLp0HbhqEsOATLG5SmiuuUAodsMFS4F9o2Gq8 fbP5kS5NGaXFO38ZrL+P6VJj/207riNlhNq/kz9ZzYqW8B3d5rq+kiPFY Q==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493950" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:50 +0800 IronPort-SDR: 5R2wNYTffDQGQaHZaS/2K0iVD9+bJ2RQ1wnvFiD9qxyGhxW9dwYzHHGJrYrZRep8sIQeE1ECeP rMTuY8C2o101if0kQTUPQrXfSoQGjwQIho5+TPd3kL88LhgwIcK+Ei0KCcW2hmla0OayEKDU9r zWGUum9q1KNpQYb8JitT6ulLSXRPBisix6dwI7BNI5yMTQLDb6RFg3T/sVGUTQ/FxrcBdrK3L3 8wErq1HEztgPzA98Dk58ds72OBhA2tNVPx4tHa5sHeWN51cFW6e8d2GeCl6xA8rFRepAIZ+vjw Xdfi5xcrLhpOqoRCnVpU0HjZ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:48 -0700 IronPort-SDR: Mbh3OstPmfJ6A9kjTN8K9cmyr4+V9bexrTLypD5LtJzdOCyzUGfx2Ax4McaNuIP6neWK4JoLTQ U9taTlP7C8H/BxS+YB1ZlJ6sjcWnvK8jS9gaNqQootHLRtsG4U7g0s2V4z5wjDxpKwmIuSauuj mBUA7gtkBtGvB0sAqDboniC+iG5GOj4Z1iJ5k6DeI5tzp3jUNSDON60fYkzyVtg3KA56QZfFFh gFywf31yvkGoWTSgO6MLfjAKeqTfMAnoPaJXqeq5n+RuHLCrvpEX34nnWTJ1/IIy4ThhClLf4t J7I= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:51 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn Subject: [PATCH v2 7/8] btrfs: rename setup_extent_mapping in relocation code Date: Thu, 9 Sep 2021 01:19:31 +0900 Message-Id: <564a5ffba7fd303ee5d6330dbb36326fbfb1981d.1631117101.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 In btrfs we have two functions called setup_extent_mapping, one in the extent_map code and one in the relocation code. While both are private to their respective implementation, this can still be confusing for the reader. So rename the version in relocation.c to setup_relocation_extent_mapping. No functional change otherwise. Signed-off-by: Johannes Thumshirn --- fs/btrfs/relocation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 6f668bc01cd1..bf93e11b6d4e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2880,8 +2880,8 @@ static noinline_for_stack int prealloc_file_extent_cluster( } static noinline_for_stack -int setup_extent_mapping(struct inode *inode, u64 start, u64 end, - u64 block_start) +int setup_relocation_extent_mapping(struct inode *inode, u64 start, u64 end, + u64 block_start) { struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; struct extent_map *em; @@ -3080,7 +3080,7 @@ static int relocate_file_extent_cluster(struct inode *inode, file_ra_state_init(ra, inode->i_mapping); - ret = setup_extent_mapping(inode, cluster->start - offset, + ret = setup_relocation_extent_mapping(inode, cluster->start - offset, cluster->end - offset, cluster->start); if (ret) goto out; From patchwork Wed Sep 8 16:19:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12481517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 831FAC433FE for ; Wed, 8 Sep 2021 16:19:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C20160F5E for ; Wed, 8 Sep 2021 16:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349298AbhIHQVC (ORCPT ); Wed, 8 Sep 2021 12:21:02 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:3327 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349076AbhIHQVA (ORCPT ); Wed, 8 Sep 2021 12:21:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1631117992; x=1662653992; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+cft4bI0eM90VfULfvmQ+jRCnOmlZuKmxc8x3bJP46E=; b=TSzd2ITGZ5cwPGegGNym+qdizt4X1BIOd/67iBw6kT/jVw4cVN7xRRn/ UD3lHpgwqqr8p4gjWF0tuAS3/LfzTWqOiS8IQs3uDJ1GIl8ePfOFPbHWx b6y4T+eRv1BKshdWt76bPT9sRF4Td6pioy7684bC1+FhwUcMujgUsKULQ 2P6dqywHPnW9/wSZ3yLNIRK9FX06neYLz9+BeexkQHpQn2SF2qlZJe/1y Hl/wcr1RjcpN2mxWaLUkL0wVuEgbDftdFR1oRMMuathrBpvRXm6oOdk5w aOsbVUqqFUhjNoWUw3aDnkeG3+Ti0HjiuBGL649X7G+OUDy0/d14J0s7H Q==; X-IronPort-AV: E=Sophos;i="5.85,278,1624291200"; d="scan'208";a="179493954" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Sep 2021 00:19:52 +0800 IronPort-SDR: C+DstAMeYIL6u9mHUJVMzWbBgyjC30kbBxKYun4lroN84OeeItvFu72QcUoPEZX8lR8NYm4tAE vKR/5BcBY7CvCKZDzNJgwQjfuhQVQrD02pw07MxK4DbXwpTZTlYCLXxaix2ICfmnxgeP31JmsC XNhkYAkhp8Rsz2JB/JWC1SmwBkeu3O/zjpWn21T3Ln3GpFNG/d27K2ly9gDuOXTc4cf5qohNE/ yk17tHhzlHbzJw3IChH/XM6Ko1DMvfsmCP3aYt6GqolAQl1nUD0zQ65LKAmywiaaQ780te1QOT jFcBd91C9OiKLi+4kFq8mmSp Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2021 08:54:49 -0700 IronPort-SDR: KceCkPUJrKUMq2OzFIajylS6nPtPsNZobzspn3UFSFKai+aA1HQtsFWwuqjJhUqIcXk3Id/ybK 75qbrMOauO0F/TYCxemYNyLNjoo0hwKD1hxOoS5LD43EHl5D8r3IK5h2KFx+o2vFc8TOIUru4o T1QE1abUCyyKX6bpY4jxpEJijzha/HzUFioSurGU9R8V3VVrl56Sd+TXlPvRK95V4PXZrixmNu ujXaJ2ojH2NqLVMwjDoAbULai4Hdkoc7CZUGKLRI1l6FfPS7E3u4/1MpsYqg/ZfK8UG3efkV9i sr0= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Sep 2021 09:19:52 -0700 From: Johannes Thumshirn To: David Sterba , linux-btrfs@vger.kernel.org, Damien Le Moal , Naohiro Aota , Filipe Manana Cc: Johannes Thumshirn Subject: [PATCH v2 8/8] btrfs: zoned: let the for_treelog test in the allocator stand out Date: Thu, 9 Sep 2021 01:19:32 +0900 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The statement which decides if an extent allocation on a zoned device is for the dedicated tree-log block-group or not and if we can use the block group we picked for this allocation is not easy to read but an important part of the allocator. Rewrite into an if condition instead of a plain boolean test to make it stand out more, like the version which tests for the dedicated data-relocation block-group. Signed-off-by: Johannes Thumshirn --- fs/btrfs/extent-tree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 708dc6492f97..77ad7bd3b22e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3763,7 +3763,7 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, u64 log_bytenr; u64 data_reloc_bytenr; int ret = 0; - bool skip; + bool skip = false; ASSERT(btrfs_is_zoned(block_group->fs_info)); @@ -3773,8 +3773,9 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group, */ spin_lock(&fs_info->treelog_bg_lock); log_bytenr = fs_info->treelog_bg; - skip = log_bytenr && ((ffe_ctl->for_treelog && bytenr != log_bytenr) || - (!ffe_ctl->for_treelog && bytenr == log_bytenr)); + if (log_bytenr && ((ffe_ctl->for_treelog && bytenr != log_bytenr) || + (!ffe_ctl->for_treelog && bytenr == log_bytenr))) + skip = true; spin_unlock(&fs_info->treelog_bg_lock); if (skip) return 1;