From patchwork Tue Mar 19 09:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13596502 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 3C296C54E60 for ; Tue, 19 Mar 2024 09:41:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A92B6B0092; Tue, 19 Mar 2024 05:41:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 439316B0093; Tue, 19 Mar 2024 05:41:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E7C96B0095; Tue, 19 Mar 2024 05:41:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 02BA46B0092 for ; Tue, 19 Mar 2024 05:41:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B26AD140918 for ; Tue, 19 Mar 2024 09:41:49 +0000 (UTC) X-FDA: 81913296738.19.4C329E7 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) by imf28.hostedemail.com (Postfix) with ESMTP id 18BD9C0015 for ; Tue, 19 Mar 2024 09:41:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iw+8pbIq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710841308; h=from:from:sender:reply-to: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=XqzN+wWZGV0/ntTi34b/frY6opMs0aB0oKSPnzSGTOk=; b=NcPxT8uNIOM+A0emtX+NqtX5JsYoIMNK2GC9x8wRrLOApwGlRk1jKuBLWmrXGQDsaCGZKr dQ2e1Q3S1ycjI9ub79BPeH0uW6rWwVt253y3FrZ1moUyzUXNzcez6nzHJ8e5ZlP54DLkPT VBYYzN1o4kcrrWuMBQnfzyyN9S6IcLs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iw+8pbIq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710841308; a=rsa-sha256; cv=none; b=rtQ0Uj/jvLmRtpbwxDKcD4EoRaY9qf4DFqkn7M0RF2iAxFDT21ISjRLBs/iftZZ+4/Tqeq 8Xo1EbWyQWeHCROo/iJZ8I6l8Rmk7sIRzhCdLCmRnSSnuL/UjXzAdHwxOSuKlozspOVWTu XAdC4mFkTncGPkc7qKn6NnLDLDOnQXw= Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3bd72353d9fso3169092b6e.3 for ; Tue, 19 Mar 2024 02:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710841306; x=1711446106; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=XqzN+wWZGV0/ntTi34b/frY6opMs0aB0oKSPnzSGTOk=; b=iw+8pbIqNbWs84QeiUoujuro6YgAmFNtjNvc0OMH0lQm1g0LJXaPEtt9a1Bn//J7yJ oZ2tMZHmxCKgALwS6EWBI/fIqrmunNJc2jkTflV7bOWytCrvcvS3Wu2aVCDIt7R5tfUj DzLFiSPfl1rAhZWnV18/FEVF/GBoUfgjKQXBRxz6ydLfgviANnLWpveNQn+/hnj7vwy4 I1DeFZlGFoC4dGL4L11PpDba5rFQ8SFN3/+jXZp4fHorhZ5z4lyq/QxtlGr2FQxc6Dyk 7GhLPocuLyFqcPlATodxhsNSKc3V83nQ3VfqfDQsTx5Yv+KoSQzj2+qWn95iVLqVJBfC axqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710841306; x=1711446106; h=content-transfer-encoding:mime-version:reply-to: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=XqzN+wWZGV0/ntTi34b/frY6opMs0aB0oKSPnzSGTOk=; b=K99/FCt/OEs3qTrOIlF45gvfJcUZ2Ia8Fqza4hPPhxssQW/He744wYSsnGVI7n3oLF SRaYMaYiOfPhojxn/ytBkX/VbfuitqzEzToNW16FabIn6KqiNO7+i1lUmXPBC6GNP3nn Rvsd79ZJ4uuekL739Buv1Dber2NMh92ijucJmLLpiPKjaInWM6VhySRnNTktKnxybfD1 WXQbZH+rnmDCWBoJsI/gn3tevWjbJYodmU79m78UqSPzPsknlWsgI3CxXXzzoqbTdenP g063wzKnGSLLTwcOwPrXr8FwyNoX+1G0ltchb6pPSVl+pLUtg+UQidxC+z6VwCyj2xs3 wMtw== X-Gm-Message-State: AOJu0Yyyqv8fj06Wy2eHap8RA0N0DBjFlsUEmFjlwUeksBonx1fJuPw1 XzRywXvSJj2P312TM+pynsfGphOwaudJMCtjtGVFUMPBBmJZrqeBXMGsOIqyVDipWjub X-Google-Smtp-Source: AGHT+IFpWzLUcgwPhIA7GrafY8so+K48aVsYG/cukRTuKwm2t4oZkaJoNlfObveyt98ye1pVmlIUsQ== X-Received: by 2002:a05:6808:180b:b0:3c3:82c3:ddcc with SMTP id bh11-20020a056808180b00b003c382c3ddccmr2678100oib.31.1710841306463; Tue, 19 Mar 2024 02:41:46 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id i185-20020a62c1c2000000b006e583a649b4sm9708761pfg.210.2024.03.19.02.41.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 19 Mar 2024 02:41:46 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 3/4] lib/xarray: introduce a new helper xas_get_order Date: Tue, 19 Mar 2024 17:27:32 +0800 Message-ID: <20240319092733.4501-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240319092733.4501-1-ryncsn@gmail.com> References: <20240319092733.4501-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 3oan8zx9wcop1zhypnpbfss3ysoncwuc X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 18BD9C0015 X-HE-Tag: 1710841307-733918 X-HE-Meta: U2FsdGVkX1/66N9wDHlyUbJTS0E7ifbZbGdLUoBAMm1cdhlWiTCDSeIdY2Xg7Lb2JUEE+7EYJqCeVVCd2aMsD9zJNW2VImUWMMW81dDfOe5hRnOkhvrY25jfYZIZWs3jFQb0gus1q2gMq+fhfV+ZIpEXFtrTTenkkjKbqMcRPyJRO4/imDbcLfO1/HB62M7BGr6amxwAP93cXhlPsY9mcVywe5kgjlrBvoKKGfUPjeAsFtkE4zXnhiBlxKxfTmt0uoToPO+qfdJjGTNPIZkfEfaYEJymF4TsSZ9m2UKhwEYxTzo9H8krSE/dexLsOyHOFUE3UkTX6P3YXsU3srFGTgYg0NyygMBlJ8a73xdo9QlSYfovIRnmfwHE0X/BNgUJ3HFC4oXCtrOvlYFmRt4iXzIh4FHgGW9pAx4X0wS5KYgfEUREjlYpKWLChi3JDopGZeuK7twZgZJxV9ITDQhNV1iNDwuaeuDqOhLQgXyP43OuNrhOq5YB5bxvA1KX2VHGqdtIagftGgoWBHkqGDUMQ7qz6bR7446el3hoO5zzXg9cZN6pyuXMUq43WUvLAhWDtPPVGfB+YT2PbCLE4VAWJ9+QS2rkZiQGHBbGjSEzries+S4XLNOdYspCW/z7uXoUUkswn4g8s5+5AzB4b/F3kXKLJiA3kwPXoGpRlPa3BRvGKo1Edls4qs1zYo2IJ03PJbXr85sieANknfDMHz9MZsKMBZqr+qVjd7BEraYSCL9MVoiErVlWbV0iTMlbnVZ2QNyp8rS2NuJ+f3EfK+7GpUcICj9MsS8HnhyLuONPbcMy/Xd1UomjIsUs7Tb2wzBeykJXlIHgfehotQ0/ehG+O7uyin1rJngdUFG3WFC2ufXzaahLCNSXoSjTY9g5lip/juth/whiFuD1T1IAzMsSPV8gZ07JaAUuCp6gqHc4VGXWLO2Av7o1oj7aPPry4x0cA1BQE1pNbvsj7Vnt42H 1y2B7CMK btyYZ7nU2cDDTqS0ILjUhWR1e6y749oJR8kuDnldILBGegpI1LhaUiNJfY7lpmXo3q9o4K0xAsWu4LMGoEuz6GhnlyRkIhoemWqK+s9T5uNx5Hnv27fAy/7IBpjMef6A1cIBKV5xHWn/+WYZOuWfiH86uD8ZCOuTc8MrVJeKxjqmWCeJ6DtioT22qGyG/l5HmKzHGlCmG2SqiKfqVhu2lwIxbumQDqAsnczucyryOyovCBsCrhUqcp5TKiipNNGRjDsYi5q1Atp5rLdD25EaSPK1hwoyx2HwKfqYb+yb0Gcd1I2rwAF8rWEn/hQ== 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: List-Subscribe: List-Unsubscribe: From: Kairui Song It can be used after xas_load to check the order of loaded entries. Compared to xa_get_order, it saves an XA_STATE and avoid a rewalk. Signed-off-by: Kairui Song Acked-by: Matthew Wilcox (Oracle) --- include/linux/xarray.h | 6 ++++++ lib/xarray.c | 49 ++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index cb571dfcf4b1..d9d479334c9e 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1548,6 +1548,7 @@ void xas_create_range(struct xa_state *); #ifdef CONFIG_XARRAY_MULTI int xa_get_order(struct xarray *, unsigned long index); +int xas_get_order(struct xa_state *xas); void xas_split(struct xa_state *, void *entry, unsigned int order); void xas_split_alloc(struct xa_state *, void *entry, unsigned int order, gfp_t); #else @@ -1556,6 +1557,11 @@ static inline int xa_get_order(struct xarray *xa, unsigned long index) return 0; } +static inline int xas_get_order(struct xa_state *xas) +{ + return 0; +} + static inline void xas_split(struct xa_state *xas, void *entry, unsigned int order) { diff --git a/lib/xarray.c b/lib/xarray.c index 39f07bfc4dcc..88fbea481e1b 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1750,39 +1750,52 @@ void *xa_store_range(struct xarray *xa, unsigned long first, EXPORT_SYMBOL(xa_store_range); /** - * xa_get_order() - Get the order of an entry. - * @xa: XArray. - * @index: Index of the entry. + * xas_get_order() - Get the order of an loaded entry after xas_load. + * @xas: XArray operation state. + * + * Called after xas_load, the xas should not be in an error state. * * Return: A number between 0 and 63 indicating the order of the entry. */ -int xa_get_order(struct xarray *xa, unsigned long index) +int xas_get_order(struct xa_state *xas) { - XA_STATE(xas, xa, index); - void *entry; int order = 0; - rcu_read_lock(); - entry = xas_load(&xas); - - if (!entry) - goto unlock; - - if (!xas.xa_node) - goto unlock; + if (!xas->xa_node) + return 0; for (;;) { - unsigned int slot = xas.xa_offset + (1 << order); + unsigned int slot = xas->xa_offset + (1 << order); if (slot >= XA_CHUNK_SIZE) break; - if (!xa_is_sibling(xas.xa_node->slots[slot])) + if (!xa_is_sibling(xas->xa_node->slots[slot])) break; order++; } - order += xas.xa_node->shift; -unlock: + order += xas->xa_node->shift; + return order; +} +EXPORT_SYMBOL(xas_get_order); + +/** + * xa_get_order() - Get the order of an entry. + * @xa: XArray. + * @index: Index of the entry. + * + * Return: A number between 0 and 63 indicating the order of the entry. + */ +int xa_get_order(struct xarray *xa, unsigned long index) +{ + XA_STATE(xas, xa, index); + int order = 0; + void *entry; + + rcu_read_lock(); + entry = xas_load(&xas); + if (entry) + order = xas_get_order(&xas); rcu_read_unlock(); return order;