From patchwork Mon May 29 15:16:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94ED5C77B7E for ; Mon, 29 May 2023 15:17:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjE2PRU (ORCPT ); Mon, 29 May 2023 11:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjE2PRT (ORCPT ); Mon, 29 May 2023 11:17:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F4C6D2 for ; Mon, 29 May 2023 08:17:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C0D1B615AF for ; Mon, 29 May 2023 15:17:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB2AEC4339B for ; Mon, 29 May 2023 15:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373436; bh=yGb8OjbPUpDhSLmvBc5AXMP8rXaZkr71y2VjNte5kPw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PsukSgwnn9B8Tya8zkGimsjjxdqLilMoMdVZXs7SPhhC2OLpGmVK6q4yaWpGwaQfF sxQdl+V7dMAo39q6ELW8prpXLi5eNaJnZSywNx5s7pEU0mVS6etiVzt3ryCb+D3d7A EMRbavVvGtpxrBGAjtlFTPffJwW5SatJYXZj6Jsj5++/qNIEmBl0KV7ifQMMta645X 0da4BZWUzcwcnALk50hzFioV0xKWWyn4eij5ew0rXdFgXMfOjt3xveKYuJKnu/1+UW OsB6itkUolOWjmK+wXAbnedg8dCkE8m7TECfM/cwGISAlbK+A7odd1dRfKy498CoDy /lhIetjUvtQrg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 01/11] btrfs: reorder some members of struct btrfs_delayed_ref_head Date: Mon, 29 May 2023 16:16:57 +0100 Message-Id: <5c8b43665ff7b486b68ff35616b53f8357876245.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Currently struct delayed_ref_head has its 'bytenr' and 'href_node' members in different cache lines (even on a release, non-debug, kernel). This is not optimal because when iterating the red black tree of delayed ref heads for inserting a new delayed ref head (htree_insert()) we have to pull in 2 cache lines of delayed ref heads we find in a patch, one for the tree node (struct rb_node) and another one for the 'bytenr' field. The same applies when searching for an existing delayed ref head (find_ref_head()). On a release (non-debug) kernel, the structure also has two 4 bytes holes, which makes it 8 bytes longer than necessary. Its current layout is the following: struct btrfs_delayed_ref_head { u64 bytenr; /* 0 8 */ u64 num_bytes; /* 8 8 */ refcount_t refs; /* 16 4 */ /* XXX 4 bytes hole, try to pack */ struct mutex mutex; /* 24 32 */ spinlock_t lock; /* 56 4 */ /* XXX 4 bytes hole, try to pack */ /* --- cacheline 1 boundary (64 bytes) --- */ struct rb_root_cached ref_tree; /* 64 16 */ struct list_head ref_add_list; /* 80 16 */ struct rb_node href_node __attribute__((__aligned__(8))); /* 96 24 */ struct btrfs_delayed_extent_op * extent_op; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ int total_ref_mod; /* 128 4 */ int ref_mod; /* 132 4 */ unsigned int must_insert_reserved:1; /* 136: 0 4 */ unsigned int is_data:1; /* 136: 1 4 */ unsigned int is_system:1; /* 136: 2 4 */ unsigned int processing:1; /* 136: 3 4 */ /* size: 144, cachelines: 3, members: 15 */ /* sum members: 128, holes: 2, sum holes: 8 */ /* sum bitfield members: 4 bits (0 bytes) */ /* padding: 4 */ /* bit_padding: 28 bits */ /* forced alignments: 1 */ /* last cacheline: 16 bytes */ } __attribute__((__aligned__(8))); This change reorders the 'href_node' and 'refs' members so that we have the 'href_node' in the same cache line as the 'bytenr' field, while also eliminating the two holes and reducing the structure size from 144 bytes down to 136 bytes, so we can now have 30 ref heads per 4K page (on x86_64) instead of 28. The new structure layout after this change is now: struct btrfs_delayed_ref_head { u64 bytenr; /* 0 8 */ u64 num_bytes; /* 8 8 */ struct rb_node href_node __attribute__((__aligned__(8))); /* 16 24 */ struct mutex mutex; /* 40 32 */ /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */ refcount_t refs; /* 72 4 */ spinlock_t lock; /* 76 4 */ struct rb_root_cached ref_tree; /* 80 16 */ struct list_head ref_add_list; /* 96 16 */ struct btrfs_delayed_extent_op * extent_op; /* 112 8 */ int total_ref_mod; /* 120 4 */ int ref_mod; /* 124 4 */ /* --- cacheline 2 boundary (128 bytes) --- */ unsigned int must_insert_reserved:1; /* 128: 0 4 */ unsigned int is_data:1; /* 128: 1 4 */ unsigned int is_system:1; /* 128: 2 4 */ unsigned int processing:1; /* 128: 3 4 */ /* size: 136, cachelines: 3, members: 15 */ /* padding: 4 */ /* bit_padding: 28 bits */ /* forced alignments: 1 */ /* last cacheline: 8 bytes */ } __attribute__((__aligned__(8))); Running the following fs_mark test shows some significant improvment. $ cat test.sh #!/bin/bash # 15G null block device DEV=/dev/nullb0 MNT=/mnt/nullb0 FILES=100000 THREADS=$(nproc --all) FILE_SIZE=0 echo "performance" | \ tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor mkfs.btrfs -f $DEV mount -o ssd $DEV $MNT OPTS="-S 0 -L 5 -n $FILES -s $FILE_SIZE -t $THREADS -k" for ((i = 1; i <= $THREADS; i++)); do OPTS="$OPTS -d $MNT/d$i" done fs_mark $OPTS umount $MNT Before this change: FSUse% Count Size Files/sec App Overhead 10 1200000 0 112631.3 11928055 16 2400000 0 189943.8 12140777 23 3600000 0 150719.2 13178480 50 4800000 0 99137.3 12504293 53 6000000 0 111733.9 12670836 Total files/sec: 664165.5 After this change: FSUse% Count Size Files/sec App Overhead 10 1200000 0 148589.5 11565889 16 2400000 0 227743.8 11561596 23 3600000 0 191590.5 12550755 30 4800000 0 179812.3 12629610 53 6000000 0 92471.4 12352383 Total files/sec: 840207.5 Measuring the execution times of htree_insert(), in nanoseconds, during those fs_mark runs: Before this change: Range: 0.000 - 940647.000; Mean: 619.733; Median: 548.000; Stddev: 1834.231 Percentiles: 90th: 980.000; 95th: 1208.000; 99th: 2090.000 0.000 - 6.384: 257 | 6.384 - 26.259: 977 | 26.259 - 99.635: 4963 | 99.635 - 370.526: 136800 ############# 370.526 - 1370.603: 566110 ##################################################### 1370.603 - 5062.704: 24945 ## 5062.704 - 18693.248: 944 | 18693.248 - 69014.670: 211 | 69014.670 - 254791.959: 30 | 254791.959 - 940647.000: 4 | After this change: Range: 0.000 - 299200.000; Mean: 587.754; Median: 542.000; Stddev: 1030.422 Percentiles: 90th: 918.000; 95th: 1113.000; 99th: 1987.000 0.000 - 5.585: 163 | 5.585 - 20.678: 452 | 20.678 - 70.369: 1806 | 70.369 - 233.965: 26268 #### 233.965 - 772.564: 333519 ##################################################### 772.564 - 2545.771: 91820 ############### 2545.771 - 8383.615: 2238 | 8383.615 - 27603.280: 170 | 27603.280 - 90879.297: 68 | 90879.297 - 299200.000: 12 | Mean, percentiles, maximum times are all better, as well as a lower standard deviation. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index b54261fe509b..9b28e800a604 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -70,20 +70,26 @@ struct btrfs_delayed_extent_op { struct btrfs_delayed_ref_head { u64 bytenr; u64 num_bytes; - refcount_t refs; + /* + * For insertion into struct btrfs_delayed_ref_root::href_root. + * Keep it in the same cache line as 'bytenr' for more efficient + * searches in the rbtree. + */ + struct rb_node href_node; /* * the mutex is held while running the refs, and it is also * held when checking the sum of reference modifications. */ struct mutex mutex; + refcount_t refs; + + /* Protects 'ref_tree' and 'ref_add_list'. */ spinlock_t lock; struct rb_root_cached ref_tree; /* accumulate add BTRFS_ADD_DELAYED_REF nodes to this ref_add_list. */ struct list_head ref_add_list; - struct rb_node href_node; - struct btrfs_delayed_extent_op *extent_op; /* From patchwork Mon May 29 15:16:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21F1DC7EE29 for ; Mon, 29 May 2023 15:17:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjE2PRU (ORCPT ); Mon, 29 May 2023 11:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjE2PRT (ORCPT ); Mon, 29 May 2023 11:17:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29CB1C4 for ; Mon, 29 May 2023 08:17:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B55B460B28 for ; Mon, 29 May 2023 15:17:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E685C433D2 for ; Mon, 29 May 2023 15:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373437; bh=H9vUovm2qM2PAxTNd2pifilI43wuvFqPwQSE/44Necs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uT7XTKVlPHifNtwjtSHvrr+jN6CqKzCggRJMN3KrS0bgGVXhWtJrFbixS+OS0a3Zg Ap3PP/ooN9DvcZjPgxk8Vyb7yLnhirCeHyM4agKXng0K+LeVESL2/3nFS25jQ0VmoN DxaVbUghp3G/BBLEmQNgE7xNjKAChNXKCq1gtqbQZUzEYsTPF5fKG0Y1CYGeDn9tVu iPgWJo43lKNvAkWCbAwifV8pGvPkNcNsAMNUS1jCTw3YjHLlDwZvG1gC2awEw0+UDb geUcxmD5mcWw58a/uucneaO8y8zwjd0NOesvkRLG7yDqlKnf0WJpObAxL66Mjb3CYE 3yl/XhQDix2ZQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/11] btrfs: remove unused is_head field from struct btrfs_delayed_ref_node Date: Mon, 29 May 2023 16:16:58 +0100 Message-Id: <4221611ef72c981c934c2328ae01f8aa47622df2.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana The 'is_head' field of struct btrfs_delayed_ref_node is no longer after commit d278850eff30 ("btrfs: remove delayed_ref_node from ref_head"), so remove it. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 1 - fs/btrfs/delayed-ref.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 0b32432d7d56..be1d18ec5cef 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -853,7 +853,6 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info, ref->num_bytes = num_bytes; ref->ref_mod = 1; ref->action = action; - ref->is_head = 0; ref->in_tree = 1; ref->seq = seq; ref->type = ref_type; diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 9b28e800a604..77b3e735772d 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -48,8 +48,6 @@ struct btrfs_delayed_ref_node { unsigned int action:8; unsigned int type:8; - /* is this node still in the rbtree? */ - unsigned int is_head:1; unsigned int in_tree:1; }; From patchwork Mon May 29 15:16:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F62EC7EE29 for ; Mon, 29 May 2023 15:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbjE2PRV (ORCPT ); Mon, 29 May 2023 11:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjE2PRU (ORCPT ); Mon, 29 May 2023 11:17:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F2E4C9 for ; Mon, 29 May 2023 08:17:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A491C615DD for ; Mon, 29 May 2023 15:17:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 917A5C433EF for ; Mon, 29 May 2023 15:17:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373438; bh=GnM9+H8HNqWtwUPyvqjLvbhwrnnY5k50Jv246I/XFiQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sOrFljfiKN1HI4uYbC/b6s4jSrSCsWm7yWV0Mn5a0tohznB5tHLCXrH8c69az0DQd NZ2ovA08JjcTMCXS5JxFj3MhBESW+6h0YE2RKakaPjfnlHqog/G4cA/xk5Up099ZFE 0Jhm5vOm7Rz3FvGfwrnXFPk/F1XPsa3AF79lOJdxB/5jm6m2SdE39nBrLRKOS8+rN0 nMy21oN+jF2WS/IyYffcMtxo3Cro3RaLsTp1o+gmGhBHjo2lfv4nOXefS4pSvzVC4i 8oosz7Mu3YM2ick/9mSGazwrPdv/hk858P2oiGzpbQCKfXQZcbJi2RUDByb01vDMYe 2pH3rt+ZlUPqw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 03/11] btrfs: remove pointless in_tree field from struct btrfs_delayed_ref_node Date: Mon, 29 May 2023 16:16:59 +0100 Message-Id: <18656b6d56a9813f52f3594637ab3acb31e129ba.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana The 'in_tree' field is really not needed in struct btrfs_delayed_ref_node, as we can check whether a reference is in the tree or not simply by checking its red black tree node member with RB_EMPTY_NODE(), as when we remove it from the tree we always call RB_CLEAR_NODE(). So remove that field and use RB_EMPTY_NODE(). Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 2 -- fs/btrfs/delayed-ref.h | 3 +-- fs/btrfs/disk-io.c | 1 - fs/btrfs/extent-tree.c | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index be1d18ec5cef..d6dce5792c0f 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -407,7 +407,6 @@ static inline void drop_delayed_ref(struct btrfs_delayed_ref_root *delayed_refs, RB_CLEAR_NODE(&ref->ref_node); if (!list_empty(&ref->add_list)) list_del(&ref->add_list); - ref->in_tree = 0; btrfs_put_delayed_ref(ref); atomic_dec(&delayed_refs->num_entries); } @@ -853,7 +852,6 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info, ref->num_bytes = num_bytes; ref->ref_mod = 1; ref->action = action; - ref->in_tree = 1; ref->seq = seq; ref->type = ref_type; RB_CLEAR_NODE(&ref->ref_node); diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 77b3e735772d..9b103bf27185 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -48,7 +48,6 @@ struct btrfs_delayed_ref_node { unsigned int action:8; unsigned int type:8; - unsigned int in_tree:1; }; struct btrfs_delayed_extent_op { @@ -341,7 +340,7 @@ static inline void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref) { WARN_ON(refcount_read(&ref->refs) == 0); if (refcount_dec_and_test(&ref->refs)) { - WARN_ON(ref->in_tree); + WARN_ON(!RB_EMPTY_NODE(&ref->ref_node)); switch (ref->type) { case BTRFS_TREE_BLOCK_REF_KEY: case BTRFS_SHARED_BLOCK_REF_KEY: diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 96f144094af6..793f7e48d62e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4849,7 +4849,6 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, while ((n = rb_first_cached(&head->ref_tree)) != NULL) { ref = rb_entry(n, struct btrfs_delayed_ref_node, ref_node); - ref->in_tree = 0; rb_erase_cached(&ref->ref_node, &head->ref_tree); RB_CLEAR_NODE(&ref->ref_node); if (!list_empty(&ref->add_list)) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 4f7ac5a5d29e..0aa775ac31e4 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1913,7 +1913,6 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, return -EAGAIN; } - ref->in_tree = 0; rb_erase_cached(&ref->ref_node, &locked_ref->ref_tree); RB_CLEAR_NODE(&ref->ref_node); if (!list_empty(&ref->add_list)) From patchwork Mon May 29 15:17:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258706 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 365B8C77B7E for ; Mon, 29 May 2023 15:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjE2PRV (ORCPT ); Mon, 29 May 2023 11:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjE2PRU (ORCPT ); Mon, 29 May 2023 11:17:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9F29C4 for ; Mon, 29 May 2023 08:17:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9AFAE615E4 for ; Mon, 29 May 2023 15:17:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85430C433D2 for ; Mon, 29 May 2023 15:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373439; bh=Dz36yvl1tm3i9aECWZ6I08lfiEyDbY+/qeaZccw5gYA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dXI+t4qPz3KH7wGKt3CTSBmnq6UzmagJi4qs1WUSAMORgufEn3Qjofa2neMET65DR 7Igyt637GxfXiZj4w5DYhEnniY8FfHbizOHiOfNSdjExLuJf0dUGiYlX8hosnKDb05 8uo1tNpJ+lWoYZyfxGN2YKTO/Y8sz8sUIMSLo8JwsiFB5Br/GyxoFVT7HsyNXvzYI6 9a35i9+DZFg5dzcpiJCOwPXc7hbE5IuQyNKyCWUQtybfXDHRr8MZXt0+75lkPmQd6f pJWH8xtgbskJc6YAZa+2+GKp9rkg+kre9eX/RKlCCHT5UBiIw07qVGIdw3qqR5ubq9 pqmcjP2NWTRiA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 04/11] btrfs: use a bool to track qgroup record insertion when adding ref head Date: Mon, 29 May 2023 16:17:00 +0100 Message-Id: <351306fd0efd24357c011e8d3d080953f9d63898.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana We are using an integer as a boolean to track the qgroup record insertion status when adding a delayed reference head. Since all we need is a boolean, switch the type from int to bool to make it more obvious. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index d6dce5792c0f..0bcec428766c 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -762,11 +762,11 @@ static noinline struct btrfs_delayed_ref_head * add_delayed_ref_head(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_head *head_ref, struct btrfs_qgroup_extent_record *qrecord, - int action, int *qrecord_inserted_ret) + int action, bool *qrecord_inserted_ret) { struct btrfs_delayed_ref_head *existing; struct btrfs_delayed_ref_root *delayed_refs; - int qrecord_inserted = 0; + bool qrecord_inserted = false; delayed_refs = &trans->transaction->delayed_refs; @@ -776,7 +776,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, delayed_refs, qrecord)) kfree(qrecord); else - qrecord_inserted = 1; + qrecord_inserted = true; } trace_add_delayed_ref_head(trans->fs_info, head_ref, action); @@ -872,7 +872,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_head *head_ref; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_qgroup_extent_record *record = NULL; - int qrecord_inserted; + bool qrecord_inserted; bool is_system; int action = generic_ref->action; int level = generic_ref->tree_ref.level; @@ -965,7 +965,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_head *head_ref; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_qgroup_extent_record *record = NULL; - int qrecord_inserted; + bool qrecord_inserted; int action = generic_ref->action; int ret; u64 bytenr = generic_ref->bytenr; From patchwork Mon May 29 15:17:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1027AC7EE2E for ; Mon, 29 May 2023 15:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229715AbjE2PRg (ORCPT ); Mon, 29 May 2023 11:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbjE2PRW (ORCPT ); Mon, 29 May 2023 11:17:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF5CC9 for ; Mon, 29 May 2023 08:17:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8F3FC615DD for ; Mon, 29 May 2023 15:17:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79342C4339B for ; Mon, 29 May 2023 15:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373440; bh=liZg0k6dA9xK9FgwVhiFcWh0ae7z5w7Slls3N/dBNRk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cxWNnT/qsf+0g5kiEY05uz1BvD/STtzPmQFP+FLS9zFg6EBCj5UWhA1DCPKe/FXJw BBsi5AVjDrVPvzHSyhhs9GjVfg11EbV+G5Yv6aHQwjEAbtK4Mo4g0MGdZZGLPStnxq OS7/JxlPeq93WqY1BrKDfMohZTB5jydKVYs0rgvgn24ZZJE2zWOHOc41xJFenaKTIZ 8D33eXQ+NmaXvtlXgJiajy9UmXB4DpLHkidSsWZv96/jGKToQ8PAV1KONeytxbFr0o WjnK9QjF4vq0QRnQyh0bopVPCfIULl0J4hiSe51xgNSPMfzIevsckpbXKBGIvDCjRF 2ZvjXur2KI45Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 05/11] btrfs: make insert_delayed_ref() return a bool instead of an int Date: Mon, 29 May 2023 16:17:01 +0100 Message-Id: <3913b547b4fb8c1c99cc69e8e489d076c494a49c.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana insert_delayed_ref() can only return 0 or 1, to indicate if the given delayed reference was added to the head reference or if it was merged into an existing delayed ref, respectively. So just make it return a boolean instead. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 0bcec428766c..c3da7c3185de 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -555,16 +555,17 @@ void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, /* * Helper to insert the ref_node to the tail or merge with tail. * - * Return 0 for insert. - * Return >0 for merge. + * Return false if the ref was inserted. + * Return true if the ref was merged into an existing one (and therefore can be + * freed by the caller). */ -static int insert_delayed_ref(struct btrfs_delayed_ref_root *root, - struct btrfs_delayed_ref_head *href, - struct btrfs_delayed_ref_node *ref) +static bool insert_delayed_ref(struct btrfs_delayed_ref_root *root, + struct btrfs_delayed_ref_head *href, + struct btrfs_delayed_ref_node *ref) { struct btrfs_delayed_ref_node *exist; int mod; - int ret = 0; + bool ret = false; spin_lock(&href->lock); exist = tree_insert(&href->ref_tree, ref); @@ -572,7 +573,7 @@ static int insert_delayed_ref(struct btrfs_delayed_ref_root *root, goto inserted; /* Now we are sure we can merge */ - ret = 1; + ret = true; if (exist->action == ref->action) { mod = ref->ref_mod; } else { @@ -874,9 +875,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, struct btrfs_qgroup_extent_record *record = NULL; bool qrecord_inserted; bool is_system; + bool merged; int action = generic_ref->action; int level = generic_ref->tree_ref.level; - int ret; u64 bytenr = generic_ref->bytenr; u64 num_bytes = generic_ref->len; u64 parent = generic_ref->parent; @@ -932,7 +933,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, head_ref = add_delayed_ref_head(trans, head_ref, record, action, &qrecord_inserted); - ret = insert_delayed_ref(delayed_refs, head_ref, &ref->node); + merged = insert_delayed_ref(delayed_refs, head_ref, &ref->node); spin_unlock(&delayed_refs->lock); /* @@ -944,7 +945,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, trace_add_delayed_tree_ref(fs_info, &ref->node, ref, action == BTRFS_ADD_DELAYED_EXTENT ? BTRFS_ADD_DELAYED_REF : action); - if (ret > 0) + if (merged) kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); if (qrecord_inserted) @@ -967,7 +968,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, struct btrfs_qgroup_extent_record *record = NULL; bool qrecord_inserted; int action = generic_ref->action; - int ret; + bool merged; u64 bytenr = generic_ref->bytenr; u64 num_bytes = generic_ref->len; u64 parent = generic_ref->parent; @@ -1024,7 +1025,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, head_ref = add_delayed_ref_head(trans, head_ref, record, action, &qrecord_inserted); - ret = insert_delayed_ref(delayed_refs, head_ref, &ref->node); + merged = insert_delayed_ref(delayed_refs, head_ref, &ref->node); spin_unlock(&delayed_refs->lock); /* @@ -1036,7 +1037,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, trace_add_delayed_data_ref(trans->fs_info, &ref->node, ref, action == BTRFS_ADD_DELAYED_EXTENT ? BTRFS_ADD_DELAYED_REF : action); - if (ret > 0) + if (merged) kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); From patchwork Mon May 29 15:17:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85461C7EE2F for ; Mon, 29 May 2023 15:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbjE2PRh (ORCPT ); Mon, 29 May 2023 11:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjE2PRW (ORCPT ); Mon, 29 May 2023 11:17:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A064FC4 for ; Mon, 29 May 2023 08:17:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 80450615AF for ; Mon, 29 May 2023 15:17:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D314C433EF for ; Mon, 29 May 2023 15:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373440; bh=pz2MAxyOZ3d+9a0F8cJTuIQmhVZjESvuXajfhu55W6k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=A01Xrcuiux1HKDTcWZgL6cPCG4+aguRxpF3ExtQIxNbB4PB9sJ38+ms6csYvlbZIX pK4I/P8MqbfMP3HfVVf4no9DJIfbzGPQGo8B79v/dgjV4lNAgmDvbPGr7HYxDgH9nk V2dBOMRE8nBXn0DrYWX1l7X6s6U0VjfhegXw8lfhn90utdtNgPY7B+I2QV90wyCLLw w4vOSzOirHl8k3zxE+gTBnoa2XrO96kc51KiK9bfHilXs1usFq95rzGoqQ0bNWcYEM gSdx9u4l+c0PlLVLjDBeT3V5i9Gb3q7DrAT4XWwj07FQaPr7lwVEPHAaiTFKSXXhTX 3TVV1eZDLhfFQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 06/11] btrfs: get rid of label and goto at insert_delayed_ref() Date: Mon, 29 May 2023 16:17:02 +0100 Message-Id: <5ef479b0dfa2c93bf010fc9d613baed9cd9f1043.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana At insert_delayed_ref() there's no point of having a label and goto in the case we were able to insert the delayed ref head. We can just add the code under label to the if statement's body and return immediately, and also there is no need to track the return value in a variable, we can just return a literal true or false value directly. So do those changes. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index c3da7c3185de..e4579e66a57a 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -565,15 +565,18 @@ static bool insert_delayed_ref(struct btrfs_delayed_ref_root *root, { struct btrfs_delayed_ref_node *exist; int mod; - bool ret = false; spin_lock(&href->lock); exist = tree_insert(&href->ref_tree, ref); - if (!exist) - goto inserted; + if (!exist) { + if (ref->action == BTRFS_ADD_DELAYED_REF) + list_add_tail(&ref->add_list, &href->ref_add_list); + atomic_inc(&root->num_entries); + spin_unlock(&href->lock); + return false; + } /* Now we are sure we can merge */ - ret = true; if (exist->action == ref->action) { mod = ref->ref_mod; } else { @@ -600,13 +603,7 @@ static bool insert_delayed_ref(struct btrfs_delayed_ref_root *root, if (exist->ref_mod == 0) drop_delayed_ref(root, href, exist); spin_unlock(&href->lock); - return ret; -inserted: - if (ref->action == BTRFS_ADD_DELAYED_REF) - list_add_tail(&ref->add_list, &href->ref_add_list); - atomic_inc(&root->num_entries); - spin_unlock(&href->lock); - return ret; + return true; } /* From patchwork Mon May 29 15:17:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D9FBC7EE23 for ; Mon, 29 May 2023 15:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229764AbjE2PRi (ORCPT ); Mon, 29 May 2023 11:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjE2PRX (ORCPT ); Mon, 29 May 2023 11:17:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9517BC9 for ; Mon, 29 May 2023 08:17:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 755FE615E4 for ; Mon, 29 May 2023 15:17:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 608F3C4339C for ; Mon, 29 May 2023 15:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373441; bh=ZeYnw0hLiYn/FPymdlt6NnvBUqWGXjwIVP/K7IEhrzI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VTYuCzuXAQEsHlv5YDxdJLYKtPuirgZ+cryV+NAa5Z07wF1lyziyIaA4dSwDi3qZ+ 7CE2GloKQv0VqonaSILgSTc5Sdg8Og+bICE3MZlKlhNfg53zNZXS/mpBHpIfyd0men 4JaopRjBqA5fe4s8Tdjn0KfKCnAmLmQJgDKiNSAALlrjvUaXpXatAJthZANFuYW5K8 bqAlOzorBE+svU7xqm2WD9ON5XO/k03k9XE9AwDtQybm6iIeiZkf7Kv6ffjI3BWzfD a9KnrLCHhyHaXxTWB4wA/atsCXMAltXCxQiuCnaOS14PK0C+EpaYQFtauiYGl4Lizb xK2Goi6YtSGtw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 07/11] btrfs: assert correct lock is held at btrfs_select_ref_head() Date: Mon, 29 May 2023 16:17:03 +0100 Message-Id: <83affb7dc94093940cba2485afedb9d661191335.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana The function btrfs_select_ref_head() iterates over the red black tree of delayed reference heads, which is protected by the spinlock in the delayed refs root. The function doesn't take the lock, it's taken by its single caller, btrfs_obtain_ref_head(), because it needs to call that function and btrfs_delayed_ref_lock() in the same critical section (delimited by that spinlock). So assert at btrfs_select_ref_head() that we are holding the expected lock. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index e4579e66a57a..c61af9012a82 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -506,6 +506,7 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( { struct btrfs_delayed_ref_head *head; + lockdep_assert_held(&delayed_refs->lock); again: head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start, true); From patchwork Mon May 29 15:17:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66B6BC77B7E for ; Mon, 29 May 2023 15:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjE2PRi (ORCPT ); Mon, 29 May 2023 11:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjE2PRZ (ORCPT ); Mon, 29 May 2023 11:17:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D45CACF for ; Mon, 29 May 2023 08:17:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6A253615AF for ; Mon, 29 May 2023 15:17:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54030C4339B for ; Mon, 29 May 2023 15:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373442; bh=63t7aAH+6PgEfoT27gIQNK1ccZQyKJ834QwBTcVgvr4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bjFvaAXO8sWoRpckxoNTm4miZZROMwZfFR/Kf2ppEeMmQ5Boi8Vhmw2URqUoerfbb ehgVqBGvbcYU3c/ohY0FeUYMq8UeXRwa9wgYwgQoVxVmi6ERpriyp+M/jN8rDuAFBS wFNqmteYrQSDl9SlAhVaBQYvZy2b8wPUiP6iwXdnV9Kpuk1Eobv9eP7JiSaRDixEJ5 bzWXSS45VqvgUSeDq6I43vfLbl23tWjzyBkBCZRKrkSN1cmcxrpDdwho0LDJX0CVSR mK/0Ir9y/fu4VUfAMXOVTjJ+x++K5jPbLZA6MmBFdhxhXXoXekZ8cwGBWctEP1EQls uFshbgrXHpb0w== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 08/11] btrfs: use bool type for delayed ref head fields that are used as booleans Date: Mon, 29 May 2023 16:17:04 +0100 Message-Id: <52be0d3f3d1e7ae93770c95099c2fcf00f151747.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana There's no point in have several fields defined as 1 bit unsigned int in struct btrfs_delayed_ref_head, we can instead use a bool type, it makes the code a bit more readable and it doesn't change the structure size. So switch them to proper booleans. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 12 ++++++------ fs/btrfs/delayed-ref.h | 8 ++++---- fs/btrfs/extent-tree.c | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index c61af9012a82..bf8c2ac6c95e 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -531,7 +531,7 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( href_node); } - head->processing = 1; + head->processing = true; WARN_ON(delayed_refs->num_heads_ready == 0); delayed_refs->num_heads_ready--; delayed_refs->run_delayed_start = head->bytenr + @@ -549,7 +549,7 @@ void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, RB_CLEAR_NODE(&head->href_node); atomic_dec(&delayed_refs->num_entries); delayed_refs->num_heads--; - if (head->processing == 0) + if (!head->processing) delayed_refs->num_heads_ready--; } @@ -697,7 +697,7 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, bool is_system) { int count_mod = 1; - int must_insert_reserved = 0; + bool must_insert_reserved = false; /* If reserved is provided, it must be a data extent. */ BUG_ON(!is_data && reserved); @@ -722,9 +722,9 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, * BTRFS_ADD_DELAYED_REF because other special casing is not required. */ if (action == BTRFS_ADD_DELAYED_EXTENT) - must_insert_reserved = 1; + must_insert_reserved = true; else - must_insert_reserved = 0; + must_insert_reserved = false; refcount_set(&head_ref->refs, 1); head_ref->bytenr = bytenr; @@ -736,7 +736,7 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, head_ref->ref_tree = RB_ROOT_CACHED; INIT_LIST_HEAD(&head_ref->ref_add_list); RB_CLEAR_NODE(&head_ref->href_node); - head_ref->processing = 0; + head_ref->processing = false; head_ref->total_ref_mod = count_mod; spin_lock_init(&head_ref->lock); mutex_init(&head_ref->mutex); diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 9b103bf27185..b8e14b0ba5f1 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -116,10 +116,10 @@ struct btrfs_delayed_ref_head { * we need to update the in ram accounting to properly reflect * the free has happened. */ - unsigned int must_insert_reserved:1; - unsigned int is_data:1; - unsigned int is_system:1; - unsigned int processing:1; + bool must_insert_reserved; + bool is_data; + bool is_system; + bool processing; }; struct btrfs_delayed_tree_ref { diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0aa775ac31e4..ffd4198c19b0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1497,7 +1497,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, static int run_delayed_data_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_node *node, struct btrfs_delayed_extent_op *extent_op, - int insert_reserved) + bool insert_reserved) { int ret = 0; struct btrfs_delayed_data_ref *ref; @@ -1647,7 +1647,7 @@ static int run_delayed_extent_op(struct btrfs_trans_handle *trans, static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_node *node, struct btrfs_delayed_extent_op *extent_op, - int insert_reserved) + bool insert_reserved) { int ret = 0; struct btrfs_delayed_tree_ref *ref; @@ -1687,7 +1687,7 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, static int run_one_delayed_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_node *node, struct btrfs_delayed_extent_op *extent_op, - int insert_reserved) + bool insert_reserved) { int ret = 0; @@ -1897,7 +1897,7 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_extent_op *extent_op; struct btrfs_delayed_ref_node *ref; - int must_insert_reserved = 0; + bool must_insert_reserved; int ret; delayed_refs = &trans->transaction->delayed_refs; @@ -1939,7 +1939,7 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, * spin lock. */ must_insert_reserved = locked_ref->must_insert_reserved; - locked_ref->must_insert_reserved = 0; + locked_ref->must_insert_reserved = false; extent_op = locked_ref->extent_op; locked_ref->extent_op = NULL; From patchwork Mon May 29 15:17:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 946D6C7EE29 for ; Mon, 29 May 2023 15:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbjE2PRk (ORCPT ); Mon, 29 May 2023 11:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjE2PRZ (ORCPT ); Mon, 29 May 2023 11:17:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3703D2 for ; Mon, 29 May 2023 08:17:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5998F60B28 for ; Mon, 29 May 2023 15:17:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 465E3C433EF for ; Mon, 29 May 2023 15:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373443; bh=qyzhnvFZ8DUwRAaTslY61RTRf+/OXDb8e2S1zea0a1M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=trYq75sCoVl2zOLYuWwJ3kwA4c+JfzP7LXjGEFisKltacbuW4F05Li/1QjMHUW1EZ iKDMzKiBr3DIVQEOq5wQ7LsQAIFM5n4iOdlwQt+WlorGDCv3i8fAgkydiK1W67GaZf AewhrqAVz0R+DtLmIv2RakALHGJHTjkdVVbgGOD4RM6iVxaY1Rj8CvDzEe6MNhxYJv bXtvNGZyoOJpodLC5tIpl1Y22d3P/bmAHsMNBpaYx+iGKzdRp28dzVogXR/ZgVQgOf 9iiTjodWatwkkVLWvhAq6a5qEZZ0bdwIxARGOAfNHlFq67IA6m0O8qRUcV2vFEaAoU dKMKT+9ga0/vw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 09/11] btrfs: use a single switch statement when initializing delayed ref head Date: Mon, 29 May 2023 16:17:05 +0100 Message-Id: <17984e68ade72b7b411688f32585a8038406bf33.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana At init_delayed_ref_head(), we are using two separate if statements to check the delayed ref head action, and initializing 'must_insert_reserved' to false twice, once when the variable is declared and once again in an else branch. Make this simpler and more straitghforward by having a single switch statement, also moving the comment about a drop action to the corresponding switch case to make it more clear and eliminating the duplicated initialization of 'must_insert_reserved' to false. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index bf8c2ac6c95e..6a13cf00218b 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -702,29 +702,33 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, /* If reserved is provided, it must be a data extent. */ BUG_ON(!is_data && reserved); - /* - * The head node stores the sum of all the mods, so dropping a ref - * should drop the sum in the head node by one. - */ - if (action == BTRFS_UPDATE_DELAYED_HEAD) + switch (action) { + case BTRFS_UPDATE_DELAYED_HEAD: count_mod = 0; - else if (action == BTRFS_DROP_DELAYED_REF) + break; + case BTRFS_DROP_DELAYED_REF: + /* + * The head node stores the sum of all the mods, so dropping a ref + * should drop the sum in the head node by one. + */ count_mod = -1; - - /* - * BTRFS_ADD_DELAYED_EXTENT means that we need to update the reserved - * accounting when the extent is finally added, or if a later - * modification deletes the delayed ref without ever inserting the - * extent into the extent allocation tree. ref->must_insert_reserved - * is the flag used to record that accounting mods are required. - * - * Once we record must_insert_reserved, switch the action to - * BTRFS_ADD_DELAYED_REF because other special casing is not required. - */ - if (action == BTRFS_ADD_DELAYED_EXTENT) + break; + case BTRFS_ADD_DELAYED_EXTENT: + /* + * BTRFS_ADD_DELAYED_EXTENT means that we need to update the + * reserved accounting when the extent is finally added, or if a + * later modification deletes the delayed ref without ever + * inserting the extent into the extent allocation tree. + * ref->must_insert_reserved is the flag used to record that + * accounting mods are required. + * + * Once we record must_insert_reserved, switch the action to + * BTRFS_ADD_DELAYED_REF because other special casing is not + * required. + */ must_insert_reserved = true; - else - must_insert_reserved = false; + break; + } refcount_set(&head_ref->refs, 1); head_ref->bytenr = bytenr; From patchwork Mon May 29 15:17:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4AC3C7EE31 for ; Mon, 29 May 2023 15:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbjE2PRl (ORCPT ); Mon, 29 May 2023 11:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbjE2PR0 (ORCPT ); Mon, 29 May 2023 11:17:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A19CF for ; Mon, 29 May 2023 08:17:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C6EB615AF for ; Mon, 29 May 2023 15:17:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38DBCC4339B for ; Mon, 29 May 2023 15:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373444; bh=SmtNh4wkuoLzutOi1oeW7k/3ncP8tpUUbMj64KQBVVg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bmVZejTCFJKK5EfyZ+HblWvFaDm87JZTqbUDhpGJGNbTrFhMz3Hqdej8p9TmNSUfk dAVGMktOMunS2iVvap/AMU/Yh23DxQpLjfDXKP7kfYAiHWb6e1cdx3LOhLQp9IUQjn EMvuGuyu+F/JJv/NvX/3uOIyahgfqYgXgNGshQoO+mj6IkZmPVLqz/4TgQEpBrXs+h FNJaWZgMqB196vyMN8jxt++cl4uzFU9CL9vMKSFBcO1TBEBqZREuRHjJr1Evx7Brts IoibBcq3vZaD5VXYsBiSM1+D262LoRaX+x42okhaX/iiU4zJ2fo2QenVenwnUAzr2g MxUGf85oTLsqQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 10/11] btrfs: remove unnecessary prototype declarations at disk-io.c Date: Mon, 29 May 2023 16:17:06 +0100 Message-Id: <241c90672d9a483bdab79a442c0d4a809097df37.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana We have a few static functions at disk-io.c for which we have a forward declaration of their prototype, but it's not needed because all those functions are defined before they are called, so remove them. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 793f7e48d62e..fb7ec47f21f1 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -60,15 +60,6 @@ BTRFS_SUPER_FLAG_METADUMP |\ BTRFS_SUPER_FLAG_METADUMP_V2) -static void btrfs_destroy_ordered_extents(struct btrfs_root *root); -static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, - struct btrfs_fs_info *fs_info); -static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root); -static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, - struct extent_io_tree *dirty_pages, - int mark); -static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info, - struct extent_io_tree *pinned_extents); static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info); static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info); From patchwork Mon May 29 15:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13258714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CC28C7EE2E for ; Mon, 29 May 2023 15:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbjE2PRl (ORCPT ); Mon, 29 May 2023 11:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbjE2PR1 (ORCPT ); Mon, 29 May 2023 11:17:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A106EC9 for ; Mon, 29 May 2023 08:17:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F0AD615DD for ; Mon, 29 May 2023 15:17:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D36FC433EF for ; Mon, 29 May 2023 15:17:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685373445; bh=oXiums+JHu6NBp8CHzKQMSZOcn1ycbQ4h46zJ0jPjGA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YWPPgWua9lT9rWwJAN5PV3E9Ddq2Eh1zyQeXPNpwMs91azzzIP9Gecbq/wxPUDVpD +Dq5BTLf1xpvcEaAbfOzO4rtjaS9T8grTPmAe2RGS8ikdIJAsQlAGeS3wIm7RFRejZ NbqrWgTaBgS+HHwd4HxYjlRlLCga0vkpPHsn5OZyYJmLatwR27oQTn+t89tt3EMN3m 79yl3XfJWV6p/Xpk1rfCwzavkecQLcLYvzXIVo5cQYYMr120JygW7Mbzg1HyhLGFd6 dzcNiFMgOLBaKHOhQ0Svxs12eTBwRH6id/+bbCCrRPEtAr7CanjH/3ZMBT+/8aTRdo AIW0ts9Njs+5A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 11/11] btrfs: make btrfs_destroy_delayed_refs() return void Date: Mon, 29 May 2023 16:17:07 +0100 Message-Id: <8f1298da5496557ca89592916cd4a445b6048b8f.1685363099.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana btrfs_destroy_delayed_refs() always returns 0 and its single caller does not even check its return value, so make it return void. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fb7ec47f21f1..02e9004f79dc 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4809,13 +4809,12 @@ static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info) btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); } -static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, - struct btrfs_fs_info *fs_info) +static void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, + struct btrfs_fs_info *fs_info) { struct rb_node *node; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_ref_node *ref; - int ret = 0; delayed_refs = &trans->delayed_refs; @@ -4823,7 +4822,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, if (atomic_read(&delayed_refs->num_entries) == 0) { spin_unlock(&delayed_refs->lock); btrfs_debug(fs_info, "delayed_refs has NO entry"); - return ret; + return; } while ((node = rb_first_cached(&delayed_refs->href_root)) != NULL) { @@ -4884,8 +4883,6 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, btrfs_qgroup_destroy_extent_records(trans); spin_unlock(&delayed_refs->lock); - - return ret; } static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root)