From patchwork Sat Feb 9 05:24:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10804131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9EF5922 for ; Sat, 9 Feb 2019 05:26:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB7AA2DD01 for ; Sat, 9 Feb 2019 05:26:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF5242DD0F; Sat, 9 Feb 2019 05:26:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AF192DD01 for ; Sat, 9 Feb 2019 05:26:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726118AbfBIFYo (ORCPT ); Sat, 9 Feb 2019 00:24:44 -0500 Received: from mx2.suse.de ([195.135.220.15]:60236 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725919AbfBIFYo (ORCPT ); Sat, 9 Feb 2019 00:24:44 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7B1D0AF5B; Sat, 9 Feb 2019 05:24:43 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov , Anand Jain Subject: [PATCH v2 1/2] btrfs: Don't search devid for every verify_one_dev_extent() call Date: Sat, 9 Feb 2019 13:24:36 +0800 Message-Id: <20190209052437.24020-2-wqu@suse.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190209052437.24020-1-wqu@suse.com> References: <20190209052437.24020-1-wqu@suse.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP verify_one_dev_extent() will call btrfs_find_device() for each dev extent, this waste some CPU time just searching the devices list. Move the search one level up, into the btrfs_verify_dev_extents(), so for each device we only call btrfs_find_device() once. Signed-off-by: Qu Wenruo Reviewed-by: Nikolay Borisov Reviewed-by: Anand Jain --- fs/btrfs/volumes.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 03f223aa7194..bae03111273e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7772,13 +7772,14 @@ static u64 calc_stripe_length(u64 type, u64 chunk_len, int num_stripes) } static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, - u64 chunk_offset, u64 devid, - u64 physical_offset, u64 physical_len) + struct btrfs_device *dev, + u64 chunk_offset, u64 physical_offset, + u64 physical_len) { struct extent_map_tree *em_tree = &fs_info->mapping_tree.map_tree; struct extent_map *em; struct map_lookup *map; - struct btrfs_device *dev; + u64 devid = dev->devid; u64 stripe_len; bool found = false; int ret = 0; @@ -7830,15 +7831,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, } /* Make sure no dev extent is beyond device bondary */ - dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true); - if (!dev) { - btrfs_err(fs_info, "failed to find devid %llu", devid); - ret = -EUCLEAN; - goto out; - } - - /* It's possible this device is a dummy for seed device */ if (dev->disk_total_bytes == 0) { + /* This device is a dummy for seed device */ dev = btrfs_find_device(fs_info->fs_devices->seed, devid, NULL, NULL, false); if (!dev) { @@ -7898,6 +7892,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) { struct btrfs_path *path; struct btrfs_root *root = fs_info->dev_root; + struct btrfs_device *device = NULL; struct btrfs_key key; u64 prev_devid = 0; u64 prev_dev_ext_end = 0; @@ -7941,6 +7936,17 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) devid = key.objectid; physical_offset = key.offset; + if (!device || devid != device->devid) { + device = btrfs_find_device(fs_info->fs_devices, devid, + NULL, NULL, true); + if (!device) { + btrfs_err(fs_info, "failed to find devid %llu", + devid); + ret = -EUCLEAN; + goto out; + } + } + dext = btrfs_item_ptr(leaf, slot, struct btrfs_dev_extent); chunk_offset = btrfs_dev_extent_chunk_offset(leaf, dext); physical_len = btrfs_dev_extent_length(leaf, dext); @@ -7954,7 +7960,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) goto out; } - ret = verify_one_dev_extent(fs_info, chunk_offset, devid, + ret = verify_one_dev_extent(fs_info, device, chunk_offset, physical_offset, physical_len); if (ret < 0) goto out;