From patchwork Mon Jun 11 14:05:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457909 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 18FB76020F for ; Mon, 11 Jun 2018 14:08:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 063A81FF81 for ; Mon, 11 Jun 2018 14:08:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEF9D27F8C; Mon, 11 Jun 2018 14:08:29 +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 868C31FF81 for ; Mon, 11 Jun 2018 14:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26C376B0278; Mon, 11 Jun 2018 10:06:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1F3C86B0279; Mon, 11 Jun 2018 10:06:53 -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 092BD6B027A; Mon, 11 Jun 2018 10:06:52 -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 AF58D6B0279 for ; Mon, 11 Jun 2018 10:06:52 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id t5-v6so6574996pgt.18 for ; Mon, 11 Jun 2018 07:06:52 -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=twa7itpLIU58lfU+MddoEIWcRCNFcsboeQJXmsXbu6U=; b=XOpKkfqo3UigIo5syqzsNEdv/oFpm1UOpx6nUvNEpGNeQ/QvRv2oqptbnVJlsu8nRS uG+usZq/Dmw0Phg1IoYY3RDXXITr/7TK0xS8wANMNNm2Ioqqoa2n6oHS8Vwh2wHih8IJ OsTF34GBKnJod96pzem1PVT86EKXYVSLo+PuAAL1GdVrZXYlu9dSLL8aWvz6XOvqaJKq hFBEXMp6PHdYzRXc5hBv1IawJ8GDCFl4saaJoeSSZXNbv9ClbwlWLzjpMOopJViEfM57 4d9jSEAZmvs41SWNT4yKBuWReCJjzdqWfP3qyTlkPHbipkWlRHIfOG/m3Adr5RrIqWG7 s2JQ== X-Gm-Message-State: APt69E2wNQFYQkNrGACgz3TzMMbOy6/rNos2KZ/v8pl+gRfLTfGZSSdF LAp2QWrsP+mERHQvFSeYSBSsKAckAiSucDcQS322ARJOzSrs/IG6W/ReG/6EbQGvR1NW3bmhvaN 4f5Bg7h2QNay4tHW3N1a7TOpP9O7qVbbeJPuW2Skk5UXErmP2kN/3FToDxPv55Bp/sQ== X-Received: by 2002:a62:fcb:: with SMTP id 72-v6mr17780440pfp.231.1528726012400; Mon, 11 Jun 2018 07:06:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZBqo2SH8MIO1q3X4UpQ9Yl9vA/NOO3Ie71hw8LTpLJScmwwm0z/76OPpF4tl8wcgiOVbs X-Received: by 2002:a62:fcb:: with SMTP id 72-v6mr17780316pfp.231.1528726010555; Mon, 11 Jun 2018 07:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726010; cv=none; d=google.com; s=arc-20160816; b=SDM6ijUnxcl5a2ZtYCTejpHLZd+fOuyiVz+cV1Lvbix7spmVld5bVp9mGfsl2Ul2zx 5FhezxnHVsQLepknp6SJ+rGCIVoQ8jcOW+M5SaBMQWGrfOOtbGafcKkgNlQLASnAj4/x 4HK441ueDUAr2xALx3Rj6VG6NUd7qXS2PpVeUSs63S7unFHkAgfFk0fuCfL+MZmdRh0e 3u/I5uYylSIocNbK7ZvId0lKtm1WdaLOSDv0ENXybn8tkVLLQFqICLTULgBVhmFeUQ1H Vm//ZK2DoyQcQHnmszBhznCr9QSn0Z/AKfJ17wUytsjkfRZQ05oMPz18e8P2jGhRtR9H McfQ== 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=twa7itpLIU58lfU+MddoEIWcRCNFcsboeQJXmsXbu6U=; b=UY1ak6AaawSVAuDY5wUD6/0wRlKQc/lKf8ZW93sZTXSZZ0LQIPA1V70wpUGCYXrjp9 Y69cq1hMgKhGJV2+NEAHSUC25SXU6f+LXjelkcOtaC3NJbhkC93UzrhY2euuXKYwkHu6 TWXYk1igzApe/HwriY1s6nFoY5PG83jdiVj/ULT+qLh/Dlg0/w3smLNIvGCMYGd02ONu V4eLTgxtKYo40gbmBk+6Tdcqp/Kd2yXkN5i9K0VBMFugL1DzO+d7mGx5kMslTyRmWPoN omIai/ADV2U92qH3rSYFFq51PZ+hKSpL21PdnIq1it4bnwboevpA2fBJ8yS+DsbzAiue 9yuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=mSlf1ufG; 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 w10-v6si31476455pgt.404.2018.06.11.07.06.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:50 -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=mSlf1ufG; 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=twa7itpLIU58lfU+MddoEIWcRCNFcsboeQJXmsXbu6U=; b=mSlf1ufG8UA2KgMlNo35S+NaM 4CjH391z2F6+7znnZEMPVL7go8HO+W+TN2hpsuDyFrxz2OPuWskz/wYlj552FIvE4Hpog7SO9kcxg DrprQ4hWv0/bDKjgatLik6LF4krDh/OsLmsXbm3H/eM8s/VqgBF6Jv98EvDxXszTyk12YNiqF1xpv d66vJwkvlPIKpNzbuT1hNaXfa2tF/8BtSOYLkWCuBKfTJPDSloDiG5SlNPm2EyWEqL2jml1g7woV7 cFqwjvs/OUsSqOtb6Q7OeV9m5zQAHgFlN7ay+NhOW5o6BjmAeP1/XMJC3yq2oo1UX/WygmkKtIClE 3CWvgUinA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNT7-0004fa-G9; Mon, 11 Jun 2018 14:06:49 +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 24/72] page cache: Convert find_get_entries to XArray Date: Mon, 11 Jun 2018 07:05:51 -0700 Message-Id: <20180611140639.17215-25-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 --- mm/filemap.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 6db3d35ff5f6..b49290131e85 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1578,53 +1578,48 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start, 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_slot(slot, &mapping->i_pages, &iter, start) { - struct page *head, *page; -repeat: - page = radix_tree_deref_slot(slot); - if (unlikely(!page)) + xas_for_each(&xas, page, ULONG_MAX) { + 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;