From patchwork Mon Jun 11 14:05:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 10457921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9E816020F for ; Mon, 11 Jun 2018 14:08:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7B0F27F8C for ; Mon, 11 Jun 2018 14:08:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC5C228434; Mon, 11 Jun 2018 14:08:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3988D28418 for ; Mon, 11 Jun 2018 14:08:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDD426B027C; Mon, 11 Jun 2018 10:06:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D65A86B027D; Mon, 11 Jun 2018 10:06:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDD036B027E; Mon, 11 Jun 2018 10:06:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id 767526B027C for ; Mon, 11 Jun 2018 10:06:54 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id j10-v6so6597865pgv.6 for ; Mon, 11 Jun 2018 07:06:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=fwqoMbRfGsDMvYDOCVix3zU3Jbw64C7uj9ufKhyC6y4=; b=SkHGRTWVXE3qGNagTvGTC0DLEeJH/BNrbzyENSlSHwDcRpEg564Hb9dw6cvcQ0H9MR r3oxelFgzj5f3EJAx6cpuVvNeoyLel7Zt7EB/OdYhFKBJgvmtGV+DdrScinJqBDV12Es GciuRqg1fDNTdbIQ97YfgNSXrCMcVqgFBz0r7TaS6T0EmGDxSIKzWHLWZSsEexUblryf hOLQQ8IjNfWrwS0Fr71u5q0OJ6auAFKnYkza+YBK9aTu3+gmqGoAWCHy76uRnQTeL+kX JlwPGD3ujwtZT1WeaCI7T7udEKPK0a2D4MFCCUleW8+4LKEyhbzw0cxa/6v8esZceZeu Tcxw== X-Gm-Message-State: APt69E257PruPZyW2DSC4rie/VAk7ghTp/WMWFcisCnE0C0F3ueZWn+U Nc8ninjKjNwK1OoYnZtqNcl33aRjSsYltS8V8kVOM5S2qHL7fMu1XB5t8H3/oVRpLPT3hsqQoYM aiWKRsjqE3vsxq5k95Zl3+iY26YmrD//dM5M/QuSKWWskhhsleJb4+O2nAXxzHK8/dg== X-Received: by 2002:a62:c809:: with SMTP id z9-v6mr17617086pff.5.1528726014171; Mon, 11 Jun 2018 07:06:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKGYrOYcq8Vv3eZ7D5kC7o2YkTFCA29xLmQUAK6RjMDN7g6YpuhlF/bhyz2FtrXv7d6ilxR X-Received: by 2002:a62:c809:: with SMTP id z9-v6mr17616995pff.5.1528726012882; Mon, 11 Jun 2018 07:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726012; cv=none; d=google.com; s=arc-20160816; b=MXEuP2dfQmFk9OcGaR3jevsKAYIk/EJRNsQ7QkpWKXnJYuvXP6LUYjIygW9HDpGNng vnNRhyhhXZZxsxTqu3rIQl6omnFltDoBnqCbFFzA8UnrWdomUCFdE4FgdSH/hgD0mD1E oa24LYEQ4XeHmHBzHADIQX5M48XqgA9OQ7tKHXemAwnMznXy5IgJ919yf9VO0AnopCws 3AkIGvM4v+cGOQCwsl21ejUPPc7S6omTNM32TvAyQmzEHCPVbuayYwsBk/x9e93ln6uR g+rO5SqEQG3ZjMCzS63YjzM9jbG6chNi1z+w5GQLOmJ38FsSJAK3OL1OcvVTJf9obv6i iXgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=fwqoMbRfGsDMvYDOCVix3zU3Jbw64C7uj9ufKhyC6y4=; b=TQ9AvlzoeR7HLqFmP05ooniHM3ngvw4EO7m+OTPpJmIs55HoDi075T6+HVPRB85/mI 777Ua7FFOjGwAcQs1LFcuSnG/onvgdijKGJXUxY7EjrZnTp5+tTjOxXIrBJDipD7MY24 i/kXhL2K2ZgXUmvv16NFIvtscT2RpsJRTUgwNfzZyKOA3Jk4IWw47PuHnNYd1AwURSsu 2X4QM8MPnn8n3vm+eFEMYv2x229s2CHaUKK+3DCgPQjD7hmN5NO+txHCGWOo0SO+3FUQ ffYW7+pGIOSe2MTQCkn/GN9mpFbzVAMCL3DmQOVhkVcidFDzrmrVffq5iGE1uIUCFAnt iLRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=a4cv7/sW; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id h91-v6si62090362pld.132.2018.06.11.07.06.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=a4cv7/sW; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org 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=fwqoMbRfGsDMvYDOCVix3zU3Jbw64C7uj9ufKhyC6y4=; b=a4cv7/sWTzuX3VMy+74ENBJsu uDXnsLwh8pfamO8PHVtIM4BfGFuFmkuWaAuTd2OyiSzwc4yvucEgPS2M4CO1fKcI9tzuzZfSr7wcY 49M405DypPQkLX2MqXuOaElrel2+hxTERI8Sx3xocIbWTLqNA0xnv+vCVDBkLSQvc3bC2Otopgb5k orYWU/Fj09Ch/hZh4TgyvmISicIli+YdFMbTpC1nuIOU4ekuXWNZG4au6rPtJ74XWny4VTXxO9Koq A4NVc+l9AZ8BJgOb5sslB15T9PTo6NdzkmBEduTVzLOR45aUY9gDp8vH6y78aI0HyO01q028HInGj iOsZN43Yg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNT9-0004hM-G0; Mon, 11 Jun 2018 14:06:51 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v13 28/72] page cache: Convert find_get_entries_tag to XArray Date: Mon, 11 Jun 2018 07:05:55 -0700 Message-Id: <20180611140639.17215-29-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-1-willy@infradead.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox Slightly shorter and simpler code. Signed-off-by: Matthew Wilcox --- include/linux/pagemap.h | 2 +- mm/filemap.c | 54 ++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a6d635fefb01..442977811b59 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -373,7 +373,7 @@ static inline unsigned find_get_pages_tag(struct address_space *mapping, nr_pages, pages); } unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start, - int tag, unsigned int nr_entries, + xa_tag_t tag, unsigned int nr_entries, struct page **entries, pgoff_t *indices); struct page *grab_cache_page_write_begin(struct address_space *mapping, diff --git a/mm/filemap.c b/mm/filemap.c index 83328635edaa..67f04bcdf9ef 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1866,57 +1866,51 @@ EXPORT_SYMBOL(find_get_pages_range_tag); * @tag. */ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start, - int tag, unsigned int nr_entries, + xa_tag_t tag, unsigned int nr_entries, struct page **entries, pgoff_t *indices) { - void **slot; + XA_STATE(xas, &mapping->i_pages, start); + struct page *page; unsigned int ret = 0; - struct radix_tree_iter iter; if (!nr_entries) return 0; rcu_read_lock(); - radix_tree_for_each_tagged(slot, &mapping->i_pages, &iter, start, tag) { - struct page *head, *page; -repeat: - page = radix_tree_deref_slot(slot); - if (unlikely(!page)) + xas_for_each_tagged(&xas, page, ULONG_MAX, tag) { + struct page *head; + if (xas_retry(&xas, page)) continue; - if (radix_tree_exception(page)) { - if (radix_tree_deref_retry(page)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - - /* - * A shadow entry of a recently evicted page, a swap - * entry from shmem/tmpfs or a DAX entry. Return it - * without attempting to raise page count. - */ + /* + * A shadow entry of a recently evicted page, a swap + * entry from shmem/tmpfs or a DAX entry. Return it + * without attempting to raise page count. + */ + if (xa_is_value(page)) goto export; - } head = compound_head(page); if (!page_cache_get_speculative(head)) - goto repeat; + goto retry; /* The page was split under us? */ - if (compound_head(page) != head) { - put_page(head); - goto repeat; - } + if (compound_head(page) != head) + goto put_page; /* Has the page moved? */ - if (unlikely(page != *slot)) { - put_page(head); - goto repeat; - } + if (unlikely(page != xas_reload(&xas))) + goto put_page; + export: - indices[ret] = iter.index; + indices[ret] = xas.xa_index; entries[ret] = page; if (++ret == nr_entries) break; + continue; +put_page: + put_page(head); +retry: + xas_reset(&xas); } rcu_read_unlock(); return ret;