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 X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACB80C433E2 for ; Thu, 3 Sep 2020 18:30:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4BD7620709 for ; Thu, 3 Sep 2020 18:30:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="pHCQOoWf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BD7620709 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DDACE6B007E; Thu, 3 Sep 2020 14:30:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8991900004; Thu, 3 Sep 2020 14:30:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C51136B0082; Thu, 3 Sep 2020 14:30:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id ACC5D6B007E for ; Thu, 3 Sep 2020 14:30:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6EB7B1EFF for ; Thu, 3 Sep 2020 18:30:57 +0000 (UTC) X-FDA: 77222591754.19.point82_0c1452c270ab Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 272511ACEBC for ; Thu, 3 Sep 2020 18:30:57 +0000 (UTC) X-HE-Tag: point82_0c1452c270ab X-Filterd-Recvd-Size: 4836 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Sep 2020 18:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=uAcIbAnv5dO2Pwhu3FPlWxgDPUCordW26Drx8aLRYGI=; b=pHCQOoWfmDks5vOiJoTcFJOwZ4 rrm2UaS2zy7P2x33sdtDUyArHPBkcq5ZczmGtk3VDELF0pq97FIGsLe6SkPDFx+glOTutm7LEM6EK 0q0WlbJo7NQzaw71Ri/GzvA0Ylrft0rk64nJNOQuYOKJkOnhavQgkyqlAztT8Bnk4W2OlhGOAmcBH NhEXYSUDLcFrHAUKgFK+IF7vIok2injwFRpChQWJJM50ylaLx2h9LxI4eI6f5HfK+1bpS4eyLtOsM UKhPvkEPeszn9o11Lt+YvaemcI06687sr20fctr8ZJwhoUatpNA2baU2aJJtmVz0tGwJcwu7VjIOz P3RdD71A==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDu0Q-0003u0-Un; Thu, 03 Sep 2020 18:30:43 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Song Liu , "Kirill A . Shutemov" , Qian Cai Subject: [PATCH 1/3] XArray: Add xa_get_order Date: Thu, 3 Sep 2020 19:30:27 +0100 Message-Id: <20200903183029.14930-2-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200903183029.14930-1-willy@infradead.org> References: <20200903183029.14930-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 272511ACEBC X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable 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: This function returns the order of the entry at the index. We need this because there isn't space in the shadow entry to encode its order. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/xarray.h | 9 +++++++++ lib/test_xarray.c | 21 +++++++++++++++++++++ lib/xarray.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index b4d70e7568b2..5b7f4ebcf4ff 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1505,6 +1505,15 @@ void xas_pause(struct xa_state *); =20 void xas_create_range(struct xa_state *); =20 +#ifdef CONFIG_XARRAY_MULTI +int xa_get_order(struct xarray *, unsigned long index); +#else +static inline int xa_get_order(struct xarray *xa, unsigned long index) +{ + return 0; +} +#endif + /** * xas_reload() - Refetch an entry from the xarray. * @xas: XArray operation state. diff --git a/lib/test_xarray.c b/lib/test_xarray.c index d4f97925dbd8..bdd4d7995f79 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -1649,6 +1649,26 @@ static noinline void check_account(struct xarray *= xa) #endif } =20 +static noinline void check_get_order(struct xarray *xa) +{ + unsigned int max_order =3D IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; + unsigned int order; + unsigned long i, j; + + for (i =3D 0; i < 3; i++) + XA_BUG_ON(xa, xa_get_order(xa, i) !=3D 0); + + for (order =3D 0; order < max_order; order++) { + for (i =3D 0; i < 10; i++) { + xa_store_order(xa, i << order, order, + xa_mk_index(i << order), GFP_KERNEL); + for (j =3D i << order; j < (i + 1) << order; j++) + XA_BUG_ON(xa, xa_get_order(xa, j) !=3D order); + xa_erase(xa, i << order); + } + } +} + static noinline void check_destroy(struct xarray *xa) { unsigned long index; @@ -1697,6 +1717,7 @@ static int xarray_checks(void) check_reserve(&array); check_reserve(&xa0); check_multi_store(&array); + check_get_order(&array); check_xa_alloc(); check_find(&array); check_find_entry(&array); diff --git a/lib/xarray.c b/lib/xarray.c index e9e641d3c0c3..b8cc769cefc0 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1592,6 +1592,45 @@ void *xa_store_range(struct xarray *xa, unsigned l= ong first, return xas_result(&xas, NULL); } EXPORT_SYMBOL(xa_store_range); + +/** + * 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); + void *entry; + int order =3D 0; + + rcu_read_lock(); + entry =3D xas_load(&xas); + + if (!entry) + goto unlock; + + if (!xas.xa_node) + goto unlock; + + for (;;) { + unsigned int slot =3D xas.xa_offset + (1 << order); + + if (slot >=3D XA_CHUNK_SIZE) + break; + if (!xa_is_sibling(xas.xa_node->slots[slot])) + break; + order++; + } + + order +=3D xas.xa_node->shift; +unlock: + rcu_read_unlock(); + + return order; +} #endif /* CONFIG_XARRAY_MULTI */ =20 /** --=20 2.28.0