From mboxrd@z Thu Jan 1 00:00:00 1970 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 ADD93C001DC for ; Wed, 26 Jul 2023 08:10:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E4496B0078; Wed, 26 Jul 2023 04:10:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46D886B007B; Wed, 26 Jul 2023 04:10:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30ECE6B007D; Wed, 26 Jul 2023 04:10:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1FBCA6B0078 for ; Wed, 26 Jul 2023 04:10:10 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E784A1C8D4D for ; Wed, 26 Jul 2023 08:10:09 +0000 (UTC) X-FDA: 81053040138.23.FF52374 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by imf08.hostedemail.com (Postfix) with ESMTP id 1BF75160008 for ; Wed, 26 Jul 2023 08:10:07 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kOcNz33W; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.161.42 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690359008; 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=qZrshQXwnAab1vq3lU/ajvCxU9+VU+QRXf7AvvzKBtQ=; b=RLkHHb7s7/V2eSzAQepnsv0tV8ZsmzkHhrZsuCgfXvG/NlTTJomJNqUwS9R5b+aJOEIOIb 5F7DKAS4lWMar1JLGMcieexUe21w4HMyQklbGZy5z95iZS4wDOJvSWHfhTr/mO+RWTLpr3 4Moj8lmy1lsK7tBdbkQbvZHAHA7Q+s4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kOcNz33W; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.161.42 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690359008; a=rsa-sha256; cv=none; b=5EoyNKr8nUxx/lfPkNxCNA15put25opveObateDtdze29lkM/5lZEJJ71Kg6ia0Pjo6BH7 ouP31rmmR7ClQIg0hPP2/0pVA1H6uEMVMUpfi7xmJ7gCIsMWYJwVM9wR6Vp8b7vXBN05W6 oE8SJw03oRxF/5lGjmu2XNj8ZZVnxS0= Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-565f2567422so3860172eaf.2 for ; Wed, 26 Jul 2023 01:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690359007; x=1690963807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qZrshQXwnAab1vq3lU/ajvCxU9+VU+QRXf7AvvzKBtQ=; b=kOcNz33W7J/uTghRxfKlgF2t8o8j/nb23QuZ5yZKbuyUJEAo08ew/cyJIJar+ZMNgI tgX5YgFX3m0skq8DC+gLxzllvMuDg70EjDBiGJDh1Mpz7+05ViTUmcEq2WUbohgItCxV YzHy4oRBemHEGHrvA5A3alCBAqXAz65/Txxwwd4nWao7MA8/0+hF3gmQ7txN/UghIKky 8G26vNuHfNxrsQXaTfctaOFa7a6rjySrzwk2OVDEFJEhTEGkky1CjAN/cm37djIrSV0x 6o0qqSUTea0zqTSaIEA6OD8+/F51B8lA3bJ3ibFJVMxXHbff0W8kAffd204aDfDk8A1R +z4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690359007; x=1690963807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qZrshQXwnAab1vq3lU/ajvCxU9+VU+QRXf7AvvzKBtQ=; b=apl6mPYQ2Ml8V1ESdBUYfm7vDKaavMA9xnAq6zQPA0E7aK2yQyw5CM1fhAby3lj22F PUnGsqUM+mtUZaRmBFWZCdSl+O02G/8u0ihObEHcXp3e/Wm/DrM1PT2k7JBaj8uVa0MK T/eiIUR4EQ62+Rni7zmkb3tV8CMfL6zBM9GzTu9Nr3Xewavy3XnQ9YZMZ+SRDODXLFQu yVLx3JkPgFeEiZ50i20bHkjEFDi/iJKOfJ+zu+kOShD8BqkS4kSSWYRlkkYWDr17uu9t T1jTf8/B2n65uby9gYk4hY5gJVfG6QVJzof7EHksHZ01LWnQ+8Ah3FQ3YZEU5M69YjvA wJMA== X-Gm-Message-State: ABy/qLYhrQh1Zhx1MhvLw5HSKiWozWu8Le1caBbMGuixpSwStiYaBbSH zCZTJQTxy/sBK2bp3Reh3uhPFg== X-Google-Smtp-Source: APBJJlFLmfT+cuxvJMJSvIXCYHo32FQ7ykqGokpbQY3Wi2ttJPt4o99SYQCfgC/jOX0M+MMpT8vadQ== X-Received: by 2002:a05:6358:2794:b0:133:b33:3b9a with SMTP id l20-20020a056358279400b001330b333b9amr1284440rwb.3.1690359006957; Wed, 26 Jul 2023 01:10:06 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id gc17-20020a17090b311100b002680b2d2ab6sm756540pjb.19.2023.07.26.01.10.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 26 Jul 2023 01:10:06 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com, corbet@lwn.net, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, surenb@google.com, michael.christie@oracle.com, peterz@infradead.org, mathieu.desnoyers@efficios.com, npiggin@gmail.com, avagin@gmail.com Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Peng Zhang Subject: [PATCH 03/11] maple_tree: Add some helper functions Date: Wed, 26 Jul 2023 16:09:08 +0800 Message-Id: <20230726080916.17454-4-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230726080916.17454-1-zhangpeng.00@bytedance.com> References: <20230726080916.17454-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1BF75160008 X-Stat-Signature: zfnrg3ch9kmw3bm38sbpo77s8pwkeq7b X-Rspam-User: X-HE-Tag: 1690359007-337126 X-HE-Meta: U2FsdGVkX18OViYDDCRxxqZAsKNkYV4w3bcWgHm2v0K/KeOw1caewqQKD0I3zuqXTz9YZePTUdrXWko7PxhQyBbF4kr5kYb/oaysT/A6t1mHIjKpA37/lrgVD4rAjxXlQeryAvYRwk7cqCkvLNVOYR2C1oEt+xbFf6VrtwdPmMM4MbB2Xvd7KdnJ2akGno2RWgC5kJcXXV6JH4bz7woYuEMNC4L1lC+bQ30xKZPc5N5EGBQ+wfGFwmmrV4LOy1MsdbtthD1jyAijp+8htp+WzZEHZ+q3Og0pDNeEHya2BMF1d7cIvQ020o4cCH2XwpFlYUFHxYcpGgFB+0UcexyASq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370Gjf+mRBnhgpzatb524bTXsarWFqSMczo0gtmu/aoMfYFRbMxg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add some helper functions so that their parameters are maple node instead of maple enode, these functions will be used later. Signed-off-by: Peng Zhang --- lib/maple_tree.c | 71 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index e0e9a87bdb43..da3a2fb405c0 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -164,6 +164,11 @@ static inline int mt_alloc_bulk(gfp_t gfp, size_t size, void **nodes) return kmem_cache_alloc_bulk(maple_node_cache, gfp, size, nodes); } +static inline void mt_free_one(struct maple_node *node) +{ + kmem_cache_free(maple_node_cache, node); +} + static inline void mt_free_bulk(size_t size, void __rcu **nodes) { kmem_cache_free_bulk(maple_node_cache, size, (void **)nodes); @@ -432,18 +437,18 @@ static inline unsigned long mte_parent_slot_mask(unsigned long parent) } /* - * mas_parent_type() - Return the maple_type of the parent from the stored - * parent type. - * @mas: The maple state - * @enode: The maple_enode to extract the parent's enum + * ma_parent_type() - Return the maple_type of the parent from the stored parent + * type. + * @mt: The maple tree + * @node: The maple_node to extract the parent's enum * Return: The node->parent maple_type */ static inline -enum maple_type mas_parent_type(struct ma_state *mas, struct maple_enode *enode) +enum maple_type ma_parent_type(struct maple_tree *mt, struct maple_node *node) { unsigned long p_type; - p_type = (unsigned long)mte_to_node(enode)->parent; + p_type = (unsigned long)node->parent; if (WARN_ON(p_type & MAPLE_PARENT_ROOT)) return 0; @@ -451,7 +456,7 @@ enum maple_type mas_parent_type(struct ma_state *mas, struct maple_enode *enode) p_type &= ~mte_parent_slot_mask(p_type); switch (p_type) { case MAPLE_PARENT_RANGE64: /* or MAPLE_PARENT_ARANGE64 */ - if (mt_is_alloc(mas->tree)) + if (mt_is_alloc(mt)) return maple_arange_64; return maple_range_64; } @@ -459,6 +464,19 @@ enum maple_type mas_parent_type(struct ma_state *mas, struct maple_enode *enode) return 0; } +/* + * mas_parent_type() - Return the maple_type of the parent from the stored + * parent type. + * @mas: The maple state + * @enode: The maple_enode to extract the parent's enum + * Return: The node->parent maple_type + */ +static inline +enum maple_type mas_parent_type(struct ma_state *mas, struct maple_enode *enode) +{ + return ma_parent_type(mas->tree, mte_to_node(enode)); +} + /* * mas_set_parent() - Set the parent node and encode the slot * @enode: The encoded maple node. @@ -499,14 +517,14 @@ void mas_set_parent(struct ma_state *mas, struct maple_enode *enode, } /* - * mte_parent_slot() - get the parent slot of @enode. - * @enode: The encoded maple node. + * ma_parent_slot() - get the parent slot of @node. + * @node: The maple node. * - * Return: The slot in the parent node where @enode resides. + * Return: The slot in the parent node where @node resides. */ -static inline unsigned int mte_parent_slot(const struct maple_enode *enode) +static inline unsigned int ma_parent_slot(const struct maple_node *node) { - unsigned long val = (unsigned long)mte_to_node(enode)->parent; + unsigned long val = (unsigned long)node->parent; if (val & MA_ROOT_PARENT) return 0; @@ -519,15 +537,36 @@ static inline unsigned int mte_parent_slot(const struct maple_enode *enode) } /* - * mte_parent() - Get the parent of @node. - * @node: The encoded maple node. + * mte_parent_slot() - get the parent slot of @enode. + * @enode: The encoded maple node. + * + * Return: The slot in the parent node where @enode resides. + */ +static inline unsigned int mte_parent_slot(const struct maple_enode *enode) +{ + return ma_parent_slot(mte_to_node(enode)); +} + +/* + * ma_parent() - Get the parent of @node. + * @node: The maple node. + * + * Return: The parent maple node. + */ +static inline struct maple_node *ma_parent(const struct maple_node *node) +{ + return (void *)((unsigned long)(node->parent) & ~MAPLE_NODE_MASK); +} + +/* + * mte_parent() - Get the parent of @enode. + * @enode: The encoded maple node. * * Return: The parent maple node. */ static inline struct maple_node *mte_parent(const struct maple_enode *enode) { - return (void *)((unsigned long) - (mte_to_node(enode)->parent) & ~MAPLE_NODE_MASK); + return ma_parent(mte_to_node(enode)); } /* -- 2.20.1