Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4428828rwb; Mon, 31 Jul 2023 06:51:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlGdRxejMmC9984UaWEYuN1EQxDtWqiPJfXGg/y1nGlu5/YRyFVknA0r7kdI4dyLi52xse7x X-Received: by 2002:a05:6512:3b83:b0:4fd:fafd:1ed4 with SMTP id g3-20020a0565123b8300b004fdfafd1ed4mr6431100lfv.2.1690811506039; Mon, 31 Jul 2023 06:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690811506; cv=none; d=google.com; s=arc-20160816; b=m7FjDZk850mZ8qggVBQOU9X/kkkPzdJtIzElh0AioAmsV1tCH+58afhUZA0F/XLBkY 7Ni5Wik2BcCAuMqoKdCsibsDMk+vzAf5BEEKVpVQDZL2q4i25vvVoz3QlYYpdjRj3hc5 5XTYUOJYc9DoXA6II/xndcaZTACy83V6PMCpQfKKqtIu0YQFDFmW/6mQfMINkAqmEv6b l5WovoxVGa59NbVr2jIMDLdJpZSMnFBfxoG/Kxu38BA0eP12IB6d/gW13ae2invXmzar J55/1DrqHwA+Z0paOe6n0bU/84gDGanzGWyQqeDduy6jnvL79r1hVrmTUxy0uR6n5+u8 1DlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc :references:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=NbHaBnPJTBufVAwcPj+/e51E470qMaDLfU8RAgBBrSo=; fh=36tutxiKNQlWEakN3RLL7WyUzcYCgTwpOWvFtOGBkcs=; b=Pm8Nijr+qu15wvpd62vAsPos5X45GTpaZUz/G1YVLVinToQ/Th6EGS9w/BUK3DzgJm patmIo8pz+Ic8dcy/q6/CvU2p5rI77N1NE3YoHbnSfBB9JV/gUognigW3LcMvqv208hR IqKF3YCa9XjCoiqOsksqzLb6rIQvZ7CIIevNzGaBiEkZf8rsrA7w8L3Ps0EgqG4YVigG S3yUjbYsMrO0i3rhkdHRJnq/ECuMtFYePKL6cZMk45VqAcuMZ5B131rapzZJVBnlJAWl Aln24la5r5V/PyjJDgyWJkWoOUd0IDaDbXLa5UJ0CKIFih2WdafYk9mT3qaEfHLJsv4U 0ZhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Oqhj9+7q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm28-20020a0564020b1c00b0052228721f74si2674631edb.264.2023.07.31.06.51.19; Mon, 31 Jul 2023 06:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Oqhj9+7q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230230AbjGaLk2 (ORCPT + 99 others); Mon, 31 Jul 2023 07:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbjGaLk0 (ORCPT ); Mon, 31 Jul 2023 07:40:26 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEEB2A6; Mon, 31 Jul 2023 04:40:25 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d2e1a72fcca58-686b643df5dso2989121b3a.1; Mon, 31 Jul 2023 04:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690803625; x=1691408425; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=NbHaBnPJTBufVAwcPj+/e51E470qMaDLfU8RAgBBrSo=; b=Oqhj9+7q02O+W9LRy4/w9ygddowj5YGZdAuQcQiAKx8xsYNHClcRtsbok6QS0FT7o5 EnqTLOZQ2khabaT7z9Y7sb4fRTsSVX1bDX522xRb1/pB6hkHuKktWo6tgpdO5UrJ+mVa yamBHZxv6GhHgFm+mFHhNbceYYuLchQPstzfFsuHCcE4ahCOp+1jICpS8uWPKscCPIK2 lf51aYlmtmTfGIhtv1APtO6vSJrqsEq029SRG5gJ1Ak717eq5rbbpcAyxJaiRocDTPzT +PTy+sMzbnntJxzHX6SLblNYGLcritk1DuTMBjbjSc7spgbtTQ4U357QI6CCDHdnBlZt V/zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690803625; x=1691408425; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=NbHaBnPJTBufVAwcPj+/e51E470qMaDLfU8RAgBBrSo=; b=IvNVIG+IiCG58ug5YHoZoqa5d1wKnMPhu+3GSzywyni9sku/DLloZ8S2jeeZ4aIk9z 08J7hdh/jB13i+fLVhKOry5OcRkZ/fGkEBm0MZgo5Ot4o9+VrJiTq4gfRkSsbHPxthPU 94+kMDkWxg8FU1PzDdop/fNNZ5TKLWtbcNpQx3blgqOmrb9ak5Cp9mkoqk5SaT09EaFq qjhFWIp46WpmWarE1dsotfZElmho+lsAcmc6/PeBWii7XTbxRcl67sDO8TuqPCilxMv0 xC+HmUbtz4gzNPQs67FMN4ARivdK7ZOlunCFEQPAqxzvc7Wbzknqz5iD0NNlTR7n3Y9o DvJA== X-Gm-Message-State: ABy/qLadRyCLiiGPa3NW043+GEZdszw1v2fZXNYNuZ3hkjxpx1lnORe0 IUC/5KZf2QiEBOwgjerVg1E= X-Received: by 2002:a05:6a20:9151:b0:13b:79dc:4538 with SMTP id x17-20020a056a20915100b0013b79dc4538mr9899227pzc.62.1690803625084; Mon, 31 Jul 2023 04:40:25 -0700 (PDT) Received: from [10.90.34.137] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id e11-20020a63ae4b000000b00563962dbc70sm792422pgp.58.2023.07.31.04.40.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jul 2023 04:40:24 -0700 (PDT) Message-ID: Date: Mon, 31 Jul 2023 19:40:16 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.1 Subject: Re: [PATCH 03/11] maple_tree: Add some helper functions To: "Liam R. Howlett" References: <20230726080916.17454-1-zhangpeng.00@bytedance.com> <20230726080916.17454-4-zhangpeng.00@bytedance.com> <20230726150252.x56owgz3ikujzicu@revolver> Cc: peterz@infradead.org, mathieu.desnoyers@efficios.com, brauner@kernel.org, Peng Zhang , surenb@google.com, linux-kernel@vger.kernel.org, npiggin@gmail.com, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org, corbet@lwn.net, willy@infradead.org, linux-mm@kvack.org, avagin@gmail.com, michael.christie@oracle.com From: Peng Zhang In-Reply-To: <20230726150252.x56owgz3ikujzicu@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2023/7/26 23:02, Liam R. Howlett 写道: > * Peng Zhang [230726 04:10]: >> 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); >> +} >> + > > There is a place in mas_destroy() that could use this if it is added. I will make changes accordingly. It's not done here because it doesn't seem to be relevant to the theme of this patchset. > >> 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) > > I was trying to keep ma_* prefix to mean the first argument is > maple_node and mt_* to mean maple_tree. I wasn't entirely successful > with this and I do see why you want to use ma_, but maybe reverse the > arguments here? I just think it is redundant to construct maple enode through node->parent in order to adapt the parameters of mte_*. So ma_* are introduced to avoid meaningless construction. > >> { >> 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) > > I had a lot of these helpers before, but they eventually became used so > little that I dropped them. Just for not wanting to construct maple enode. It's not really a problem. > >> +{ >> + 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 >>