From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EB78C2D0A3 for ; Mon, 26 Oct 2020 04:14:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1E7A022256 for ; Mon, 26 Oct 2020 04:14:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YP8CA8T0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E7A022256 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 990FF6B0074; Mon, 26 Oct 2020 00:14:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9196C6B0075; Mon, 26 Oct 2020 00:14:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B9076B007B; Mon, 26 Oct 2020 00:14:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 457FD6B0074 for ; Mon, 26 Oct 2020 00:14:30 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D6FA58249980 for ; Mon, 26 Oct 2020 04:14:29 +0000 (UTC) X-FDA: 77412759858.26.bell57_231687d27270 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id BA34D1804B65A for ; Mon, 26 Oct 2020 04:14:29 +0000 (UTC) X-HE-Tag: bell57_231687d27270 X-Filterd-Recvd-Size: 6140 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 04:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=DLWB4TNbNLy+vkO6OI9SCJlRakguX3c3DViMXWpue3Y=; b=YP8CA8T0rij4qO56RnbwxvhtfQ Ot5Cy3FbS062Jt0im9h7XCoMlLQkxBkqf4IWbY+x8qNyVKsWQhEytO4Q+86JuHwy9CnyUtck2xTBi SZ5C7nI+T9ysi5m+qSddHtAdsSEGvQNKqLaAowWFBxboDf3PgY8mREObTilfMMNhYV5vVrarkqX/g lPtWTaSjQjUkABJZx9Jo69qy+ExvRgnzOanbG3AZ1KkSrAKBQ52HdqIHfEOjSQ5lDCqwzVKsZW+d9 1clJATtpMkWPRXo+cRNEMhuvJSS2+YAQu8+9Tw1bxPPubxcaVpI3CDjH+cSb/v7oJe9SxOpuiuRjR B/tZX1CA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kWttb-0006a6-Eu; Mon, 26 Oct 2020 04:14:11 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, Andrew Morton , Hugh Dickins , Johannes Weiner , Yang Shi , Dave Chinner , linux-kernel@vger.kernel.org, Jan Kara , William Kucharski Subject: [PATCH v3 06/12] mm: Add an 'end' parameter to find_get_entries Date: Mon, 26 Oct 2020 04:14:02 +0000 Message-Id: <20201026041408.25230-7-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201026041408.25230-1-willy@infradead.org> References: <20201026041408.25230-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: This simplifies the callers and leads to a more efficient implementation since the XArray has this functionality already. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara Reviewed-by: William Kucharski --- include/linux/pagemap.h | 4 ++-- mm/filemap.c | 9 +++++---- mm/shmem.c | 10 ++-------- mm/swap.c | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 5f3e829c91fd..5b425f666bc5 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -450,8 +450,8 @@ static inline struct page *find_subpage(struct page *= head, pgoff_t index) } =20 unsigned find_get_entries(struct address_space *mapping, pgoff_t start, - unsigned int nr_entries, struct page **entries, - pgoff_t *indices); + pgoff_t end, unsigned int nr_entries, struct page **entries, + pgoff_t *indices); unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *st= art, pgoff_t end, unsigned int nr_pages, struct page **pages); diff --git a/mm/filemap.c b/mm/filemap.c index 9a33d1b8cef6..6ed2422426d2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1897,6 +1897,7 @@ static inline struct page *xas_find_get_entry(struc= t xa_state *xas, * find_get_entries - gang pagecache lookup * @mapping: The address_space to search * @start: The starting page cache index + * @end: The final page index (inclusive). * @nr_entries: The maximum number of entries * @entries: Where the resulting entries are placed * @indices: The cache indices corresponding to the entries in @entries @@ -1920,9 +1921,9 @@ static inline struct page *xas_find_get_entry(struc= t xa_state *xas, * * Return: the number of pages and shadow entries which were found. */ -unsigned find_get_entries(struct address_space *mapping, - pgoff_t start, unsigned int nr_entries, - struct page **entries, pgoff_t *indices) +unsigned find_get_entries(struct address_space *mapping, pgoff_t start, + pgoff_t end, unsigned int nr_entries, struct page **entries, + pgoff_t *indices) { XA_STATE(xas, &mapping->i_pages, start); struct page *page; @@ -1932,7 +1933,7 @@ unsigned find_get_entries(struct address_space *map= ping, return 0; =20 rcu_read_lock(); - while ((page =3D xas_find_get_entry(&xas, ULONG_MAX, XA_PRESENT))) { + while ((page =3D xas_find_get_entry(&xas, end, XA_PRESENT))) { /* * Terminate early on finding a THP, to allow the caller to * handle it all at once; but continue if this is hugetlbfs. diff --git a/mm/shmem.c b/mm/shmem.c index ef34271cad2d..27b93b738ea0 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -913,8 +913,6 @@ static void shmem_undo_range(struct inode *inode, lof= f_t lstart, loff_t lend, struct page *page =3D pvec.pages[i]; =20 index =3D indices[i]; - if (index >=3D end) - break; =20 if (xa_is_value(page)) { if (unfalloc) @@ -967,9 +965,8 @@ static void shmem_undo_range(struct inode *inode, lof= f_t lstart, loff_t lend, while (index < end) { cond_resched(); =20 - pvec.nr =3D find_get_entries(mapping, index, - min(end - index, (pgoff_t)PAGEVEC_SIZE), - pvec.pages, indices); + pvec.nr =3D find_get_entries(mapping, index, end - 1, + PAGEVEC_SIZE, pvec.pages, indices); if (!pvec.nr) { /* If all gone or hole-punch or unfalloc, we're done */ if (index =3D=3D start || end !=3D -1) @@ -982,9 +979,6 @@ static void shmem_undo_range(struct inode *inode, lof= f_t lstart, loff_t lend, struct page *page =3D pvec.pages[i]; =20 index =3D indices[i]; - if (index >=3D end) - break; - if (xa_is_value(page)) { if (unfalloc) continue; diff --git a/mm/swap.c b/mm/swap.c index 47a47681c86b..9b0836cda971 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -1099,7 +1099,7 @@ unsigned pagevec_lookup_entries(struct pagevec *pve= c, pgoff_t start, unsigned nr_entries, pgoff_t *indices) { - pvec->nr =3D find_get_entries(mapping, start, nr_entries, + pvec->nr =3D find_get_entries(mapping, start, ULONG_MAX, nr_entries, pvec->pages, indices); return pagevec_count(pvec); } --=20 2.28.0