From patchwork Wed Dec 8 04:22:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12663733 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 7BD51C433F5 for ; Wed, 8 Dec 2021 06:30:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B5616B0073; Wed, 8 Dec 2021 01:23:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 416FC6B0075; Wed, 8 Dec 2021 01:23:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B84F6B007D; Wed, 8 Dec 2021 01:23:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay032.a.hostedemail.com [64.99.140.32]) by kanga.kvack.org (Postfix) with ESMTP id 1C4E76B0073 for ; Wed, 8 Dec 2021 01:23:45 -0500 (EST) Received: by unirelay01.hostedemail.com (Postfix, from userid 108) id A6DA960415; Wed, 8 Dec 2021 05:38:45 +0000 (UTC) Received: by unirelay01.hostedemail.com (Postfix, from userid 108) id C2A0F605C7; Wed, 8 Dec 2021 05:32:09 +0000 (UTC) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 949A460A13 for ; Wed, 8 Dec 2021 04:23:19 +0000 (UTC) X-FDA: 78893332518.03.6D48692 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 282654002087 for ; Wed, 8 Dec 2021 04:23:19 +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=p/v1MPFlGwVbfYsmas4PVpJ8hDUuzrJOYjz6XpsPNfA=; b=j7XgVYa7JGB4uUrwY82lww50++ TWoEOzfjKih0daSh1t7pMCCAUT/KcnbdGe+cnlRMSYn2STHxsGZp8bDjnIjcEZccXHJ33ScGqHw3u MdZaS9mX5iOTWIqBuniEOCq03InAsBNLXHwNBmfuHj/mJyg7sad76LC821iIBepHApiXRW1r/ABxa Q3Xv5A25X4Yw9idApTa2hQ3JFqEhD2p5g3RTV/9nRLXJW9KSVJ1sdiRfkH2f94ceM5NVBYmvlD4Ky j48uBakB1VsJvk6TNSxk1BDBSgIZTDPiSBDm1R9zD/OKnouredPIKGwfHhEQ3+3AV7YtHDYclSeKl lgqgVJLQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1muoU8-0084eW-MM; Wed, 08 Dec 2021 04:23:16 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 47/48] XArray: Add xas_advance() Date: Wed, 8 Dec 2021 04:22:55 +0000 Message-Id: <20211208042256.1923824-48-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211208042256.1923824-1-willy@infradead.org> References: <20211208042256.1923824-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=j7XgVYa7; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 282654002087 X-Stat-Signature: 19sz5sgu64r9wfksgnjmh5yqh451h6db X-HE-Tag: 1638937399-834833 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 a new helper function to help iterate over multi-index entries. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/xarray.h | 18 ++++++++++++++++++ lib/xarray.c | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index a91e3d90df8a..d6d5da6ed735 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -1580,6 +1580,24 @@ static inline void xas_set(struct xa_state *xas, unsigned long index) xas->xa_node = XAS_RESTART; } +/** + * xas_advance() - Skip over sibling entries. + * @xas: XArray operation state. + * @index: Index of last sibling entry. + * + * Move the operation state to refer to the last sibling entry. + * This is useful for loops that normally want to see sibling + * entries but sometimes want to skip them. Use xas_set() if you + * want to move to an index which is not part of this entry. + */ +static inline void xas_advance(struct xa_state *xas, unsigned long index) +{ + unsigned char shift = xas_is_node(xas) ? xas->xa_node->shift : 0; + + xas->xa_index = index; + xas->xa_offset = (index >> shift) & XA_CHUNK_MASK; +} + /** * xas_set_order() - Set up XArray operation state for a multislot entry. * @xas: XArray operation state. diff --git a/lib/xarray.c b/lib/xarray.c index f5d8f54907b4..6f47f6375808 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -157,7 +157,7 @@ static void xas_move_index(struct xa_state *xas, unsigned long offset) xas->xa_index += offset << shift; } -static void xas_advance(struct xa_state *xas) +static void xas_next_offset(struct xa_state *xas) { xas->xa_offset++; xas_move_index(xas, xas->xa_offset); @@ -1250,7 +1250,7 @@ void *xas_find(struct xa_state *xas, unsigned long max) xas->xa_offset = ((xas->xa_index - 1) & XA_CHUNK_MASK) + 1; } - xas_advance(xas); + xas_next_offset(xas); while (xas->xa_node && (xas->xa_index <= max)) { if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { @@ -1268,7 +1268,7 @@ void *xas_find(struct xa_state *xas, unsigned long max) if (entry && !xa_is_sibling(entry)) return entry; - xas_advance(xas); + xas_next_offset(xas); } if (!xas->xa_node)