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 C1610C04FDF for ; Mon, 31 Jul 2023 11:40:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0836E280033; Mon, 31 Jul 2023 07:40:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0357A280023; Mon, 31 Jul 2023 07:40:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3E15280033; Mon, 31 Jul 2023 07:40:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D52CB280023 for ; Mon, 31 Jul 2023 07:40:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7FEE3160AD2 for ; Mon, 31 Jul 2023 11:40:28 +0000 (UTC) X-FDA: 81071714136.09.5DEEFB5 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf24.hostedemail.com (Postfix) with ESMTP id 90A4918001C for ; Mon, 31 Jul 2023 11:40:26 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Oqhj9+7q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of perlyzhang@gmail.com designates 209.85.210.193 as permitted sender) smtp.mailfrom=perlyzhang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690803626; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NbHaBnPJTBufVAwcPj+/e51E470qMaDLfU8RAgBBrSo=; b=Wddw2rfC9vi3xAQumBt6PMX86UWrrbr1muqKyOfzSCg5wfHSMt9Tr6PK+U7O63IuEjG9qr TbPSaD8tN3KtMwPI85u33c+d0e0frMCr/IKBUpuPWoIakSsuRXRldwCFxhljOvfwJthkht YIHSueXGqw1wN8zsqWUDBk/tBJE6lrA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Oqhj9+7q; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of perlyzhang@gmail.com designates 209.85.210.193 as permitted sender) smtp.mailfrom=perlyzhang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690803626; a=rsa-sha256; cv=none; b=vWouMmqNODMw8OwqQv36M04VnBb4fxn+8gCOovB+rHmQQU8AVkgN2v9K1ppz5D/vEGL3BT Sy1q+f4cx+jbQofQli+AJXEyKBjvlu1K51x/fLebDYXF0r7r42OAO81DX75x3UFD2ivNRT XiqYx+K1VmAm2sJnFxPh5gCUuGzQxgQ= Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-686daaa5f1fso2974475b3a.3 for ; Mon, 31 Jul 2023 04:40:26 -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=PbgpCg6zDaK8gYFNjrjmlbLlxN1qfdQtmT+xNHOMHIWur5OQS50l5CCfLL/FazYf8M 5coIG43bJ562dsJ3DiFvrIPPSN7P+vP37j+Qt4R2gdMd2iD60DuqzFETXsrTGGAmk0lb +FxK3zGwls0dnLsLhK/xcvsu1EklL2dKDg+3sEdQOSc37ecjngW9D3QY++N2wTcvrn6i ex3wB6xI47Lieg11wRKjfaqiLR6HJruZgXEY8iC/jQ7qWXiQX/xDCI7SdwJ4c1Uyvnlm zume+1hiRPMKXnQRCnna7U5CBcOQg0ZPSBIZk/SPrmU579QI7KA0Hxx4kfnP+rF/qRQ8 Z6kg== X-Gm-Message-State: ABy/qLY9Gjy5eDnxsaJd94RMcqJMDr5tU4o/BzOLksa7C5NTTa1nTmLH hOnNGBNqA8cOMgca7/pCcs0= X-Google-Smtp-Source: APBJJlExlIfJlZY/sSBlcw6EfNRGkZZTwEkZ+JAJ9sqSSJViGVx+t05/p99K9MXZ7/FpPZdW7zHT8w== 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-Rspam-User: X-Stat-Signature: tndhkzteba8p83zdgdc4tuuor8ui9drm X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 90A4918001C X-HE-Tag: 1690803626-39970 X-HE-Meta: U2FsdGVkX1/SO6nMILAfs6cS397b+SnkfddIrEUYHSOoEbnzm7O/9TUNuuPafWm3IqaOcpA0MSgww1nqYvIElSIS1qsiT9TqqQBTBbS2kg8wR13K791UWsCX9SpJwupxzbPar6gRbJX46E6RlxZ7ySAAvLQAgsrdHhgjag7l279GI7qpuQCeXNE5E8ci7kuZLPQDLFEf4wFhRNNcU4SLJ6b4/Ci3Gw/2eX9/yNIDzHYXM3s8tEyZfvvGh4Ter7i5qTP8BFrNC/k35QPvooAoveqbh6SEx0PmAPVgi0M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h5gG0HRIwYcWJ0QZOdFIjxHhfeGrxVIOfrf9GvqmIQoLYJ+UAPO9dWvaJPLOueTahFxCZMlTHDlsDcGCTUXJNpFEzvJ8uyCz3v9oAw8GHf3jdlbLVJPUigdBHtGojrs150oidXvzs6ZXz1QOHQnhUangm27k5CeEyRl 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: 在 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 >>