From patchwork Sun Jun 17 02:00:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10468387 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 A4217600CC for ; Sun, 17 Jun 2018 02:05:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9404A28D41 for ; Sun, 17 Jun 2018 02:05:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 868FC28D4D; Sun, 17 Jun 2018 02:05:40 +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 1728128D41 for ; Sun, 17 Jun 2018 02:05:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5768B6B02DA; Sat, 16 Jun 2018 22:02:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4D6FC6B02DB; Sat, 16 Jun 2018 22:02:58 -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 2DBA46B02DC; Sat, 16 Jun 2018 22:02:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id D98E36B02DA for ; Sat, 16 Jun 2018 22:02:57 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id z9-v6so6621480pfe.23 for ; Sat, 16 Jun 2018 19:02:57 -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=swEIFSIKt2NvfdWOTUWTQV6Qzybb5fYEWm8H1x1L5ac=; b=e7kuuVbEJBmkpWT0C78oKgkQtqd0mUNOIC2il9bSZ8QCvT3bzbxNtQSlZDq//vBLHm qSQJgdnX1FP/NYxh9gNQw+Ta6eXSRjax0wFoXJTt3gNc0rIdXRjDoVntGJ+M/uxNZfZ7 zWDMaE9doDNNG/wqryQYtFjwsYIFNAvtMD8S/vT6sBKe9H/3CsPODFIElkXMSL+B1X0M Kikh14Yc+6CO2tLA7OwcO0sTajeyg62PQqD5ep/0ztxGoChXBIe7G+K3EahI6Tis1vk7 43n7rF2YVG67Po5krlhPkvIxASoGmBTYXTQL3wqVMZO/Xl4MrKjlYMbSm/Ew/8votJ+b e2Ng== X-Gm-Message-State: APt69E3kPJ3aNCPK/dWDjHYjKPy5DwkYF0RcdFlyvfg5/Yly4gLImm0f Ei2gjVSBSZP+aGUXRoMCteltUu1AIFEt5bbe7bqY7cjy/hT0alkWbVETVbhDZLmPYLSe+aVt367 EU+nlyhFYy7i2YgknFfyGZDfmzmCvqe5kvJrEyS7AMyiHtnx2t5F31h8P5SbiuXtNcg== X-Received: by 2002:a62:ab0e:: with SMTP id p14-v6mr8008610pff.211.1529200977565; Sat, 16 Jun 2018 19:02:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJcPOY28FXXa5coAyu/Kj/FER2oVmu4pYrWWUNMoeDQ/FiaIP1jcs/xVBECYj/Rnx/I/KBN X-Received: by 2002:a62:ab0e:: with SMTP id p14-v6mr8003512pff.211.1529200861231; Sat, 16 Jun 2018 19:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529200861; cv=none; d=google.com; s=arc-20160816; b=D3luT6QkYHKd7t5i7DKNb2OeGhpqe+tsXkGsXMdVI5kFFGi06Z4hbPszq4BzZsHJg6 iDozkGObTszjPt6ALzW3491kN16KzDrHuc/qKgK5KiJaQDAtfX9zMr4YwqACJOZ2R3lm wzckY9zpUTfHaa3eMRIsTUSH9Eq5YLNBr8B9NeS/E77CRWB+zT8vAkw23ErDH/Bj1+EO XQxfTtWewKeWhQXHHNyiTYgvDvy0ttC+28vllfvS7AHIpLrcwgOmy4l4xtO8Mmn3LJnT P2PhNeiDaJ87TgKvzGjn6asCtxbF+tOM6AYTnT15z66Eb/CF/GlPPmBisxY4dfLyqiMd uZ2g== 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=swEIFSIKt2NvfdWOTUWTQV6Qzybb5fYEWm8H1x1L5ac=; b=U65DcobPPH5dPvvqg6YqjmgGw8auOE1ncnQnryj5KN6RQ3HPsZL/NqaiargoIeNuuT XGRKA0MSVjgiXz8AqzB/IqIDS/wZjVjRGVuYBIueJFCXA70jMh9olzTOUiE9S6hwHHgI b5T+l3mIQD3FtRAnG+CRGfvR6a+cdytNt3Wai5MZ1N1VIE1eso5xx/eyTbqpf0tnHsRb 834CuoIqyyF15gHauKTENtc35cjsNRE0Il2Jw4PwKP2u8EWWiks8CY8k/DpFEKnLlYp0 zu2i9E5qCvFjpqDxBkQEz3tnU1ZwfnCXHKPfT4XZZzStFHlMsp9biLBRa8cd6a9hMT4C 7Ahw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=aAQmFyx0; 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 x9-v6si11429840plo.368.2018.06.16.19.01.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Jun 2018 19:01:01 -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=aAQmFyx0; 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=swEIFSIKt2NvfdWOTUWTQV6Qzybb5fYEWm8H1x1L5ac=; b=aAQmFyx0cVjTXqtePBlN/Gge1 6GAqypN2Sd/9jLth3wwwkxuXRtSKKxfGDSJxHjw7XruOko4f2+J0aQEazFxZbT9st3pkFvQLjdS5O Uk8iT+UyZGL2vvJgRvMNeJOih+Olkwe0ZNKGxWm42YfgBEXYLL+Ma3PKpwudp432g9+I4RYJqK+Rh ShFqf+Mwx7QTpycJl7TivE24r6HwkGfGeKRQP82noTMR4vc4FBRZ7+njOGBaBtiXX9Myku4R08p+7 jzlcpj59lkspt2+2QvIHBLvky5rchFeVlmSuULPcfE4kugcNx4j+dd/kEeomdvqXgUTOhmgR/EyOe 4DdD+SVBA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN00-0001Io-Gy; Sun, 17 Jun 2018 02:01:00 +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 v14 29/74] page cache: Convert find_get_entries_tag to XArray Date: Sat, 16 Jun 2018 19:00:07 -0700 Message-Id: <20180617020052.4759-30-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180617020052.4759-1-willy@infradead.org> References: <20180617020052.4759-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 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;