From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>,
William Kucharski <william.kucharski@oracle.com>,
Johannes Weiner <hannes@cmpxchg.org>, Jan Kara <jack@suse.cz>,
Yang Shi <yang.shi@linux.alibaba.com>,
Dave Chinner <dchinner@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 12/12] mm/filemap: Return only head pages from find_get_entries
Date: Mon, 14 Sep 2020 14:00:42 +0100 [thread overview]
Message-ID: <20200914130042.11442-13-willy@infradead.org> (raw)
In-Reply-To: <20200914130042.11442-1-willy@infradead.org>
All callers now expect head (and base) pages, and can handle multiple
head pages in a single batch, so make find_get_entries() behave that way.
Also take the opportunity to make it use the pagevec infrastructure
instead of open-coding how pvecs behave. This has the side-effect of
being able to append to a pagevec with existing contents, although we
don't make use of that functionality anywhere yet.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/pagemap.h | 2 --
mm/filemap.c | 36 ++++++++----------------------------
mm/internal.h | 2 ++
3 files changed, 10 insertions(+), 30 deletions(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 788c280737e0..50d2c39b47ab 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -413,8 +413,6 @@ static inline struct page *find_subpage(struct page *head, pgoff_t index)
return head + (index & (thp_nr_pages(head) - 1));
}
-unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
- pgoff_t end, struct pagevec *pvec, pgoff_t *indices);
unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
pgoff_t end, unsigned int nr_pages,
struct page **pages);
diff --git a/mm/filemap.c b/mm/filemap.c
index a4ad294a34dc..dbe3f7050897 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1807,49 +1807,29 @@ static inline struct page *xas_find_get_entry(struct xa_state *xas,
* the mapping. The entries are placed in @pvec. find_get_entries()
* takes a reference on any actual pages it returns.
*
- * The search returns a group of mapping-contiguous page cache entries
- * with ascending indexes. There may be holes in the indices due to
- * not-present pages.
+ * The entries have ascending indexes. The indices may not be consecutive
+ * due to not-present entries or THPs.
*
* Any shadow entries of evicted pages, or swap entries from
* shmem/tmpfs, are included in the returned array.
*
- * If it finds a Transparent Huge Page, head or tail, find_get_entries()
- * stops at that page: the caller is likely to have a better way to handle
- * the compound page as a whole, and then skip its extent, than repeatedly
- * calling find_get_entries() to return all its tails.
- *
- * Return: the number of pages and shadow entries which were found.
+ * Return: The number of entries which were found.
*/
unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
pgoff_t end, struct pagevec *pvec, pgoff_t *indices)
{
XA_STATE(xas, &mapping->i_pages, start);
struct page *page;
- unsigned int ret = 0;
- unsigned nr_entries = PAGEVEC_SIZE;
rcu_read_lock();
while ((page = 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.
- */
- if (!xa_is_value(page) && PageTransHuge(page) &&
- !PageHuge(page)) {
- page = find_subpage(page, xas.xa_index);
- nr_entries = ret + 1;
- }
-
- indices[ret] = xas.xa_index;
- pvec->pages[ret] = page;
- if (++ret == nr_entries)
+ indices[pvec->nr] = xas.xa_index;
+ if (!pagevec_add(pvec, page))
break;
}
rcu_read_unlock();
- pvec->nr = ret;
- return ret;
+ return pagevec_count(pvec);
}
/**
@@ -1868,8 +1848,8 @@ unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
* not returned.
*
* The entries have ascending indexes. The indices may not be consecutive
- * due to not-present entries, THP pages, pages which could not be locked
- * or pages under writeback.
+ * due to not-present entries, THPs, pages which could not be locked or
+ * pages under writeback.
*
* Return: The number of entries which were found.
*/
diff --git a/mm/internal.h b/mm/internal.h
index d17d9060902f..55da9860a54b 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -62,6 +62,8 @@ static inline void force_page_cache_readahead(struct address_space *mapping,
struct page *find_get_entry(struct address_space *mapping, pgoff_t index);
struct page *find_lock_entry(struct address_space *mapping, pgoff_t index);
+unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
+ pgoff_t end, struct pagevec *pvec, pgoff_t *indices);
unsigned find_lock_entries(struct address_space *mapping, pgoff_t start,
pgoff_t end, struct pagevec *pvec, pgoff_t *indices);
--
2.28.0
next prev parent reply other threads:[~2020-09-14 13:03 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-14 13:00 [PATCH v2 00/12] Overhaul multi-page lookups for THP Matthew Wilcox (Oracle)
2020-09-14 13:00 ` [PATCH v2 01/12] mm: Make pagecache tagged lookups return only head pages Matthew Wilcox (Oracle)
2020-09-29 9:13 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 02/12] mm/shmem: Use pagevec_lookup in shmem_unlock_mapping Matthew Wilcox (Oracle)
2020-09-29 8:28 ` Jan Kara
2020-09-29 18:36 ` Matthew Wilcox
2020-09-14 13:00 ` [PATCH v2 03/12] mm/filemap: Add helper for finding pages Matthew Wilcox (Oracle)
2020-09-29 8:27 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 04/12] mm/filemap: Add mapping_seek_hole_data Matthew Wilcox (Oracle)
2020-09-29 8:46 ` Jan Kara
2020-09-29 12:42 ` Matthew Wilcox
2020-09-29 13:39 ` Matthew Wilcox
2020-09-14 13:00 ` [PATCH v2 05/12] mm: Add and use find_lock_entries Matthew Wilcox (Oracle)
2020-09-29 8:58 ` Jan Kara
2020-09-29 12:48 ` Matthew Wilcox
2020-09-30 10:40 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 06/12] mm: Add an 'end' parameter to find_get_entries Matthew Wilcox (Oracle)
2020-09-14 13:00 ` [PATCH v2 07/12] mm: Add an 'end' parameter to pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-09-29 9:02 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 08/12] mm: Remove nr_entries parameter from pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-09-29 9:03 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 09/12] mm: Pass pvec directly to find_get_entries Matthew Wilcox (Oracle)
2020-09-29 9:07 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 10/12] mm: Remove pagevec_lookup_entries Matthew Wilcox (Oracle)
2020-09-29 9:08 ` Jan Kara
2020-09-14 13:00 ` [PATCH v2 11/12] mm/truncate,shmem: Handle truncates that split THPs Matthew Wilcox (Oracle)
2020-09-30 11:59 ` Jan Kara
2020-09-30 14:51 ` Matthew Wilcox
2020-09-14 13:00 ` Matthew Wilcox (Oracle) [this message]
2020-09-30 12:15 ` [PATCH v2 12/12] mm/filemap: Return only head pages from find_get_entries Jan Kara
2020-09-30 12:36 ` Matthew Wilcox
2020-09-30 17:08 ` Jan Kara
2020-09-30 17:23 ` Matthew Wilcox
2020-10-01 7:17 ` Jan Kara
2020-10-25 23:19 ` Matthew Wilcox
2020-10-26 9:11 ` Jan Kara
2020-09-28 20:13 ` [PATCH v2 00/12] Overhaul multi-page lookups for THP Matthew Wilcox
2020-09-29 8:50 ` William Kucharski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200914130042.11442-13-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=dchinner@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=william.kucharski@oracle.com \
--cc=yang.shi@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).