From patchwork Tue Mar 11 13:56:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3812571 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 374D89F402 for ; Tue, 11 Mar 2014 13:56:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A48820394 for ; Tue, 11 Mar 2014 13:56:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 851F82021A for ; Tue, 11 Mar 2014 13:56:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752491AbaCKN4e (ORCPT ); Tue, 11 Mar 2014 09:56:34 -0400 Received: from mail-wg0-f41.google.com ([74.125.82.41]:59914 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754015AbaCKN4c (ORCPT ); Tue, 11 Mar 2014 09:56:32 -0400 Received: by mail-wg0-f41.google.com with SMTP id n12so10178099wgh.0 for ; Tue, 11 Mar 2014 06:56:31 -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:in-reply-to:references; bh=yQe8TtVBjVDV72ymfNc66MWukN4obfGz41QycT3484o=; b=Iw1oyXB7EwH/yKQxVh8dLv3OrM5l+Gl144KWcGmZOm5zjxPuoHM7f8jVUDGCM1MZZI wXxJ6ereLPMi1b33QoZ568YD/eKHAGrWPPK4s5knoKHDT+1v/FSgWZvWZOMsP+V/mlE3 74rlzK0EKuxC1RZ6IrPgvfBizGTl90MFgPtcUSFzvEbdyJMeh/07MRsZBIKu1RtWvpGX McCrm5NYw7p6Ww75/4UbR36CAUcsOLr+lzLYcJnynNbeeY2rNVhaasqrMVeLrGTW5SP+ z9InYNGiI2b5GeEe1k+j7pjdJTHD2rNZK0E0okfGktRY7AUnGZMj0a6Kjw+ushwq7Pcr dyRA== X-Received: by 10.180.72.239 with SMTP id g15mr3316984wiv.45.1394546191572; Tue, 11 Mar 2014 06:56:31 -0700 (PDT) Received: from storm-desktop.lan (bl10-252-34.dsl.telepac.pt. [85.243.252.34]) by mx.google.com with ESMTPSA id hy8sm61678118wjb.2.2014.03.11.06.56.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Mar 2014 06:56:30 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH 2/2] Btrfs: cache extent states in defrag code path Date: Tue, 11 Mar 2014 13:56:15 +0000 Message-Id: <1394546175-7370-2-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1394546175-7370-1-git-send-email-fdmanana@gmail.com> References: <1394546175-7370-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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 locking file ranges in the inode's io_tree, cache the first extent state that belongs to the target range, so that when unlocking the range we don't need to search in the io_tree again, reducing cpu time and making and therefore holding the io_tree's lock for a shorter period. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/ioctl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 5239470..6de00ad 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -994,10 +994,13 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start) read_unlock(&em_tree->lock); if (!em) { + struct extent_state *cached = NULL; + u64 end = start + len - 1; + /* get the big lock and read metadata off disk */ - lock_extent(io_tree, start, start + len - 1); + lock_extent_bits(io_tree, start, end, 0, &cached); em = btrfs_get_extent(inode, NULL, 0, start, len, 0); - unlock_extent(io_tree, start, start + len - 1); + unlock_extent_cached(io_tree, start, end, &cached, GFP_NOFS); if (IS_ERR(em)) return NULL; @@ -1136,10 +1139,12 @@ again: page_start = page_offset(page); page_end = page_start + PAGE_CACHE_SIZE - 1; while (1) { - lock_extent(tree, page_start, page_end); + lock_extent_bits(tree, page_start, page_end, + 0, &cached_state); ordered = btrfs_lookup_ordered_extent(inode, page_start); - unlock_extent(tree, page_start, page_end); + unlock_extent_cached(tree, page_start, page_end, + &cached_state, GFP_NOFS); if (!ordered) break;