From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756342AbcDNOR4 (ORCPT ); Thu, 14 Apr 2016 10:17:56 -0400 Received: from mga14.intel.com ([192.55.52.115]:31796 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754261AbcDNORt (ORCPT ); Thu, 14 Apr 2016 10:17:49 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,485,1455004800"; d="scan'208";a="85155909" 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 v2 13/29] radix-tree: Introduce radix_tree_load_root() Date: Thu, 14 Apr 2016 10:16:34 -0400 Message-Id: <1460643410-30196-14-git-send-email-willy@linux.intel.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1460643410-30196-1-git-send-email-willy@linux.intel.com> References: <1460643410-30196-1-git-send-email-willy@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All the tree walking functions start with some variant of this code; centralise it in one place so we're not chasing subtly different bugs everywhere. Signed-off-by: Matthew Wilcox Reviewed-by: Ross Zwisler --- lib/radix-tree.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 6900f7b..272ce81 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -405,6 +405,29 @@ static inline unsigned long radix_tree_maxindex(unsigned int height) return height_to_maxindex[height]; } +static inline unsigned long node_maxindex(struct radix_tree_node *node) +{ + return radix_tree_maxindex(node->path & RADIX_TREE_HEIGHT_MASK); +} + +static unsigned radix_tree_load_root(struct radix_tree_root *root, + struct radix_tree_node **nodep, unsigned long *maxindex) +{ + struct radix_tree_node *node = rcu_dereference_raw(root->rnode); + + *nodep = node; + + if (likely(radix_tree_is_indirect_ptr(node))) { + node = indirect_to_ptr(node); + *maxindex = node_maxindex(node); + return (node->path & RADIX_TREE_HEIGHT_MASK) * + RADIX_TREE_MAP_SHIFT; + } + + *maxindex = 0; + return 0; +} + /* * Extend a radix tree so it can store key @index. */ -- 2.8.0.rc3 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 v2 13/29] radix-tree: Introduce radix_tree_load_root() Date: Thu, 14 Apr 2016 10:16:34 -0400 Message-Id: <1460643410-30196-14-git-send-email-willy@linux.intel.com> In-Reply-To: <1460643410-30196-1-git-send-email-willy@linux.intel.com> References: <1460643410-30196-1-git-send-email-willy@linux.intel.com> Sender: owner-linux-mm@kvack.org List-ID: All the tree walking functions start with some variant of this code; centralise it in one place so we're not chasing subtly different bugs everywhere. Signed-off-by: Matthew Wilcox Reviewed-by: Ross Zwisler --- lib/radix-tree.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 6900f7b..272ce81 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -405,6 +405,29 @@ static inline unsigned long radix_tree_maxindex(unsigned int height) return height_to_maxindex[height]; } +static inline unsigned long node_maxindex(struct radix_tree_node *node) +{ + return radix_tree_maxindex(node->path & RADIX_TREE_HEIGHT_MASK); +} + +static unsigned radix_tree_load_root(struct radix_tree_root *root, + struct radix_tree_node **nodep, unsigned long *maxindex) +{ + struct radix_tree_node *node = rcu_dereference_raw(root->rnode); + + *nodep = node; + + if (likely(radix_tree_is_indirect_ptr(node))) { + node = indirect_to_ptr(node); + *maxindex = node_maxindex(node); + return (node->path & RADIX_TREE_HEIGHT_MASK) * + RADIX_TREE_MAP_SHIFT; + } + + *maxindex = 0; + return 0; +} + /* * Extend a radix tree so it can store key @index. */ -- 2.8.0.rc3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org