Received: by 10.223.164.202 with SMTP id h10csp665491wrb; Wed, 22 Nov 2017 13:19:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ3HQgP10d11VIFusRxI1SaQEeMI6rQJ1wSEOSK2O8WyqfCbSJWaFez0th+CkgFt9Vmqkof X-Received: by 10.84.133.165 with SMTP id f34mr22601196plf.268.1511385581459; Wed, 22 Nov 2017 13:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511385581; cv=none; d=google.com; s=arc-20160816; b=f91lWzcK9Ra0acgjGdeu3JI9vN18j63d2ApRGtRsCiSXnwYsFiDf7n3seJA+SW+8H2 RcD6r8ygYfzmXiW7MyICND0AnwrssEZ8wCYve+e9H+s3aEzEL5BmDDRRuO3rZn6u8esF EGbeEQtV8s1rGn70fiMbZ4FKe65a1OzQ20pUiP2uhsSIySnE6qzcd9Td43WSUleQKbNe GnhO/HGz/LmuuflXuiBqcB4Dsu3MVacr/TW+OEd6dqGfPnwSRM5UguV1nflB16Q5k2WY zmCZJlr7F0oV15zDbuK5cS4PB4eVOAhMs+z87/0MKcI5AkoSrErhcmU6nwuQjwMeAQsT gWHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=QNyE2eAvmEZsW4Y/LL2JRgb1wFbbp+cl5DvSpHC7r0o=; b=CYx1Up2qOMw2VXD7eZZ8QznONsy3j6TXlZhz0U1xWWt+eF/zzSSD8lMkWJb1iP7oxy PQ9TrlsFqKSXEIRq1houU7Kv1O4whgLaBUTAcPAjraxy+ROAk3nQtlqIs3IJQh9KNMJZ 9u15ZEs/BKil0ddPnz0eoqHTLAzhkTDAaWEz6uN5A0sKaEH6j2FcHnLPZJhwe6AZYIXk 8N+PQsiv5I4KFbuIP7Ghsx70sHI7aHAB4EF4ezadNNMQvCyr/6EpqE0QRr8QBDpK3sQd L3LX83LSMqJvWnjUZW+Btcxe4AIht8Wnp8icpfIaNBabgf2vY+CfkK/+lWwNOh4msTv7 jE7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=K/k5Xugu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t63si9345023pgc.793.2017.11.22.13.19.27; Wed, 22 Nov 2017 13:19:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=K/k5Xugu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752177AbdKVVSV (ORCPT + 77 others); Wed, 22 Nov 2017 16:18:21 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:39894 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751796AbdKVVIS (ORCPT ); Wed, 22 Nov 2017 16:08:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QNyE2eAvmEZsW4Y/LL2JRgb1wFbbp+cl5DvSpHC7r0o=; b=K/k5Xugu1EStbhHq49/Bwz2rj CeTLLy7o0rD1g1eWaP2RZUN98N9gKRdxgqj9Y53GohZ8IDG217lO7Jy+7OmDatEq5/GFPtnC/DghY 3o6UiIGMC4eKq+rEBnHESP8DB7MrHEl7EEi3qV66J4eapY9nERtd2Rdb2LKApDONtNHTDnoEmJAaC +rcOXCfW8PdKeVmuYSCpEynKReUx/j/3behysTGxOW6rx7p/iFptY8vRIrDDOPT0uwfjWTvUQt2Gx 2z8MjoCcSgXxCEbLGadoOJMdSHIkTzNCHhkABtvs0bMyf+jWsGI6czjRDJRC8kcXKsU5TfkX23IhE Ozhp35jZg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFm-0007ul-0e; Wed, 22 Nov 2017 21:08:18 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 30/62] xarray: Add xas_find_any / xas_next_any Date: Wed, 22 Nov 2017 13:07:07 -0800 Message-Id: <20171122210739.29916-31-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171122210739.29916-1-willy@infradead.org> References: <20171122210739.29916-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox These variations will find any entry (whether it be NULL or an internal entry). The only thing they won't return is a node pointer (because it will walk down the tree). xas_next_any() is an inline version of xas_find_any() which avoids making a function call for the common cases. Signed-off-by: Matthew Wilcox --- include/linux/xarray.h | 25 +++++++++++++++++++++++++ lib/xarray.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index e0cfe6944752..8ab6c4468c21 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -466,6 +466,7 @@ void *xas_load(struct xarray *, struct xa_state *); void *xas_store(struct xarray *, struct xa_state *, void *entry); void *xas_create(struct xarray *, struct xa_state *); void *xas_find(struct xarray *, struct xa_state *, unsigned long max); +void *xas_find_any(struct xarray *, struct xa_state *); void *xas_prev_any(struct xarray *, struct xa_state *); bool xas_get_tag(const struct xarray *, const struct xa_state *, xa_tag_t); @@ -540,6 +541,30 @@ static inline bool xa_iter_skip(void *entry) (xa_is_internal(entry) && entry < XA_RETRY_ENTRY)); } +/** + * xas_next_any() - Advance iterator to next entry of any kind. + * @xa: XArray. + * @xas: XArray operation state. + * + * xas_next_any() is an inline function to optimise xarray traversal for speed. + * It is equivalent to calling xas_find_any(), and will call xas_find_any() + * for all the hard cases. + * + * Return: The next entry after the one currently referred to by @xas. + */ +static inline void *xas_next_any(struct xarray *xa, struct xa_state *xas) +{ + struct xa_node *node = xas->xa_node; + + if (unlikely(xas_not_node(node) || node->shift || + xas->xa_offset == XA_CHUNK_MASK)) + return xas_find_any(xa, xas); + + xas->xa_index++; + xas->xa_offset++; + return xa_entry(xa, node, xas->xa_offset); +} + /** * xas_next() - Advance iterator to next present entry. * @xa: XArray. diff --git a/lib/xarray.c b/lib/xarray.c index 202e5aae596d..38e5fe39bb97 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -805,6 +805,57 @@ void xas_pause(struct xa_state *xas) } EXPORT_SYMBOL_GPL(xas_pause); +/** + * xas_find_any() - Find the next entry in the XArray. + * @xa: XArray. + * @xas: XArray operation state. + * + * If the xas has not yet been walked to an entry, return the entry + * which has an index >= xas.xa_index. If it has been walked, the entry + * currently being pointed at has been processed, and so we move to the + * next entry. + * + * Return: The entry at that location. + */ +void *xas_find_any(struct xarray *xa, struct xa_state *xas) +{ + void *entry; + + if (xas_error(xas)) + return NULL; + + if (xas->xa_node == XAS_RESTART) { + return xas_load(xa, xas); + } else if (!xas->xa_node) { + xas->xa_index = 1; + xas->xa_node = XAS_RESTART; + return NULL; + } + + xas->xa_index = next_index(xas->xa_index, xas->xa_node); + xas->xa_offset++; + + while (xas->xa_node) { + if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { + xas->xa_offset = xas->xa_node->offset + 1; + xas->xa_node = xa_parent(xa, xas->xa_node); + continue; + } + + entry = xa_entry(xa, xas->xa_node, xas->xa_offset); + if (!xa_is_node(entry)) + return entry; + + xas->xa_node = xa_to_node(entry); + xas->xa_offset = 0; + } + + if (!xas->xa_node) + xas->xa_node = XAS_RESTART; + return NULL; +} +EXPORT_SYMBOL_GPL(xas_find_any); + /** * xas_find() - Find the next present entry in the XArray. * @xa: XArray. -- 2.15.0 From 1584802237902971690@xxx Wed Nov 22 21:13:10 +0000 2017 X-GM-THRID: 1584802237902971690 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread