From patchwork Tue May 26 14:21:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11570641 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 349401392 for ; Tue, 26 May 2020 14:21:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DA62206C3 for ; Tue, 26 May 2020 14:21:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="mBZYlAen" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727885AbgEZOVh (ORCPT ); Tue, 26 May 2020 10:21:37 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15674 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbgEZOVg (ORCPT ); Tue, 26 May 2020 10:21:36 -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=1590502896; x=1622038896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kgnjXng8/JrK5MZmUJI2s7IuSHBEfvk8UizKsNXmmiY=; b=mBZYlAentxSdwAhECJh07kqnHGB7nkb0TiFj10+ABE8ysT9dETRYaph/ Vb4NcjdZA8hlgOXV5lgXHR/Ruc9DdbLhpSYzqnwQ6RdkE9O+3n5GRIAxU eeHzOjC7p7+tmtudvwvL2ibOs5C3NkjiflBp1eohAl20/qyA4XjMOlsCL VVqoKjPGLIIgEPhAWiTb4ueyJAAp2ditlC25WFAaC5fnG381Wo3sMK5pY F/OVn6nhZr4etGbLyUpypeOHqvDJ7O1tpVQgaEr584OMwPYPUsDt/XOhm kYSX+Bm8IgLYZNjiHkRmM2Hc1JlOTpDmzWSCfThBnajeRgGiqx7OGmbN1 Q==; IronPort-SDR: SSS39h+kvigY8RuGt3/wjtYzI8dVGSD8NezBielrUpc9V8viAUMwt5WPKEYEmkYvb1Is4TVKg9 scxOWRJjgcIc01Up8hJmJnkx/x3ZKiII0l6K8vfmM3QX0VfaRqcFbBIvvJzqPlGZMqrJusuGzF 1y+d/vXVr91tfzGuJk9MkW9x09vUbWOXeZtUBgO5fFs0qxA5ys6KpU3bTa0Fd9Z0cSkPGmk7GH o4LbkjTFSjPQdDki/7ogn9n5uzjnQ72l1pfs7Km79vphCgDgHa+x5LYrwqcbvLEj2T2tdF3dah 6P4= X-IronPort-AV: E=Sophos;i="5.73,437,1583164800"; d="scan'208";a="247571874" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2020 22:21:35 +0800 IronPort-SDR: 63iXCvcRsMTEgGil4ZtIzp1sbVvcWGcL1Znkq6n3sXKktk9K4zvaMw/4vqNjEIXr52RteDZTbO gIQwjpBG1b4qLOMezE8jf9xBjL6qNyBzI= 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; 26 May 2020 07:10:55 -0700 IronPort-SDR: lwEuOx2+3jQGL4lYI24tlnaXwA+8zbaHMaADQLi/JrZp0jFCr5dM0Wrr8kVcz+ZFFCIsEkBtS9 w9+fvx3nb1rw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2020 07:21:35 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 1/3] btrfs: remove pointless out label in find_first_block_group Date: Tue, 26 May 2020 23:21:22 +0900 Message-Id: <20200526142124.36202-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200526142124.36202-1-johannes.thumshirn@wdc.com> References: <20200526142124.36202-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The 'out' label in find_first_block_group() does not do anything in terms of cleanup. It is better to directly return 'ret' instead of jumping to out to not confuse readers. Additionally there is no need to initialize ret with 0. Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- fs/btrfs/block-group.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 176e8a292fd1..c5acd89c864c 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1527,7 +1527,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, struct btrfs_key *key) { struct btrfs_root *root = fs_info->extent_root; - int ret = 0; + int ret; struct btrfs_key found_key; struct extent_buffer *leaf; struct btrfs_block_group_item bg; @@ -1536,7 +1536,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, ret = btrfs_search_slot(NULL, root, key, path, 0, 0); if (ret < 0) - goto out; + return ret; while (1) { slot = path->slots[0]; @@ -1546,7 +1546,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, if (ret == 0) continue; if (ret < 0) - goto out; + return ret; break; } btrfs_item_key_to_cpu(leaf, &found_key, slot); @@ -1594,11 +1594,11 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, } } free_extent_map(em); - goto out; + return ret; } path->slots[0]++; } -out: + return ret; } From patchwork Tue May 26 14:21:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11570645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B72E013B4 for ; Tue, 26 May 2020 14:21:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96389206C3 for ; Tue, 26 May 2020 14:21:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="CKilb/ud" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728061AbgEZOVi (ORCPT ); Tue, 26 May 2020 10:21:38 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15674 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727888AbgEZOVi (ORCPT ); Tue, 26 May 2020 10:21:38 -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=1590502897; x=1622038897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pgfFMefm73C0QZ4iZxCnqz1lYnwe0blqEwAqg17Ncgs=; b=CKilb/udwJ0QnFsSZKgK8AtoLV2v8zTQS7Nz08uhr+7dRbKM3ZQIrjqW ice0ZHmJA2uqOjgY+dR+lWTf/tBJRq8GyuvnLgSW0U2wKR1h/ljcF9q9M PhGVu6jcGIfoRJxdOcrf9ZnkYKkV0ala7Pl1DsFNcnnrbCg0FlSCC1Mj+ +U4ghx9xQMJHzDjs8ELT1EKzt7yIRKJ/metkuktnap0Fd86kQJwp12PbK L4xj3MB2sp5w0emxQuGgmEu3+0MoFfMO1UWH3e46l9XUJHh8shfkK21zz eC1aVvKSjCV322Z4Gy1ajHtrIPlhEK1KLIB50Rkt2hhlpFCNN2MJIJWGb g==; IronPort-SDR: YRNkiMGFAf2CQ6SreB8vNp4XGhjRNd5ujufkhcIvhOc1j2bdLA4S6G99S5KJqo3It1McVzJnzJ l9nZoNY3PBaCdtA3UWi1/JDNwlNKEtPyDxx/T8/lHGQpsSobvclwKN9A228B3q6lABYjdsBlBY zepxQEVycg+Oqgp3NkzBkym4GaGKvara85n6wwyHlDiF+TQA4NBSTT6zn2wBmBmKZCcBE4i1DB osPvAmbLZ3jjMzUZg1SYIZHaSdjI2NPAwG3wGGlZJTIbeI5j5BpAfPo0sgsnJDSqJ+aAVyzwXv 4gk= X-IronPort-AV: E=Sophos;i="5.73,437,1583164800"; d="scan'208";a="247571875" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2020 22:21:36 +0800 IronPort-SDR: UFf7u8tzEumBEyx4quJFrIpPJwyIEDJH4+TsWgQZSh0qKO06nOF454OIiCxYjVi3hgQ90gnhup 5aO6nWBJqZl2H3DeS+W8W6GNWHoJWCHAM= 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; 26 May 2020 07:10:56 -0700 IronPort-SDR: 0qEVEg2lV85ehLL9FwydM43mYm1DNsVzgcsiN7oX4QuYnjvycMSodBb9HVkYtcHQZI9N3FC4AJ kRKpfRsmMeMg== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2020 07:21:36 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 2/3] btrfs: get mapping tree directly from fsinfo in find_first_block_group Date: Tue, 26 May 2020 23:21:23 +0900 Message-Id: <20200526142124.36202-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200526142124.36202-1-johannes.thumshirn@wdc.com> References: <20200526142124.36202-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We already have an fs_info in our function parameters, there's no need to do the maths again and get fs_info from the extent_root just to get the mapping_tree. Instead directly grab the mapping_tree from fs_info. Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- fs/btrfs/block-group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c5acd89c864c..c4462e4c8413 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1556,7 +1556,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, struct extent_map_tree *em_tree; struct extent_map *em; - em_tree = &root->fs_info->mapping_tree; + em_tree = &fs_info->mapping_tree; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, found_key.objectid, found_key.offset); From patchwork Tue May 26 14:21:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11570643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAF1713B4 for ; Tue, 26 May 2020 14:21:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 935C8206C3 for ; Tue, 26 May 2020 14:21:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="KGwZaRvX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728111AbgEZOVj (ORCPT ); Tue, 26 May 2020 10:21:39 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15676 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbgEZOVi (ORCPT ); Tue, 26 May 2020 10:21:38 -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=1590502897; x=1622038897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VR1ItsBlp1d05PqxlMrWHBw9Qt8at6uO9u44E7ZZksE=; b=KGwZaRvXmnxLe04+FZdEm5X3feSPPp4jnFghouT9kFxo0rCyghWClUHh 5P8eZWd4aEdLv03uoiuhg0zNM89D8V6EH7btrnwbyH1XRMDiZAdPz7TPR BQ0KwGZi0KrIoMFC2uX9D1aX3Lr4QYcdXudIn1sd2hCnvFTs32S8XnZwI 7CPx3jPvLcIMeJwkEtKDah0k6gyQnIMzXoK64Oj9HT7QS7s/K4J9BiFBZ NxiR5DKjbGdemXO1PAFmErbocUhmjTAaS8x/lSMeiHYLSqBeiC2IuKxeM aYopGEr4nsY5WytNmlvsxgjXAsiWF3/J9h4TYGOcycx38F89gKf2Aia/n g==; IronPort-SDR: IzzDVf/46vGeUmDqDoMIlqYG3UJSyKoZYem/OZQC94+bAHH6dJO+KIWrcIuG0OBuquZEg7pMGE FZFhAWsfZ2V61lMZ26PBuS9AG50NIei1WvBnzcxykiEzVFemSu+iLooj7UbaBMUuTG50z0C7ek SewK58d4oKcd9THYIO005Xvzxap78XtlOa7IZx0P7dyuKbzk+GQI/23p50jXiYrxSU2Ohmet4u pJWPQ6HA8GR6BlJ1Cd6gzh5SpQrr+wFZZ0bK6d67ih3Rq5VcCHiDlHK+i5b/P7iOlrvj07mTAQ nEs= X-IronPort-AV: E=Sophos;i="5.73,437,1583164800"; d="scan'208";a="247571876" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2020 22:21:37 +0800 IronPort-SDR: qmTjDlv9qKrtd+yTnLmhkkYLPT3Na8tWpUbtjTNef3Di8akEktpApdkBSnr3iUYCOpfy7fMafB /Chr3Vuk4M3CJYqInh2GN8uXZISb9opu8= 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; 26 May 2020 07:10:56 -0700 IronPort-SDR: DVtlyO8dN91xZh+Hnz3p4r8Y9cCWIhTyrQamIDAMVUV4iYcjhweSasnQvYU18lHf1p5OmNmhOd Maczmawroj6A== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2020 07:21:37 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 3/3] btrfs: factor out reading of bg from find_frist_block_group Date: Tue, 26 May 2020 23:21:24 +0900 Message-Id: <20200526142124.36202-4-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200526142124.36202-1-johannes.thumshirn@wdc.com> References: <20200526142124.36202-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When find_first_block_group() finds a block group item in the extent-tree, it does a lookup of the object in the extent mapping tree and does further checks on the item. Factor out this step from find_first_block_group() so we can further simplify the code. As a bonus we even get a slight decrease in size: $ ./scripts/bloat-o-meter btrfs_old.ko btrfs.ko add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-2503 (-2503) Function old new delta btrfs_read_block_groups.cold 462 337 -125 btrfs_read_block_groups 4787 2409 -2378 Total: Before=2369371, After=2366868, chg -0.11% Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- fs/btrfs/block-group.c | 95 ++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c4462e4c8413..3d9e0ee1d1be 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1522,6 +1522,52 @@ void btrfs_mark_bg_unused(struct btrfs_block_group *bg) spin_unlock(&fs_info->unused_bgs_lock); } +static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key, + struct extent_buffer *leaf, int slot) +{ + struct extent_map_tree *em_tree; + struct extent_map *em; + struct btrfs_block_group_item bg; + u64 flags; + int ret = 0; + + em_tree = &fs_info->mapping_tree; + read_lock(&em_tree->lock); + em = lookup_extent_mapping(em_tree, key->objectid, key->offset); + read_unlock(&em_tree->lock); + if (!em) { + btrfs_err(fs_info, + "logical %llu len %llu found bg but no related chunk", + key->objectid, key->offset); + return -ENOENT; + } + + if (em->start != key->objectid || em->len != key->offset) { + btrfs_err(fs_info, + "block group %llu len %llu mismatch with chunk %llu len %llu", + key->objectid, key->offset, em->start, em->len); + ret = -EUCLEAN; + goto out_free_em; + } + + read_extent_buffer(leaf, &bg, btrfs_item_ptr_offset(leaf, slot), + sizeof(bg)); + flags = btrfs_stack_block_group_flags(&bg) & + BTRFS_BLOCK_GROUP_TYPE_MASK; + + if (flags != (em->map_lookup->type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(fs_info, + "block group %llu len %llu type flags 0x%llx mismatch with chunk type flags 0x%llx", + key->objectid, key->offset, flags, + (BTRFS_BLOCK_GROUP_TYPE_MASK & em->map_lookup->type)); + ret = -EUCLEAN; + } + +out_free_em: + free_extent_map(em); + return ret; +} + static int find_first_block_group(struct btrfs_fs_info *fs_info, struct btrfs_path *path, struct btrfs_key *key) @@ -1530,8 +1576,6 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, int ret; struct btrfs_key found_key; struct extent_buffer *leaf; - struct btrfs_block_group_item bg; - u64 flags; int slot; ret = btrfs_search_slot(NULL, root, key, path, 0, 0); @@ -1552,50 +1596,9 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, btrfs_item_key_to_cpu(leaf, &found_key, slot); if (found_key.objectid >= key->objectid && - found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { - struct extent_map_tree *em_tree; - struct extent_map *em; - - em_tree = &fs_info->mapping_tree; - read_lock(&em_tree->lock); - em = lookup_extent_mapping(em_tree, found_key.objectid, - found_key.offset); - read_unlock(&em_tree->lock); - if (!em) { - btrfs_err(fs_info, - "logical %llu len %llu found bg but no related chunk", - found_key.objectid, found_key.offset); - ret = -ENOENT; - } else if (em->start != found_key.objectid || - em->len != found_key.offset) { - btrfs_err(fs_info, - "block group %llu len %llu mismatch with chunk %llu len %llu", - found_key.objectid, found_key.offset, - em->start, em->len); - ret = -EUCLEAN; - } else { - read_extent_buffer(leaf, &bg, - btrfs_item_ptr_offset(leaf, slot), - sizeof(bg)); - flags = btrfs_stack_block_group_flags(&bg) & - BTRFS_BLOCK_GROUP_TYPE_MASK; - - if (flags != (em->map_lookup->type & - BTRFS_BLOCK_GROUP_TYPE_MASK)) { - btrfs_err(fs_info, -"block group %llu len %llu type flags 0x%llx mismatch with chunk type flags 0x%llx", - found_key.objectid, - found_key.offset, flags, - (BTRFS_BLOCK_GROUP_TYPE_MASK & - em->map_lookup->type)); - ret = -EUCLEAN; - } else { - ret = 0; - } - } - free_extent_map(em); - return ret; - } + found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) + return read_bg_from_eb(fs_info, &found_key, leaf, slot); + path->slots[0]++; }