From patchwork Fri Jan 31 16:42:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3562741 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 404869F381 for ; Fri, 31 Jan 2014 16:42:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C6E52021E for ; Fri, 31 Jan 2014 16:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFFF52022A for ; Fri, 31 Jan 2014 16:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932624AbaAaQm2 (ORCPT ); Fri, 31 Jan 2014 11:42:28 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:41813 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932281AbaAaQm1 (ORCPT ); Fri, 31 Jan 2014 11:42:27 -0500 Received: by mail-pa0-f41.google.com with SMTP id fa1so4631176pad.14 for ; Fri, 31 Jan 2014 08:42:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=PI/1thBhklJIBlkteC2UYkOwWfcRKtZ9kQTa7C4HDsY=; b=I3S7WRYntVoqQ58cqBl4K8F3mv6oATFdv7Az6OZ5Hvda4Bx0JM7JhsSVRfIH6BivOv Sm8SR175eERVeO2XLfEgl0mUdBLYj6k0dvF1ccTxmZyhWX8sIVfgzNm8mEkUkMB96sNR buSRG7D3diQ5C1HXwjpsy4zaj7yXoAA+lB5XNA6f57iVGz3J+HGk1sGUIncA8RVD/aNh tXp5BeOepSU6RIoXIuHKJG4aAiwj+Lie0n14XhbhqtDxDk6ZO9dkpEtr1BMpVKZpq1ZC VFqX3VNZyuGhJWUOlYG7/nv6/xcFpOb6PpDf1D/3+KBezVN6qvTUKgijPiE58PsRvy0E 59Aw== X-Received: by 10.68.223.9 with SMTP id qq9mr21886455pbc.58.1391186546645; Fri, 31 Jan 2014 08:42:26 -0800 (PST) Received: from linux-b0ol.localdomain ([36.59.228.44]) by mx.google.com with ESMTPSA id om6sm29181142pbc.43.2014.01.31.08.42.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2014 08:42:26 -0800 (PST) From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] Btrfs: only add roots if necessary in find_parent_nodes() Date: Sat, 1 Feb 2014 00:42:05 +0800 Message-Id: <1391186525-2965-2-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1391186525-2965-1-git-send-email-wangshilong1991@gmail.com> References: <1391186525-2965-1-git-send-email-wangshilong1991@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=-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 From: Wang Shilong find_all_leafs() dosen't need add all roots actually, add roots only if we need, this can avoid unnecessary ulist dance. Signed-off-by: Wang Shilong --- fs/btrfs/backref.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 4f59f07..2888f7a 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -965,7 +965,7 @@ again: while (!list_empty(&prefs)) { ref = list_first_entry(&prefs, struct __prelim_ref, list); WARN_ON(ref->count < 0); - if (ref->count && ref->root_id && ref->parent == 0) { + if (roots && ref->count && ref->root_id && ref->parent == 0) { /* no parent == root of tree */ ret = ulist_add(roots, ref->root_id, 0, GFP_NOFS); if (ret < 0) @@ -1061,22 +1061,14 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans, u64 time_seq, struct ulist **leafs, const u64 *extent_item_pos) { - struct ulist *tmp; int ret; - tmp = ulist_alloc(GFP_NOFS); - if (!tmp) - return -ENOMEM; *leafs = ulist_alloc(GFP_NOFS); - if (!*leafs) { - ulist_free(tmp); + if (!*leafs) return -ENOMEM; - } ret = find_parent_nodes(trans, fs_info, bytenr, - time_seq, *leafs, tmp, extent_item_pos); - ulist_free(tmp); - + time_seq, *leafs, NULL, extent_item_pos); if (ret < 0 && ret != -ENOENT) { free_leaf_list(*leafs); return ret;