From patchwork Fri Jan 10 13:25:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3466151 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 302B4C02DC for ; Fri, 10 Jan 2014 13:27:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1E5E420121 for ; Fri, 10 Jan 2014 13:27:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D565B2010B for ; Fri, 10 Jan 2014 13:27:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752326AbaAJN1D (ORCPT ); Fri, 10 Jan 2014 08:27:03 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:1604 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751303AbaAJN1C (ORCPT ); Fri, 10 Jan 2014 08:27:02 -0500 X-IronPort-AV: E=Sophos;i="4.95,638,1384272000"; d="scan'208";a="9401201" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 10 Jan 2014 21:23:22 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s0ADQxjn020747; Fri, 10 Jan 2014 21:26:59 +0800 Received: from wangs.fnst.cn.fujitsu.com ([10.167.226.104]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014011021255462-985552 ; Fri, 10 Jan 2014 21:25:54 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: Wang Shilong , Liu Bo Subject: [PATCH] Btrfs: optimize to remove unnecessary removal with ulist reallocation Date: Fri, 10 Jan 2014 21:25:46 +0800 Message-Id: <1389360346-23842-1-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/01/10 21:25:54, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/01/10 21:25:54, Serialize complete at 2014/01/10 21:25:54 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.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Here we are not going to free memory, no need to remove every node one by one, just init root node here is ok. Cc: Liu Bo Signed-off-by: Wang Shilong --- fs/btrfs/ulist.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/ulist.c b/fs/btrfs/ulist.c index b0a523b2..35f5de9 100644 --- a/fs/btrfs/ulist.c +++ b/fs/btrfs/ulist.c @@ -207,9 +207,6 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux, void *old = NULL; int i; - for (i = 0; i < ulist->nnodes; i++) - rb_erase(&ulist->nodes[i].rb_node, &ulist->root); - /* * if nodes_alloced == ULIST_SIZE no memory has been allocated * yet, so pass NULL to krealloc @@ -234,6 +231,7 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux, * pointers, so we have to do it ourselves. Otherwise we may * be bitten by crashes. */ + ulist->root = RB_ROOT; for (i = 0; i < ulist->nnodes; i++) { ret = ulist_rbtree_insert(ulist, &ulist->nodes[i]); if (ret < 0)