From patchwork Fri Sep 28 15:58:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 1520061 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 7D5F8DF266 for ; Fri, 28 Sep 2012 15:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757747Ab2I1PxH (ORCPT ); Fri, 28 Sep 2012 11:53:07 -0400 Received: from mx2.fusionio.com ([66.114.96.31]:60994 "EHLO mx2.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756195Ab2I1PxF (ORCPT ); Fri, 28 Sep 2012 11:53:05 -0400 X-ASG-Debug-ID: 1348847583-0421b562ec5b100001-6jHSXT Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx2.fusionio.com with ESMTP id XHim3BZ9aY5bSWGi (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Fri, 28 Sep 2012 09:53:03 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (24.211.209.217) by mail.fusionio.com (10.101.1.19) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 28 Sep 2012 09:53:01 -0600 From: Josef Bacik To: Subject: [PATCH] Btrfs: be smarter about dropping things from the tree log Date: Fri, 28 Sep 2012 11:58:34 -0400 X-ASG-Orig-Subj: [PATCH] Btrfs: be smarter about dropping things from the tree log Message-ID: <1348847914-2192-1-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.7.7.6 MIME-Version: 1.0 X-Barracuda-Connect: mail1.int.fusionio.com[10.101.1.21] X-Barracuda-Start-Time: 1348847583 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.181:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.109840 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we truncate existing items in the tree log we've been searching for each individual item and removing them. This is unnecessary churn and searching, just keep track of the slot we are on and how many items we need to delete and delete them all at once. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/tree-log.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 4e468a0..90e1c28 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -2872,12 +2872,15 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans, int ret; struct btrfs_key key; struct btrfs_key found_key; + int start_slot; + int del_nr = 0; key.objectid = objectid; key.type = max_key_type; key.offset = (u64)-1; while (1) { + del_nr = 0; ret = btrfs_search_slot(trans, log, &key, path, -1, 1); BUG_ON(ret == 0); if (ret < 0) @@ -2885,20 +2888,29 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans, if (path->slots[0] == 0) break; - +next_slot: path->slots[0]--; + btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); if (found_key.objectid != objectid) break; - ret = btrfs_del_item(trans, log, path); + start_slot = path->slots[0]; + del_nr++; + if (start_slot) + goto next_slot; + + ret = btrfs_del_items(trans, log, path, start_slot, del_nr); if (ret) break; btrfs_release_path(path); } + if (!ret && del_nr) + ret = btrfs_del_items(trans, log, path, start_slot, del_nr); btrfs_release_path(path); + if (ret > 0) ret = 0; return ret;