Received: by 10.213.65.68 with SMTP id h4csp360131imn; Tue, 13 Mar 2018 06:45:36 -0700 (PDT) X-Google-Smtp-Source: AG47ELs/9/3DTByelbLNjf/VnCatxxSh4ggy1PuvGk862zmUFu3BqNfjZjy6LG2lOvL0/xYkWvrC X-Received: by 10.101.97.139 with SMTP id c11mr529753pgv.443.1520948735984; Tue, 13 Mar 2018 06:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520948735; cv=none; d=google.com; s=arc-20160816; b=H+wokXJMAmiipIHzu0cl3PA9deNVhUcQQIE3Q1tQSLGcQ45CWY+mjFcoyMFlCLtZ0g e6rYvKE1VLeE9RrVyYqX62S0OvWTRSknaotAtKN/cFjyPnx26oRSMBepdmo9E3i2xtYR IHw/z7LRfmQz4fdvMSdBV6Xs87utkmVpkULA8ApilGtSBEx3grju86amtKNawG/QBZ8Q iq2rW/7DLtGYbHrOa5h2Sn6Ju9PWdNcB/nJZkLZ+w0DtWyNX+68Fuk0O9OO5teuuR4sn 4iRG7MAMhfAXcAGg9wdJezt432VwiPTjkEnPAe5A8SMAegqI67QVnPW7SnbGyOtaZQ6M pETA== 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=TUtEh0M91EPdkADjFqpMeEIRJ3g2LkGH+aLO+Cd7bW8=; b=WVr81TqE39n3TkkQXTg9H2YwuQMMDt/bLZZO8Ldm1NPZDxZSgkkvBe5VbH8be+ne/n L803a9G6frx81v+iEji7HI8Y89j4LsxInyZXe0ZyedyAJuH+HJX5SY294FgwXX4T3LiF jQCcLlbJg1JnrpJHLyNr7IEfCV2UHBR7AqzSAPnFPNDHsJIp/v29KTobdZajTKU04u6y naFKLTdZ6Wswsp46vY0WQGE0w3zsO35hfNXxeBxP8R1J5laEJPcqhqnoGMT2hW4y3Ij6 ee4POYCBh6bTc9ws/NN5NL+xxoStebMigWfaiIlmR4INLt4GQAsoxMpayEVAL5sFC4jD stIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=BPq+i0sH; 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 x70si123249pgd.724.2018.03.13.06.45.21; Tue, 13 Mar 2018 06:45:35 -0700 (PDT) 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=BPq+i0sH; 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 S932981AbeCMNnO (ORCPT + 99 others); Tue, 13 Mar 2018 09:43:14 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35264 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752763AbeCMN04 (ORCPT ); Tue, 13 Mar 2018 09:26:56 -0400 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=TUtEh0M91EPdkADjFqpMeEIRJ3g2LkGH+aLO+Cd7bW8=; b=BPq+i0sH4X8mQQ3hYKfgA4pB6 lMf3JutbTRpYlzl7vOVMlWV9Am8sMC6At5bhiG+aa1rQUsC6nkTzaMknlz0/yPTn3/f5uydzF7RAd gi/yoZClIFwQR9i0pyxfw1RpaB4JMqByS9/HUQyJg0+8z9eH1F9Gz7B/6qrO9n9U3LvhyyluKB6ti JYXYfcfGVMoh+Lpe5PwpkCW8DtoRuhcPcAj2lfSMAfOeItyhpEpCjz90gRJEEwucaY9H+ftBvihH5 +3QYvK4Q97sYgGZQLRYj35Q4kah1BdparUIqtOAI6x+M7uMV2u0L5Gc6TQFmUsd7Pyk9rMPyMvHFB AnTqSd1Tw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1evjx9-0004ey-94; Tue, 13 Mar 2018 13:26:55 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Ryusuke Konishi , linux-nilfs@vger.kernel.org Subject: [PATCH v9 31/61] page cache: Convert filemap_range_has_page to XArray Date: Tue, 13 Mar 2018 06:26:09 -0700 Message-Id: <20180313132639.17387-32-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313132639.17387-1-willy@infradead.org> References: <20180313132639.17387-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 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 86c83014c909..9bc417913269 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -458,20 +458,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); -- 2.16.1