From patchwork Fri Jan 24 17:42:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3535571 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F31BB9F1C3 for ; Fri, 24 Jan 2014 17:42:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A7B0620154 for ; Fri, 24 Jan 2014 17:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D1C0200FE for ; Fri, 24 Jan 2014 17:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751490AbaAXRmb (ORCPT ); Fri, 24 Jan 2014 12:42:31 -0500 Received: from mail-we0-f169.google.com ([74.125.82.169]:63680 "EHLO mail-we0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750997AbaAXRma (ORCPT ); Fri, 24 Jan 2014 12:42:30 -0500 Received: by mail-we0-f169.google.com with SMTP id u57so3046643wes.0 for ; Fri, 24 Jan 2014 09:42:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=/eT99ih41nqLP9w5qqKDQuoUkiHun5cqmXX52iqay+M=; b=rYPzKCeoW6ty5n6JI+eAAExGJz/4e8A6hp07c/zJbm7M5xayuOv4/B9cQq0J4ilrXX h6y+ewbxYSIYz41pqFcgvwlzJM2350CTBMYu6s2tqZnxHl3Zv0L8Vt1lerPsqK8EzZ3J SBsy0BvSkj5rLeNQl3iX92FOeKGa01GxfRrYDpNjgdkkn3YzzA8t5auB3e/D3qQbeW+t En79P4AknzbUVtwiHL7Bu7dQJy8Felvd1udbAZMgsQSbQYwIFop0bDNqhay3kc+9auc3 pj4XNFuEpd+oCLW1hOKcMI2jm0V7nOVXLitlv4JG0it3O+thEOkZGlfQE6ODa84iGmw3 rzdA== X-Received: by 10.194.22.129 with SMTP id d1mr11944692wjf.22.1390585349279; Fri, 24 Jan 2014 09:42:29 -0800 (PST) Received: from storm-desktop.lan (bl10-142-212.dsl.telepac.pt. [85.243.142.212]) by mx.google.com with ESMTPSA id f9sm8673518wib.3.2014.01.24.09.42.25 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 09:42:28 -0800 (PST) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: make send's file extent item search more efficient Date: Fri, 24 Jan 2014 17:42:09 +0000 Message-Id: <1390585329-11627-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 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 Instead of looking for a file extent item, process it, release the path and do a btree search for the next file extent item, just process all file extent items in a leaf without intermediate btree searches. This way we save cpu and we're not blocking other tasks or affecting concurrency on the btree, because send's paths use the commit root and skip btree node/leaf locking. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/send.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 78aba99..306f9a9 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4569,17 +4569,25 @@ static int process_all_extents(struct send_ctx *sctx) key.objectid = sctx->cmp_key->objectid; key.type = BTRFS_EXTENT_DATA_KEY; key.offset = 0; - while (1) { - ret = btrfs_search_slot_for_read(root, &key, path, 1, 0); - if (ret < 0) - goto out; - if (ret) { - ret = 0; - goto out; - } + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + if (ret < 0) + goto out; + while (1) { eb = path->nodes[0]; slot = path->slots[0]; + + if (slot >= btrfs_header_nritems(eb)) { + ret = btrfs_next_leaf(root, path); + if (ret < 0) { + goto out; + } else if (ret > 0) { + ret = 0; + break; + } + continue; + } + btrfs_item_key_to_cpu(eb, &found_key, slot); if (found_key.objectid != key.objectid || @@ -4592,8 +4600,7 @@ static int process_all_extents(struct send_ctx *sctx) if (ret < 0) goto out; - btrfs_release_path(path); - key.offset = found_key.offset + 1; + path->slots[0]++; } out: