From patchwork Tue Jul 30 11:03:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 2835529 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CF862C0319 for ; Tue, 30 Jul 2013 11:03:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84E9C2030E for ; Tue, 30 Jul 2013 11:03:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26FA420303 for ; Tue, 30 Jul 2013 11:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751950Ab3G3LDR (ORCPT ); Tue, 30 Jul 2013 07:03:17 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:59329 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750848Ab3G3LDQ (ORCPT ); Tue, 30 Jul 2013 07:03:16 -0400 Received: by mail-wg0-f45.google.com with SMTP id x12so6005327wgg.24 for ; Tue, 30 Jul 2013 04:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=B9IWrHeyKm0wfqT/EaiYQo7gBkoGWDgN/UN7lUl74xs=; b=vCpuNUIANhgslvzkV1duBCQQDfaPhCZeittoe7j7SjLyMrN8yfq3Fpq50E+AT1XMH8 OpOg14FmPcyTDFHe/ti8RghUxhmITS66HpcGHJnBN5I9RDFd80mH4at6eQLCpURvrXyJ urf7hM1nkcNYKdpXj9tAE3zPvxslugVOxyTambQKdGKcgijm6bo5Lb10HPz0nfKP8qI8 5zx7rwwnW37bKBhjX+J6CvIJ0g30BVAGmFZLwuBUPak+aYKTL+AJ0S65PwTjAXW5njL0 f+7Tc7wa+niBWVwEETj8C5pt13ScwHZGbJ28YK9H794hiBAs96a4qrWYMToswk3QMQSA Zw1g== X-Received: by 10.180.210.231 with SMTP id mx7mr617237wic.5.1375182195000; Tue, 30 Jul 2013 04:03:15 -0700 (PDT) Received: from storm-desktop.lan (bl9-171-157.dsl.telepac.pt. [85.242.171.157]) by mx.google.com with ESMTPSA id jf9sm15535232wic.5.2013.07.30.04.03.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Jul 2013 04:03:14 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: jbacik@fusionio.com, Filipe David Borba Manana Subject: [PATCH v3] Btrfs: optimize function btrfs_read_chunk_tree Date: Tue, 30 Jul 2013 12:03:04 +0100 Message-Id: <1375182184-30490-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1372853956-10569-1-git-send-email-fdmanana@gmail.com> References: <1372853956-10569-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After reading all device items from the chunk tree, don't exit the loop and then navigate down the tree again to find the chunk items. Instead just read all device items and chunk items with a single tree search. This is possible because all device items are found before any chunk item in the chunks tree. Signed-off-by: Filipe David Borba Manana Reviewed-by: Miao Xie --- V2: Simplified logic inside the loop (suggested by Josef Bacik on irc). V3: Updated comment to comply with kernel coding style. fs/btrfs/volumes.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 090f57c..125a60e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5676,14 +5676,15 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) mutex_lock(&uuid_mutex); lock_chunks(root); - /* first we search for all of the device items, and then we - * read in all of the chunk items. This way we can create chunk - * mappings that reference all of the devices that are afound + /* + * Read all device items, and then all the chunk items. All + * device items are found before any chunk item (their object id + * is smaller than the lowest possible object id for a chunk + * item - BTRFS_FIRST_CHUNK_TREE_OBJECTID). */ key.objectid = BTRFS_DEV_ITEMS_OBJECTID; key.offset = 0; key.type = 0; -again: ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) goto error; @@ -5699,17 +5700,13 @@ again: break; } btrfs_item_key_to_cpu(leaf, &found_key, slot); - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) - break; - if (found_key.type == BTRFS_DEV_ITEM_KEY) { - struct btrfs_dev_item *dev_item; - dev_item = btrfs_item_ptr(leaf, slot, + if (found_key.type == BTRFS_DEV_ITEM_KEY) { + struct btrfs_dev_item *dev_item; + dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_dev_item); - ret = read_one_dev(root, leaf, dev_item); - if (ret) - goto error; - } + ret = read_one_dev(root, leaf, dev_item); + if (ret) + goto error; } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { struct btrfs_chunk *chunk; chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); @@ -5719,11 +5716,6 @@ again: } path->slots[0]++; } - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - key.objectid = 0; - btrfs_release_path(path); - goto again; - } ret = 0; error: unlock_chunks(root);