From patchwork Mon Jan 13 19:35:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3480131 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 40991C02DC for ; Mon, 13 Jan 2014 19:35:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 616CB20122 for ; Mon, 13 Jan 2014 19:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CD6B20121 for ; Mon, 13 Jan 2014 19:35:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522AbaAMTfV (ORCPT ); Mon, 13 Jan 2014 14:35:21 -0500 Received: from mail-wg0-f49.google.com ([74.125.82.49]:64941 "EHLO mail-wg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752050AbaAMTfT (ORCPT ); Mon, 13 Jan 2014 14:35:19 -0500 Received: by mail-wg0-f49.google.com with SMTP id a1so4726650wgh.28 for ; Mon, 13 Jan 2014 11:35:18 -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:in-reply-to:references; bh=IB/J1oMUP0CdA1z9LAgWhYvrT/ToRl29BrssBdDOEy8=; b=vHQ4m0o7oKZqBrUZoclt+W+pTptc2+KK8pCYIpVQigLvxL6HGDrGE3+XY5/SWkuzJT E64VkBE4J2/juX8vd/LaqPnfMV4iRHkb0sRnQoBbtp7koNYzh8ExMtuIwxF04ULiOE22 ZrNbF2t8tMJFyBaBRKYHJg0KK9uhceLgmVktP/Lqnm76XZy1AWVsKnn2DWbv1dC50NRO FjamJ9uRliVh2RPkw6YWc2+Eg81T+oXOq5uCl7sIA4sCSi+pjQAWGgdvtLlkWe5hGeLA p6eKMBbrOZKO/Wb/4znmuVpVpXX3jl4ysjCltAbezjhBuKNs80CNUEFvmy9A9b4e6bn+ TuPQ== X-Received: by 10.181.12.76 with SMTP id eo12mr4625694wid.19.1389641718178; Mon, 13 Jan 2014 11:35:18 -0800 (PST) Received: from storm-desktop.lan (bl5-79-235.dsl.telepac.pt. [82.154.79.235]) by mx.google.com with ESMTPSA id hy8sm12354319wjb.2.2014.01.13.11.35.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Jan 2014 11:35:17 -0800 (PST) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH v3] Btrfs: faster file extent item search in clone ioctl Date: Mon, 13 Jan 2014 19:35:01 +0000 Message-Id: <1389641701-19162-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389475828-19339-1-git-send-email-fdmanana@gmail.com> References: <1389475828-19339-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=-6.9 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 When we are looking for file extent items that intersect the cloning range, for each one that falls completely outside the range, don't release the path and do another full tree search - just move on to the next slot and copy the file extent item into our buffer only if the item intersects the cloning range. Signed-off-by: Filipe David Borba Manana --- V2: Set path->leave_spinning to 1. V3: Reset path->leave_spinning to 0 before path is used by btrfs_drop_extents, as that function allocates memory without GFP_ATOMIC and therefore can sleep. fs/btrfs/ioctl.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 3970f32..25301bb 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2905,12 +2905,14 @@ static int btrfs_clone(struct inode *src, struct inode *inode, * note the key will change type as we walk through the * tree. */ + path->leave_spinning = 1; ret = btrfs_search_slot(NULL, BTRFS_I(src)->root, &key, path, 0, 0); if (ret < 0) goto out; nritems = btrfs_header_nritems(path->nodes[0]); +process_slot: if (path->slots[0] >= nritems) { ret = btrfs_next_leaf(BTRFS_I(src)->root, path); if (ret < 0) @@ -2937,11 +2939,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode, u8 comp; u64 endoff; - size = btrfs_item_size_nr(leaf, slot); - read_extent_buffer(leaf, buf, - btrfs_item_ptr_offset(leaf, slot), - size); - extent = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item); comp = btrfs_file_extent_compression(leaf, extent); @@ -2960,11 +2957,20 @@ static int btrfs_clone(struct inode *src, struct inode *inode, datal = btrfs_file_extent_ram_bytes(leaf, extent); } - btrfs_release_path(path); if (key.offset + datal <= off || - key.offset >= off + len - 1) - goto next; + key.offset >= off + len - 1) { + path->slots[0]++; + goto process_slot; + } + + size = btrfs_item_size_nr(leaf, slot); + read_extent_buffer(leaf, buf, + btrfs_item_ptr_offset(leaf, slot), + size); + + btrfs_release_path(path); + path->leave_spinning = 0; memcpy(&new_key, &key, sizeof(new_key)); new_key.objectid = btrfs_ino(inode); @@ -3135,7 +3141,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode, } ret = btrfs_end_transaction(trans, root); } -next: btrfs_release_path(path); key.offset++; }