Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4122653imm; Mon, 11 Jun 2018 07:22:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLcPBtQi0d3099CwLv62E1wyv5ocgI4sy7i3mt4urHRoT1X+Ub2/EvCWsbfgLXBYw29um6G X-Received: by 2002:a63:2c94:: with SMTP id s142-v6mr14698346pgs.39.1528726923676; Mon, 11 Jun 2018 07:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726923; cv=none; d=google.com; s=arc-20160816; b=EXSt7QmpVSCPs6e2Rc3GuoB5R9DFNitzxm9AJaGI9HbNiPrVg86c5c02l/dwcA9QP1 rr5l/+23CmMLNx2B0xSRlwCoRYaAkOsc8+XdWME8Dhy2+QF59yblBPpr+XhpsiQwJjV7 2PUvaok+xJ7Huj4oyV2qYND5zwCHUcWjy2D4bM9H48Nm7BCrm2nIGeXX5kt/pJPjVxv5 uRSP+5VWQ5afYv/LY1rrEnQwx2zhiGfBuEpZdVoAba6lwwaEucOnRpTGgTEo8J+PH8jX 7q3pRIQ8i6hKGIByv1Ci2d6+ZMRS1KH7KqP5KTdLKB8ttd1bxNqgN+6OyLbp1dSqB1Mb CdtA== 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=sqW1jfi9fXH0Wb9SlzcbfFhp+ufIQamOcMd7GrKgp30=; b=F9G4AX4lAVd+cJbpl7MB3bMfqJNbBoIWb57/gw9ia2jozqchep39Op1kaEMLDOCZvm kvumtjGc16qVYgz+BsL4y0LuRJi4ExgXNs1xm2dsLvjLoHiDoUFvrgD1OYTs/KCKktrK 4e2lDB7ztivaEvbgxMYK6M5JHEYvCp2RWcqTKTZrRoE6IwtlsofITt0W1L1ZVjz2Yc+K cIBYmL362sp+d9v9c0SvpMa7B+AQO7n3E+iGW4rbNscQma0tlcoeKwPcmKM5YqIGqpGv jl1ETWtyL1bWD+9jj0KqgZJG9rjQmuVV5HQBJExqDPilrAy/8Y3XVkFfrxcRcWGjw5YU v5zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ti2BeWGG; 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 y1-v6si62041802plt.316.2018.06.11.07.21.49; Mon, 11 Jun 2018 07:22:03 -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=ti2BeWGG; 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 S934184AbeFKOTy (ORCPT + 99 others); Mon, 11 Jun 2018 10:19:54 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:45522 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933503AbeFKOGz (ORCPT ); Mon, 11 Jun 2018 10:06:55 -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=sqW1jfi9fXH0Wb9SlzcbfFhp+ufIQamOcMd7GrKgp30=; b=ti2BeWGG2O8VtFgPTXfuBL08A fYuk5wfFSIALiyRyiOVZYMYGq+cmtU7k/7WXmu/wpYRpkoqK/AbVGMoB/HOQ4tqx3PvwRRjOUurEe JI5AJhhxiDZt2xzHTex3R+REArl+nCwQmFWVa3J0S4I63THIuPrc8ogqn7p6LwNx6ZkxWgRHtq0ku 5tNiZUKBM26rVuzmNRYclzQueBCbuMka4yXBMeKWR08d2DxcTmJ2hg21SWBs6jeNwjwR8uW9n1MmE ewJyWeyMdDWApJSBc9BXzQW3QdLeCg5G9kOiJFQf/I03iUZ6UEEZ9tymI2JW/Fh9/gA/dWQrrfvuh J8mFNoFmQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTC-0004jI-4s; Mon, 11 Jun 2018 14:06:54 +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 33/72] page cache: Convert filemap_range_has_page to XArray Date: Mon, 11 Jun 2018 07:06:00 -0700 Message-Id: <20180611140639.17215-34-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> 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 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); -- 2.17.1