Received: by 10.223.164.202 with SMTP id h10csp667597wrb; Wed, 22 Nov 2017 13:22:16 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ50pfP857ty2J84J8P6GP7GB/86otk9mj24CtU7rzPBBWLLarRRN+0HxAWDNIbOiauaBLw X-Received: by 10.84.253.134 with SMTP id a6mr1352858plm.419.1511385736153; Wed, 22 Nov 2017 13:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511385736; cv=none; d=google.com; s=arc-20160816; b=sGjjGk8NMYEkxmvF9vnYHI3U5UgwQ7KiDkAry8tkGSkjaErzHp/tbCllA/wKmq+M9B tpMKkbH1jA6jXjmwIyY4FqNJIbXoWEwhuDtCEjuLJc2Ksi6Tu0/qcSap8uoVV7uFV90s qItIaPCrl9KYGq//pH43uCv21CWy9dMA7mz7SiXflMoDaNzqHpg8zrvADVLiunY4kHr5 oIFh9TJ7Um8+xXF9yx0ZRwAe4fbtavyLrC0XQEA182KibB0vuiwcPIPaCQckijPgAgKP oQjYEN53aue/tbcL9T774YchXbWq9SN5xxygrgtT1TX4idlnMFuxjb6w35wBXP4GMuLG DUAQ== 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=QGGW8HcRd47GsYkB8wMyZVMLocUOkhET7DkHmrAPaIE=; b=pbChHgE3q/Y2/esvd7VIWhoHDcqhbUE54947G+7TbD1+Te6H+KnvWjkyu74pwzLflW KJq/zE4+txIKWbAi9tnExZgCludVlhubgExksKCWjc92+KxiMBiOhVl6+lRaozsaq+Cx 0yxtHZIdUQhr/r/YccKWMm1pZ3V87gyDKdNmH1CZCdizBfG2LAfyI34A6aS4lgeMTpT0 822G1XTh5oyHQzmZ0y+30bNAJ894ebny0TZKeSweig/Bia1hilS7pMKnR2fnfzUUVF4M a/esUOrUFVH00Zom7j6XCKA8e+gE4WB/YmeiPiSqajUJMCuZJh01njJcyC/l9F4LToBK zJsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tik3n7b7; 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 g207si15622528pfb.190.2017.11.22.13.22.04; Wed, 22 Nov 2017 13:22:16 -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=tik3n7b7; 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 S1751957AbdKVVTt (ORCPT + 77 others); Wed, 22 Nov 2017 16:19:49 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:51741 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751776AbdKVVIS (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=QGGW8HcRd47GsYkB8wMyZVMLocUOkhET7DkHmrAPaIE=; b=tik3n7b7d4MAO7ht5SyYzhRL6 l+7K0qBQZb92GdRmQhaK56T/ejUMEAE+6/ylkltsBr7UTrvGxCQH3iC8GDVfT3clKRRPWPVmmkOY8 h74nCQ3awibeZpGJNKuI7rvGt414dQLZVFVIDaRm0zGnqiH4wHlauMGFAq5vixXPTF/7ESgrHNA6/ K6+Q7ZzR1XNdnnWs2bSGJJyBKXV5W9QY3dQ9Vv9y1kzy05CRpO5BDPrRFe13J1aPGk8Qnndk7z59W +nIUBwE9OYkmwFL/uXcEu73EcH9ml8sPJyq0cMpQ9/YLu2uytj0VKrAWGZqSWO6XEWj7pCyT81G0a kl5p0iajA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFl-0007ud-Tt; Wed, 22 Nov 2017 21:08:17 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 29/62] xarray: Add xas_prev_any Date: Wed, 22 Nov 2017 13:07:06 -0800 Message-Id: <20171122210739.29916-30-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 The page cache wants to search backwards to find the first hole. Its definition of a hole doesn't make sense for the xarray, so introduce a function called xas_prev_any() which will return any kind of entry, including NULL or internal entries. Signed-off-by: Matthew Wilcox --- include/linux/xarray.h | 1 + lib/xarray.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ mm/filemap.c | 15 +++++---------- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 347347499652..e0cfe6944752 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_prev_any(struct xarray *, struct xa_state *); bool xas_get_tag(const struct xarray *, const struct xa_state *, xa_tag_t); void xas_set_tag(struct xarray *, const struct xa_state *, xa_tag_t); diff --git a/lib/xarray.c b/lib/xarray.c index 4fc1073f9454..202e5aae596d 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -948,6 +948,55 @@ void *xas_find_tag(struct xarray *xa, struct xa_state *xas, unsigned long max, } EXPORT_SYMBOL_GPL(xas_find_tag); +/** + * xas_prev_any() - Find the previous 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 + * previous entry. + * + * If asked for the previous entry of 0, this function returns NULL and + * sets xa_index to ULONG_MAX. The caller is responsible for detecting + * this situation. + * + * Return: The entry at the index, even if it is NULL. + */ +void *xas_prev_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); + + while (xas->xa_node) { + if (unlikely(xas->xa_offset == 0)) { + xas->xa_offset = xas->xa_node->offset; + xas->xa_node = xa_parent(xa, xas->xa_node); + continue; + } + + xas->xa_offset--; + xas->xa_index -= 1UL << xas->xa_node->shift; + 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 = XA_CHUNK_MASK; + xas->xa_index |= XA_CHUNK_MASK << xas->xa_node->shift; + } + + xas->xa_index = ULONG_MAX; + return NULL; +} +EXPORT_SYMBOL_GPL(xas_prev_any); + /** * __xa_init() - Initialise an empty XArray * @xa: XArray. diff --git a/mm/filemap.c b/mm/filemap.c index 1d012dd3629e..1c03b0ea105e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1390,20 +1390,15 @@ EXPORT_SYMBOL(page_cache_next_hole); pgoff_t page_cache_prev_hole(struct address_space *mapping, pgoff_t index, unsigned long max_scan) { - unsigned long i; - - for (i = 0; i < max_scan; i++) { - struct page *page; + XA_STATE(xas, index); - page = radix_tree_lookup(&mapping->pages, index); - if (!page || xa_is_value(page)) - break; - index--; - if (index == ULONG_MAX) + while (max_scan--) { + void *entry = xas_prev_any(&mapping->pages, &xas); + if (!entry || xa_is_value(entry)) break; } - return index; + return xas.xa_index; } EXPORT_SYMBOL(page_cache_prev_hole); -- 2.15.0 From 1584801285087510596@xxx Wed Nov 22 20:58:02 +0000 2017 X-GM-THRID: 1584801285087510596 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread