Merge tag 'net-next-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev...
[linux-2.6-microblaze.git] / mm / filemap.c
index f6d36cc..e3b8987 100644 (file)
@@ -414,7 +414,7 @@ int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start,
                .range_end = end,
        };
 
-       if (!mapping_cap_writeback_dirty(mapping) ||
+       if (!mapping_can_writeback(mapping) ||
            !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
                return 0;
 
@@ -1645,19 +1645,19 @@ 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
- * page cache page, it is returned with an increased refcount.
+ * page cache page, the head page is returned 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.
  *
- * Return: the found page or shadow entry, %NULL if nothing is found.
+ * Return: The head 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();
@@ -1685,7 +1685,6 @@ repeat:
                put_page(page);
                goto repeat;
        }
-       page = find_subpage(page, offset);
 out:
        rcu_read_unlock();
 
@@ -1693,40 +1692,37 @@ out:
 }
 
 /**
- * find_lock_entry - locate, pin and lock a page cache entry
- * @mapping: the address_space to search
- * @offset: the page cache index
+ * 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 cache slot at @mapping & @offset.  If there is a
- * page cache page, it is returned locked and with an increased
- * refcount.
+ * 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.
  *
- * find_lock_entry() may sleep.
- *
- * Return: the found page or shadow entry, %NULL if nothing is found.
+ * 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 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);
+               VM_BUG_ON_PAGE(!thp_contains(page, index), page);
        }
        return page;
 }
-EXPORT_SYMBOL(find_lock_entry);
 
 /**
  * pagecache_get_page - Find and get a reference to a page.
@@ -1741,6 +1737,8 @@ EXPORT_SYMBOL(find_lock_entry);
  *
  * * %FGP_ACCESSED - The page will be marked accessed.
  * * %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_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.
@@ -1781,12 +1779,12 @@ repeat:
                }
 
                /* 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(!thp_contains(page, index), page);
        }
 
        if (fgp_flags & FGP_ACCESSED)
@@ -1796,11 +1794,13 @@ repeat:
                if (page_is_idle(page))
                        clear_page_idle(page);
        }
+       if (!(fgp_flags & FGP_HEAD))
+               page = find_subpage(page, index);
 
 no_page:
        if (!page && (fgp_flags & FGP_CREAT)) {
                int err;
-               if ((fgp_flags & FGP_WRITE) && mapping_cap_account_dirty(mapping))
+               if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping))
                        gfp_mask |= __GFP_WRITE;
                if (fgp_flags & FGP_NOFS)
                        gfp_mask &= ~__GFP_FS;
@@ -2793,42 +2793,42 @@ void filemap_map_pages(struct vm_fault *vmf,
        pgoff_t last_pgoff = start_pgoff;
        unsigned long max_idx;
        XA_STATE(xas, &mapping->i_pages, start_pgoff);
-       struct page *page;
+       struct page *head, *page;
        unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss);
 
        rcu_read_lock();
-       xas_for_each(&xas, page, end_pgoff) {
-               if (xas_retry(&xas, page))
+       xas_for_each(&xas, head, end_pgoff) {
+               if (xas_retry(&xas, head))
                        continue;
-               if (xa_is_value(page))
+               if (xa_is_value(head))
                        goto next;
 
                /*
                 * Check for a locked page first, as a speculative
                 * reference may adversely influence page migration.
                 */
-               if (PageLocked(page))
+               if (PageLocked(head))
                        goto next;
-               if (!page_cache_get_speculative(page))
+               if (!page_cache_get_speculative(head))
                        goto next;
 
                /* Has the page moved or been split? */
-               if (unlikely(page != xas_reload(&xas)))
+               if (unlikely(head != xas_reload(&xas)))
                        goto skip;
-               page = find_subpage(page, xas.xa_index);
+               page = find_subpage(head, xas.xa_index);
 
-               if (!PageUptodate(page) ||
+               if (!PageUptodate(head) ||
                                PageReadahead(page) ||
                                PageHWPoison(page))
                        goto skip;
-               if (!trylock_page(page))
+               if (!trylock_page(head))
                        goto skip;
 
-               if (page->mapping != mapping || !PageUptodate(page))
+               if (head->mapping != mapping || !PageUptodate(head))
                        goto unlock;
 
                max_idx = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE);
-               if (page->index >= max_idx)
+               if (xas.xa_index >= max_idx)
                        goto unlock;
 
                if (mmap_miss > 0)
@@ -2840,12 +2840,12 @@ void filemap_map_pages(struct vm_fault *vmf,
                last_pgoff = xas.xa_index;
                if (alloc_set_pte(vmf, page))
                        goto unlock;
-               unlock_page(page);
+               unlock_page(head);
                goto next;
 unlock:
-               unlock_page(page);
+               unlock_page(head);
 skip:
-               put_page(page);
+               put_page(head);
 next:
                /* Huge page is mapped? No need to proceed. */
                if (pmd_trans_huge(*vmf->pmd))