mm: convert find_get_incore_page() to filemap_get_incore_folio()

Return the containing folio instead of the precise page.  One of the
callers wants the folio and the other can do the folio->page conversion
itself.  Nets 442 bytes of text size reduction, 478 bytes removed and 36
bytes added.

Link: https://lkml.kernel.org/r/20221019183332.2802139-4-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Matthew Wilcox (Oracle) 2022-10-19 19:33:31 +01:00 committed by Andrew Morton
parent dd8095b15a
commit 524984ff66
4 changed files with 26 additions and 19 deletions

View File

@ -5648,15 +5648,21 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma,
static struct page *mc_handle_file_pte(struct vm_area_struct *vma, static struct page *mc_handle_file_pte(struct vm_area_struct *vma,
unsigned long addr, pte_t ptent) unsigned long addr, pte_t ptent)
{ {
unsigned long index;
struct folio *folio;
if (!vma->vm_file) /* anonymous vma */ if (!vma->vm_file) /* anonymous vma */
return NULL; return NULL;
if (!(mc.flags & MOVE_FILE)) if (!(mc.flags & MOVE_FILE))
return NULL; return NULL;
/* page is moved even if it's not RSS of this task(page-faulted). */ /* folio is moved even if it's not RSS of this task(page-faulted). */
/* shmem/tmpfs may report page out on swap: account for that too. */ /* shmem/tmpfs may report page out on swap: account for that too. */
return find_get_incore_page(vma->vm_file->f_mapping, index = linear_page_index(vma, addr);
linear_page_index(vma, addr)); folio = filemap_get_incore_folio(vma->vm_file->f_mapping, index);
if (!folio)
return NULL;
return folio_file_page(folio, index);
} }
/** /**

View File

@ -52,7 +52,7 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr,
static unsigned char mincore_page(struct address_space *mapping, pgoff_t index) static unsigned char mincore_page(struct address_space *mapping, pgoff_t index)
{ {
unsigned char present = 0; unsigned char present = 0;
struct page *page; struct folio *folio;
/* /*
* When tmpfs swaps out a page from a file, any process mapping that * When tmpfs swaps out a page from a file, any process mapping that
@ -60,10 +60,10 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t index)
* any other file mapping (ie. marked !present and faulted in with * any other file mapping (ie. marked !present and faulted in with
* tmpfs's .fault). So swapped out tmpfs mappings are tested here. * tmpfs's .fault). So swapped out tmpfs mappings are tested here.
*/ */
page = find_get_incore_page(mapping, index); folio = filemap_get_incore_folio(mapping, index);
if (page) { if (folio) {
present = PageUptodate(page); present = folio_test_uptodate(folio);
put_page(page); folio_put(folio);
} }
return present; return present;

View File

@ -41,7 +41,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
unsigned long end); unsigned long end);
struct folio *swap_cache_get_folio(swp_entry_t entry, struct folio *swap_cache_get_folio(swp_entry_t entry,
struct vm_area_struct *vma, unsigned long addr); struct vm_area_struct *vma, unsigned long addr);
struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index); struct folio *filemap_get_incore_folio(struct address_space *mapping,
pgoff_t index);
struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
struct vm_area_struct *vma, struct vm_area_struct *vma,
@ -105,9 +106,10 @@ static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
} }
static inline static inline
struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index) struct folio *filemap_get_incore_folio(struct address_space *mapping,
pgoff_t index)
{ {
return find_get_page(mapping, index); return filemap_get_folio(mapping, index);
} }
static inline bool add_to_swap(struct folio *folio) static inline bool add_to_swap(struct folio *folio)

View File

@ -373,16 +373,17 @@ struct folio *swap_cache_get_folio(swp_entry_t entry,
} }
/** /**
* find_get_incore_page - Find and get a page from the page or swap caches. * filemap_get_incore_folio - Find and get a folio from the page or swap caches.
* @mapping: The address_space to search. * @mapping: The address_space to search.
* @index: The page cache index. * @index: The page cache index.
* *
* This differs from find_get_page() in that it will also look for the * This differs from filemap_get_folio() in that it will also look for the
* page in the swap cache. * folio in the swap cache.
* *
* Return: The found page or %NULL. * Return: The found folio or %NULL.
*/ */
struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index) struct folio *filemap_get_incore_folio(struct address_space *mapping,
pgoff_t index)
{ {
swp_entry_t swp; swp_entry_t swp;
struct swap_info_struct *si; struct swap_info_struct *si;
@ -405,9 +406,7 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
folio = filemap_get_folio(swap_address_space(swp), index); folio = filemap_get_folio(swap_address_space(swp), index);
put_swap_device(si); put_swap_device(si);
out: out:
if (!folio) return folio;
return NULL;
return folio_file_page(folio, index);
} }
struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,