From patchwork Sun Jun 17 02:00:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10468353 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 8C16F600CC for ; Sun, 17 Jun 2018 02:04:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CE0428D12 for ; Sun, 17 Jun 2018 02:04:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7132F28D38; Sun, 17 Jun 2018 02:04:53 +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 0FFDD28D12 for ; Sun, 17 Jun 2018 02:04:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AD376B0005; Sat, 16 Jun 2018 22:02:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 85B5C6B0006; Sat, 16 Jun 2018 22:02:28 -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 6AD726B0007; Sat, 16 Jun 2018 22:02:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 263DD6B0005 for ; Sat, 16 Jun 2018 22:02:28 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id t17-v6so7725173ply.13 for ; Sat, 16 Jun 2018 19:02:28 -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=RmQxGBWzt2Rxic4Hz4j+/UfZAYB1EstyKVlk7zyedMk=; b=O0pjgrxlGI3xz8g6WvBrF8JWynL6ty6VVRrCDioCKNFdWzELk2FYnMxodAI7eiu9Jc Elw8el02eaO5+2ZeAT43KlYEwWzPe2rZ0t5a2o50oy1YYOqIk4+rABXvwnRk9qdSJjgA r4rwhPw/Ro8fFa6xmmJKY1BsVSitFR+uESHLlUlFOQeKxZwz+18LGWJHjUvDE/G2XLBf YKWSF/DHDmI5FVpDpF9Sy+RUYov23jfK9a0Y+4p9lkKPjXKDwo9ztOaKmuEf2g9lcZ2h SeabBVshSde879iRoruBjPx35glWajYdilt+huHiZNmWdpRchr/FCElSMTgenFtG7Ojd +YYw== X-Gm-Message-State: APt69E0HfM0mNKFMWQZ95HIY+0ZWLw9UZAX9eEBsLN/90zxxvUcW/a1K 6EUt4a/nS1xV65OAxshNnlF3Fnwl4vru/Cmhwi6m+zrKeVkF1q767pUESBgEXINhYYsbAKbcb4R yPsq8IsRKL4hkE9tZ6a4viLhQptvhIR3YZBHwHos6nP4Aq8bLesT3pDQqlaKaEH3raA== X-Received: by 2002:a63:a74c:: with SMTP id w12-v6mr6759140pgo.374.1529200947836; Sat, 16 Jun 2018 19:02:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ7F6jmhg/9XLqC3sHk4/BPVb+y9eWygp/8CWHj9ykU1SB/6W5kmCwIDMN4ZI+kPPub1qxA X-Received: by 2002:a63:a74c:: with SMTP id w12-v6mr6756087pgo.374.1529200863207; Sat, 16 Jun 2018 19:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529200863; cv=none; d=google.com; s=arc-20160816; b=YmPqKOFMinS84CkFvlCAVWUqWOdZyeKl8LHLIol/wMr4xEeTh+4nVnIfLZsGYQE28B WkW0Y+M8NCX7jntVqvAttl5oIGqj7JfWgkjY/GoWc6tFx+p+0cp/cvmH39nnLu3LcyzP f/IwXM6LvzGLfqSt80RObCqGw8VtlMUeQR9Yvn74qzJrr/tNR3RjY11ZBRz5gei7u0Xy KtQrPjbRBKg8XWXU8q+qPXSTHWWu/BAhDykfoH+8QfO+ulIL2EOCdCq2msVv8kqKbWz7 cH0HtMW6HokzVTbBndQ3JZ99Qk4EsoLDc0j3i3GGoqZidUDKXsT+gMQHBRu3UopNbpBU jszA== 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=RmQxGBWzt2Rxic4Hz4j+/UfZAYB1EstyKVlk7zyedMk=; b=x4rBDHIo6jACJ7/OifAnz3qeDomoqTBl7hfD7pRN5oP3/739UvT59az5aH6sJu08Tq T4LcqchHHAAx3aY0jadiWyjOf7E7PvdXWkNDP7qWCpCKm4OChPDedAPVWWZCHCTeTFEh VOGnL3qi+E8dFST/nebCCI0c8hSJO1d1xHQNKDNW6SdLt6DLYEBIiJuk9A37mGqrKfyl dlyQ8Zqy0fy8ELmhHNV3s//O6j35b3lTxN/WSU221pLGWRwWB2+4L3pMIqZhuGFAc0hV tQRYRA5ExAt5oUxfE/4drmSym63qV+LJ3k/0wSm8+wBee+FaPWR7W+1kE3Fovqw9a8Oy FSQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=VAh90YkP; 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 y23-v6si11220690pfk.75.2018.06.16.19.01.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Jun 2018 19:01:03 -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=VAh90YkP; 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=RmQxGBWzt2Rxic4Hz4j+/UfZAYB1EstyKVlk7zyedMk=; b=VAh90YkPtkWsf2GEmVLvEr4E1 C104EEcRnq5IRFvAFey/G5674jWmMV+hNdU/hTQ7gftDOaj5R5WnyNgmhAR9dKO3bsRD/Z2HQJGG5 oi5/UoxCozYhg/lmJ5hyEarBt16rH4I10IYRPywmT5tITeI+eAUM3Oj9LgE2iB/7jcnhAUJyGJYsq f12bQ4oVBnIyWU3CqYrnoHNJ+pePxVPIMX304XhaPXRHLOnR6uDEC0R3PtGloXB+P+OBE2r4seA3/ rqDO5M8ynkmbLNZr55U3d8VF3TWOnMio6Oulv6YxSoIG1xcswpK76pwOPm6jTe7Etf4QMFOxQiMsW tKeil2txw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN01-0001Jr-MK; Sun, 17 Jun 2018 02:01:01 +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 34/74] page cache: Convert filemap_range_has_page to XArray Date: Sat, 16 Jun 2018 19:00:12 -0700 Message-Id: <20180617020052.4759-35-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 Instead of calling find_get_pages_range() and putting any reference, use xas_find() to iterate over any entries in the range, skipping the shadow/swap entries. Signed-off-by: Matthew Wilcox --- mm/filemap.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index e447dd2d0f5c..68890327d1f2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -455,20 +455,30 @@ EXPORT_SYMBOL(filemap_flush); bool filemap_range_has_page(struct address_space *mapping, loff_t start_byte, loff_t end_byte) { - pgoff_t index = start_byte >> PAGE_SHIFT; - pgoff_t end = end_byte >> PAGE_SHIFT; struct page *page; + XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT); + pgoff_t max = end_byte >> PAGE_SHIFT; if (end_byte < start_byte) return false; - if (mapping->nrpages == 0) - return false; + rcu_read_lock(); + do { + page = xas_find(&xas, max); + if (xas_retry(&xas, page)) + continue; + /* Shadow entries don't count */ + if (xa_is_value(page)) + continue; + /* + * We don't need to try to pin this page; we're about to + * release the RCU lock anyway. It is enough to know that + * there was a page here recently. + */ + } while (0); + rcu_read_unlock(); - if (!find_get_pages_range(mapping, &index, end, 1, &page)) - return false; - put_page(page); - return true; + return page != NULL; } EXPORT_SYMBOL(filemap_range_has_page);