From patchwork Thu Apr 14 14:37:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 8837981 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 78A97C0554 for ; Thu, 14 Apr 2016 14:39:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6BF620166 for ; Thu, 14 Apr 2016 14:39:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3AE920173 for ; Thu, 14 Apr 2016 14:39:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932379AbcDNOiO (ORCPT ); Thu, 14 Apr 2016 10:38:14 -0400 Received: from mga02.intel.com ([134.134.136.20]:46752 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932106AbcDNOiJ (ORCPT ); Thu, 14 Apr 2016 10:38:09 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 14 Apr 2016 07:37:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,485,1455004800"; d="scan'208";a="945178736" Received: from unknown (HELO thog.int.wil.cx) ([10.254.90.221]) by fmsmga001.fm.intel.com with SMTP; 14 Apr 2016 07:37:27 -0700 Received: by thog.int.wil.cx (Postfix, from userid 1000) id E615B5FC01; Thu, 14 Apr 2016 10:37:24 -0400 (EDT) From: Matthew Wilcox To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Konstantin Khlebnikov , Kirill Shutemov , Jan Kara , Neil Brown , Ross Zwisler Subject: [PATCH 05/19] radix-tree: Remove a use of root->height from delete_node Date: Thu, 14 Apr 2016 10:37:08 -0400 Message-Id: <1460644642-30642-6-git-send-email-willy@linux.intel.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1460644642-30642-1-git-send-email-willy@linux.intel.com> References: <1460644642-30642-1-git-send-email-willy@linux.intel.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.9 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 If radix_tree_shrink returns whether it managed to shrink, then __radix_tree_delete_node doesn't ned to query the tree to find out whether it did any work or not. Signed-off-by: Matthew Wilcox --- lib/radix-tree.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index e963823..f85c8f5 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -1416,8 +1416,10 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item) * radix_tree_shrink - shrink height of a radix tree to minimal * @root radix tree root */ -static inline void radix_tree_shrink(struct radix_tree_root *root) +static inline bool radix_tree_shrink(struct radix_tree_root *root) { + bool shrunk = false; + /* try to shrink tree height */ while (root->height > 0) { struct radix_tree_node *to_free = root->rnode; @@ -1477,7 +1479,10 @@ static inline void radix_tree_shrink(struct radix_tree_root *root) to_free->slots[0] = RADIX_TREE_RETRY; radix_tree_node_free(to_free); + shrunk = true; } + + return shrunk; } /** @@ -1500,11 +1505,8 @@ bool __radix_tree_delete_node(struct radix_tree_root *root, struct radix_tree_node *parent; if (node->count) { - if (node == indirect_to_ptr(root->rnode)) { - radix_tree_shrink(root); - if (root->height == 0) - deleted = true; - } + if (node == indirect_to_ptr(root->rnode)) + deleted |= radix_tree_shrink(root); return deleted; }