From patchwork Thu Nov 14 17:05:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sid Kumar X-Patchwork-Id: 13875510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABDD8D637D4 for ; Thu, 14 Nov 2024 17:07:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A81E6B00A3; Thu, 14 Nov 2024 12:07:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 257896B00B3; Thu, 14 Nov 2024 12:07:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11F956B00B4; Thu, 14 Nov 2024 12:07:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E58B06B00A3 for ; Thu, 14 Nov 2024 12:07:52 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9D048ACB5D for ; Thu, 14 Nov 2024 17:07:52 +0000 (UTC) X-FDA: 82785331482.22.DBF95C7 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf22.hostedemail.com (Postfix) with ESMTP id CEF2EC0095 for ; Thu, 14 Nov 2024 17:04:36 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Z1GCbDs1; spf=pass (imf22.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731603738; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DRxKYAZcCAMW15klVCiRiGLQ4sjCSB7uPPfv42IObWU=; b=8V5hr4vkz5OFUFybuN1ov+ffyWyqkq+u6k7+ZSDEchWy25lZEBH9dj2yFKzkXGowuQlUNj 4CRA0gO8HV0l1OZ91NWm+BNX0wNZUODM5bw5XJBXyZptZWbc9iCdilbJB97FBIerne/n+0 Nbhi1/pVzK/BtGq82I9nJI+gjLYd+ag= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Z1GCbDs1; spf=pass (imf22.hostedemail.com: domain of sidhartha.kumar@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=sidhartha.kumar@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731603738; a=rsa-sha256; cv=none; b=0PaJdLhyWcMZOSV5Sk1cHeV89zPCU2y5e6f8HcY5TVZ+tq8WnnEdH1TK8BURIquRCwWLtL 8irEe4DuoyoUCTnXPXFfRb92d60qZ8EcfnNbUy+smCGaTtzVRG50dLG7NXF57dcn4kSI3h qiZ6nRBrweV704WVRtUBKf71QlWNGw4= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AECXUrQ006704; Thu, 14 Nov 2024 17:05:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2023-11-20; bh=DRxKY AZcCAMW15klVCiRiGLQ4sjCSB7uPPfv42IObWU=; b=Z1GCbDs1t6Vnl15y76+He YuuuRLWsnt6ujrK8hIL0wKm6QgjMSzD6h7Tjgc1Xm7khuxNP+Hgjayvnbjt8xKnU DxFL/DSVy9o5tug+xlQ9747gU6GyPoTnz20jD062hvdhwd3rASi+9JS3sbhJmPMT UvIJ8pnD/Azc0C+zp0CMhjozcMPgY4RLb/dhMZkRG4nj5tK4y0dy/hexXmcY4VD0 4WDFWvEEgHkU0R4NfJ1MMhzmAas7WkucuXgxfEgjTu6n8ouz8unaoGARYjd6tcUv CUPHMFKg6WA4SDhfolG/ZWrnQcfr7mId9fiDCROu6av6cPGOdFyBHNDY800JbZ2o g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42t0nwsr6n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Nov 2024 17:05:30 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4AEGGpAX022744; Thu, 14 Nov 2024 17:05:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42vuw1jy83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Nov 2024 17:05:29 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 4AEH5QmL032739; Thu, 14 Nov 2024 17:05:28 GMT Received: from sidkumar-mac.us.oracle.com (dhcp-10-39-201-66.vpn.oracle.com [10.39.201.66]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 42vuw1jy5w-3; Thu, 14 Nov 2024 17:05:28 +0000 From: Sidhartha Kumar To: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, liam.howlett@oracle.com, Sidhartha Kumar Subject: [PATCH 2/5] maple_tree: use height and depth consistently Date: Thu, 14 Nov 2024 12:05:21 -0500 Message-ID: <20241114170524.64391-3-sidhartha.kumar@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241114170524.64391-1-sidhartha.kumar@oracle.com> References: <20241114170524.64391-1-sidhartha.kumar@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-14_05,2024-11-13_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=975 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411140134 X-Proofpoint-GUID: 7jgAwCWQElIyqGhjSvDnTmTu9MQckSbD X-Proofpoint-ORIG-GUID: 7jgAwCWQElIyqGhjSvDnTmTu9MQckSbD X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CEF2EC0095 X-Stat-Signature: k5t111hyp9sru845wyhxtcrsp1ftrmtx X-Rspam-User: X-HE-Tag: 1731603876-85094 X-HE-Meta: U2FsdGVkX18xVBYBRVVnbS12o4svfwAFej/sAStyOiUq4zKMA3bfIBoWNRupRbaAf/LHv8tBiVA3zioEyhPxb+lstjNOXo+fNsAX6kp7B6ExMT7kfsTP7HRcN5V3IjZdixzQS2OqBlf1AJBr6M5In29HX1D/QJQu8qZJVzfRFh20Ym98+kVIQmoDToZswqcYmhPIlB4Z4bBQAMoaqRJLqwz/QSDB0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sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: For the maple tree, the root node is defined to have a depth of 0 with a height of 1. Each level down from the node, these values are incremented by 1. Various code paths define a root with depth 1 which is inconsisent with the definition. Modify the code to be consistent with this definition. Signed-off-by: Sidhartha Kumar --- lib/maple_tree.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 318d496debd7..21289e350382 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -211,14 +211,14 @@ static void ma_free_rcu(struct maple_node *node) call_rcu(&node->rcu, mt_free_rcu); } -static void mas_set_height(struct ma_state *mas) +static void mt_set_height(struct maple_tree *mt, unsigned char height) { - unsigned int new_flags = mas->tree->ma_flags; + unsigned int new_flags = mt->ma_flags; new_flags &= ~MT_FLAGS_HEIGHT_MASK; - MAS_BUG_ON(mas, mas->depth > MAPLE_HEIGHT_MAX); - new_flags |= mas->depth << MT_FLAGS_HEIGHT_OFFSET; - mas->tree->ma_flags = new_flags; + MT_BUG_ON(mt, height > MAPLE_HEIGHT_MAX); + new_flags |= height << MT_FLAGS_HEIGHT_OFFSET; + mt->ma_flags = new_flags; } static unsigned int mas_mt_height(struct ma_state *mas) @@ -1375,7 +1375,6 @@ static inline struct maple_enode *mas_start(struct ma_state *mas) root = mas_root(mas); /* Tree with nodes */ if (likely(xa_is_node(root))) { - mas->depth = 1; mas->status = ma_active; mas->node = mte_safe_root(root); mas->offset = 0; @@ -1727,7 +1726,7 @@ static inline void mas_put_in_tree(struct ma_state *mas, if (mte_is_root(mas->node)) { mas_mn(mas)->parent = ma_parent_ptr(mas_tree_parent(mas)); rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); - mas_set_height(mas); + mt_set_height(mas->tree, mas->depth + 1); } else { offset = mte_parent_slot(mas->node); @@ -2888,12 +2887,12 @@ static void mas_spanning_rebalance(struct ma_state *mas, */ memset(mast->bn, 0, sizeof(struct maple_big_node)); mast->bn->type = mte_node_type(left); - l_mas.depth++; /* Root already stored in l->node. */ if (mas_is_root_limits(mast->l)) goto new_root; + l_mas.depth++; mast_ascend(mast); mast_combine_cp_left(mast); l_mas.offset = mast->bn->b_end; @@ -3141,7 +3140,7 @@ static inline void mas_split_final_node(struct maple_subtree_state *mast, mast->bn->type = maple_arange_64; else mast->bn->type = maple_range_64; - mas->depth = height; + mas->depth = height - 1; } /* * Only a single node is used here, could be root. @@ -3308,6 +3307,7 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node) { struct maple_subtree_state mast; int height = 0; + unsigned int orig_height = mas_mt_height(mas); unsigned char mid_split, split = 0; struct maple_enode *old; @@ -3334,7 +3334,6 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node) MA_STATE(prev_r_mas, mas->tree, mas->index, mas->last); trace_ma_op(__func__, mas); - mas->depth = mas_mt_height(mas); mast.l = &l_mas; mast.r = &r_mas; @@ -3342,7 +3341,7 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node) mast.orig_r = &prev_r_mas; mast.bn = b_node; - while (height++ <= mas->depth) { + while (height++ <= orig_height) { if (mt_slots[b_node->type] > b_node->b_end) { mas_split_final_node(&mast, mas, height); break; @@ -3439,8 +3438,7 @@ static inline void mas_root_expand(struct ma_state *mas, void *entry) if (mas->last != ULONG_MAX) pivots[++slot] = ULONG_MAX; - mas->depth = 1; - mas_set_height(mas); + mt_set_height(mas->tree, 1); ma_set_meta(node, maple_leaf_64, 0, slot); /* swap the new root into the tree */ rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); @@ -3684,8 +3682,7 @@ static inline void mas_new_root(struct ma_state *mas, void *entry) WARN_ON_ONCE(mas->index || mas->last != ULONG_MAX); if (!entry) { - mas->depth = 0; - mas_set_height(mas); + mt_set_height(mas->tree, 0); rcu_assign_pointer(mas->tree->ma_root, entry); mas->status = ma_start; goto done; @@ -3699,8 +3696,7 @@ static inline void mas_new_root(struct ma_state *mas, void *entry) mas->status = ma_active; rcu_assign_pointer(slots[0], entry); pivots[0] = mas->last; - mas->depth = 1; - mas_set_height(mas); + mt_set_height(mas->tree, 1); rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); done: