]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: add FGP_ENTRY
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 31 Dec 2020 22:04:15 +0000 (22:04 +0000)
committerJohannes Weiner <hannes@cmpxchg.org>
Thu, 31 Dec 2020 22:04:15 +0000 (22:04 +0000)
The functionality of find_lock_entry() and find_get_entry() can be
provided by pagecache_get_page(), which lets us delete find_lock_entry()
and make find_get_entry() static.

Link: https://lkml.kernel.org/r/20201112212641.27837-5-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/pagemap.h
mm/filemap.c
mm/internal.h
mm/shmem.c
mm/swap_state.c

index d5570deff4003f0cec29eed2cfbb77b06a8f0cec..f33661c1eeb0a299d8ad3ee5b8a963cfe6f90f0a 100644 (file)
@@ -315,6 +315,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
 #define FGP_NOWAIT             0x00000020
 #define FGP_FOR_MMAP           0x00000040
 #define FGP_HEAD               0x00000080
+#define FGP_ENTRY              0x00000100
 
 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
                int fgp_flags, gfp_t cache_gfp_mask);
index ae854def09f1e2e5ecf42686fbcfbfb3cc4aa1e0..a1afdba8bc6eec4662133118d75422cdaff9d0d4 100644 (file)
@@ -1671,7 +1671,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
 }
 EXPORT_SYMBOL(page_cache_prev_miss);
 
-/**
+/*
  * find_get_entry - find and get a page cache entry
  * @mapping: the address_space to search
  * @index: The page cache index.
@@ -1684,7 +1684,7 @@ EXPORT_SYMBOL(page_cache_prev_miss);
  *
  * Return: The head page or shadow entry, %NULL if nothing is found.
  */
-struct page *find_get_entry(struct address_space *mapping, pgoff_t index)
+static struct page *find_get_entry(struct address_space *mapping, pgoff_t index)
 {
        XA_STATE(xas, &mapping->i_pages, index);
        struct page *page;
@@ -1720,39 +1720,6 @@ out:
        return page;
 }
 
-/**
- * find_lock_entry - Locate and lock a page cache entry.
- * @mapping: The address_space to search.
- * @index: The page cache index.
- *
- * Looks up the page at @mapping & @index.  If there is a page in the
- * cache, the head page is returned locked and with an increased refcount.
- *
- * If the slot holds a shadow entry of a previously evicted page, or a
- * swap entry from shmem/tmpfs, it is returned.
- *
- * Context: May sleep.
- * Return: The head page or shadow entry, %NULL if nothing is found.
- */
-struct page *find_lock_entry(struct address_space *mapping, pgoff_t index)
-{
-       struct page *page;
-
-repeat:
-       page = find_get_entry(mapping, index);
-       if (page && !xa_is_value(page)) {
-               lock_page(page);
-               /* Has the page been truncated? */
-               if (unlikely(page->mapping != mapping)) {
-                       unlock_page(page);
-                       put_page(page);
-                       goto repeat;
-               }
-               VM_BUG_ON_PAGE(!thp_contains(page, index), page);
-       }
-       return page;
-}
-
 /**
  * pagecache_get_page - Find and get a reference to a page.
  * @mapping: The address_space to search.
@@ -1768,6 +1735,8 @@ repeat:
  * * %FGP_LOCK - The page is returned locked.
  * * %FGP_HEAD - If the page is present and a THP, return the head page
  *   rather than the exact page specified by the index.
+ * * %FGP_ENTRY - If there is a shadow / swap / DAX entry, return it
+ *   instead of allocating a new page to replace it.
  * * %FGP_CREAT - If no page is present then a new page is allocated using
  *   @gfp_mask and added to the page cache and the VM's LRU list.
  *   The page is returned locked and with an increased refcount.
@@ -1792,8 +1761,11 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
 
 repeat:
        page = find_get_entry(mapping, index);
-       if (xa_is_value(page))
+       if (xa_is_value(page)) {
+               if (fgp_flags & FGP_ENTRY)
+                       return page;
                page = NULL;
+       }
        if (!page)
                goto no_page;
 
index 25d2b2439f19f27d788944c2f18bd563e94b601a..eed74f1e614725a90a943b3e2a30fc39d4f52cd8 100644 (file)
@@ -60,9 +60,6 @@ static inline void force_page_cache_readahead(struct address_space *mapping,
        force_page_cache_ra(&ractl, &file->f_ra, nr_to_read);
 }
 
-struct page *find_get_entry(struct address_space *mapping, pgoff_t index);
-struct page *find_lock_entry(struct address_space *mapping, pgoff_t index);
-
 /**
  * page_evictable - test whether a page is evictable
  * @page: the page to test
index e9d6ffdbdd7c1e43ff42e9d91e20701f918722cd..e471b91c810a8813378f5c609383c015c676f48b 100644 (file)
@@ -1810,7 +1810,8 @@ repeat:
        sbinfo = SHMEM_SB(inode->i_sb);
        charge_mm = vma ? vma->vm_mm : current->mm;
 
-       page = find_lock_entry(mapping, index);
+       page = pagecache_get_page(mapping, index,
+                                       FGP_ENTRY | FGP_HEAD | FGP_LOCK, 0);
        if (xa_is_value(page)) {
                error = shmem_swapin_page(inode, index, &page,
                                          sgp, gfp, vma, fault_type);
index d3ccfab6c9b7687be059bffe3ea4d2253580fb48..6ecc84448d759042745c99bc7ca59167d8c66ba6 100644 (file)
@@ -427,7 +427,8 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
 {
        swp_entry_t swp;
        struct swap_info_struct *si;
-       struct page *page = find_get_entry(mapping, index);
+       struct page *page = pagecache_get_page(mapping, index,
+                                               FGP_ENTRY | FGP_HEAD, 0);
 
        if (!page)
                return page;