From: Matthew Wilcox <willy@infradead.org>
To: linux-mm@kvack.org
Subject: [PATCH 5/4] mm: Return head pages from find_get_entry
Date: Sat, 11 Jul 2020 04:31:56 +0100 [thread overview]
Message-ID: <20200711033156.GS12769@casper.infradead.org> (raw)
In-Reply-To: <20200710202642.21794-1-willy@infradead.org>
This was the original destination of the prior patch series. I have a
few places in the THP patch set which add calls to find_get_entry() and it
annoyed me that I was carefully calling find_subpage() in find_get_entry()
only to immediately call thp_head() to get back to the original subpage.
I'm not sure it's worth applying this as part of the patch series,
which is why I left it out earlier.
There are going to be some other functions which return only head pages.
I currently have a find_get_heads_range_tag() in my tree, which is
probably going to become find_get_entries_range_tag().
--- 8< ---
mm: Return head pages from find_get_entry
All the callers of find_get_entry() call compound_head() to get back to
the head page. They still do because compound_head() calls are hidden in
such functions as put_page() and lock_page(), but it lets us get rid of
a few calls.
diff --git a/mm/filemap.c b/mm/filemap.c
index f0ae9a6308cb..7e0a7d02e7aa 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1487,9 +1487,9 @@ EXPORT_SYMBOL(page_cache_prev_miss);
/**
* find_get_entry - find and get a page cache entry
* @mapping: the address_space to search
- * @offset: the page cache index
+ * @index: the page cache index
*
- * Looks up the page cache slot at @mapping & @offset. If there is a
+ * Looks up the page cache slot at @mapping & @index. If there is a
* page cache page, it is returned with an increased refcount.
*
* If the slot holds a shadow entry of a previously evicted page, or a
@@ -1497,9 +1497,9 @@ EXPORT_SYMBOL(page_cache_prev_miss);
*
* Return: the found page or shadow entry, %NULL if nothing is found.
*/
-struct page *find_get_entry(struct address_space *mapping, pgoff_t offset)
+struct page *find_get_entry(struct address_space *mapping, pgoff_t index)
{
- XA_STATE(xas, &mapping->i_pages, offset);
+ XA_STATE(xas, &mapping->i_pages, index);
struct page *page;
rcu_read_lock();
@@ -1527,7 +1527,6 @@ struct page *find_get_entry(struct address_space *mapping, pgoff_t offset)
put_page(page);
goto repeat;
}
- page = find_subpage(page, offset);
out:
rcu_read_unlock();
@@ -1537,9 +1536,9 @@ struct page *find_get_entry(struct address_space *mapping, pgoff_t offset)
/**
* find_lock_entry - locate, pin and lock a page cache entry
* @mapping: the address_space to search
- * @offset: the page cache index
+ * @index: the page cache index
*
- * Looks up the page cache slot at @mapping & @offset. If there is a
+ * Looks up the page cache slot at @mapping & @index. If there is a
* page cache page, it is returned locked and with an increased
* refcount.
*
@@ -1550,21 +1549,22 @@ struct page *find_get_entry(struct address_space *mapping, pgoff_t offset)
*
* Return: the found page or shadow entry, %NULL if nothing is found.
*/
-struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset)
+struct page *find_lock_entry(struct address_space *mapping, pgoff_t index)
{
struct page *page;
repeat:
- page = find_get_entry(mapping, offset);
+ page = find_get_entry(mapping, index);
if (page && !xa_is_value(page)) {
lock_page(page);
/* Has the page been truncated? */
- if (unlikely(page_mapping(page) != mapping)) {
+ if (unlikely(page->mapping != mapping)) {
unlock_page(page);
put_page(page);
goto repeat;
}
- VM_BUG_ON_PAGE(page_to_pgoff(page) != offset, page);
+ page = find_subpage(page, index);
+ VM_BUG_ON_PAGE(page_to_pgoff(page) != index, page);
}
return page;
}
@@ -1620,12 +1620,13 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
}
/* Has the page been truncated? */
- if (unlikely(compound_head(page)->mapping != mapping)) {
+ if (unlikely(page->mapping != mapping)) {
unlock_page(page);
put_page(page);
goto repeat;
}
- VM_BUG_ON_PAGE(page->index != index, page);
+ VM_BUG_ON_PAGE(page->index !=
+ (index & ~(thp_nr_pages(page) - 1)), page);
}
if (fgp_flags & FGP_ACCESSED)
@@ -1666,7 +1667,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
unlock_page(page);
}
- return page;
+ return find_subpage(page, index);
}
EXPORT_SYMBOL(pagecache_get_page);
diff --git a/mm/mincore.c b/mm/mincore.c
index abc24ca6f0f7..cda857110d44 100644
--- a/mm/mincore.c
+++ b/mm/mincore.c
@@ -58,8 +58,10 @@ struct page *find_get_swap_page(struct address_space *mapping, pgoff_t index)
struct swap_info_struct *si;
struct page *page = find_get_entry(mapping, index);
- if (!xa_is_value(page))
+ if (!page)
return page;
+ if (!xa_is_value(page))
+ return find_subpage(page, index);
if (!IS_ENABLED(CONFIG_SWAP) || !shmem_mapping(mapping))
return NULL;
prev parent reply other threads:[~2020-07-11 3:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-10 20:26 [PATCH 0/4] Remove/consolidate calls to find_get_entry Matthew Wilcox (Oracle)
2020-07-10 20:26 ` [PATCH 1/4] mm: Factor find_get_swap_page out of mincore_page Matthew Wilcox (Oracle)
2020-07-10 20:26 ` [PATCH 2/4] mm: Use find_get_swap_page in memcontrol Matthew Wilcox (Oracle)
2020-07-10 20:26 ` [PATCH 3/4] mm: Optimise madvise WILLNEED Matthew Wilcox (Oracle)
2020-07-10 20:26 ` [PATCH 4/4] proc: Optimise smaps for shmem entries Matthew Wilcox (Oracle)
2020-07-11 0:15 ` [PATCH 0/4] Remove/consolidate calls to find_get_entry William Kucharski
2020-07-11 3:31 ` Matthew Wilcox [this message]
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=20200711033156.GS12769@casper.infradead.org \
--to=willy@infradead.org \
--cc=linux-mm@kvack.org \
/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