]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mm/gup: Convert gup_pte_range() to use a folio
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 10 Dec 2021 20:54:11 +0000 (15:54 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 21 Mar 2022 16:56:35 +0000 (12:56 -0400)
We still call try_grab_folio() once per PTE; a future patch could
optimise to just adjust the reference count for each page within
the folio.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
mm/gup.c

index 014004102e26e6e9c142969e5b34e5836e4e5c17..94e0e2a130fc2bf24ef996b163142edeadbde12f 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2232,7 +2232,8 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
        ptem = ptep = pte_offset_map(&pmd, addr);
        do {
                pte_t pte = ptep_get_lockless(ptep);
-               struct page *head, *page;
+               struct page *page;
+               struct folio *folio;
 
                /*
                 * Similar to the PMD case below, NUMA hinting must take slow
@@ -2259,22 +2260,20 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
                VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
                page = pte_page(pte);
 
-               head = try_grab_compound_head(page, 1, flags);
-               if (!head)
+               folio = try_grab_folio(page, 1, flags);
+               if (!folio)
                        goto pte_unmap;
 
                if (unlikely(page_is_secretmem(page))) {
-                       put_compound_head(head, 1, flags);
+                       gup_put_folio(folio, 1, flags);
                        goto pte_unmap;
                }
 
                if (unlikely(pte_val(pte) != pte_val(*ptep))) {
-                       put_compound_head(head, 1, flags);
+                       gup_put_folio(folio, 1, flags);
                        goto pte_unmap;
                }
 
-               VM_BUG_ON_PAGE(compound_head(page) != head, page);
-
                /*
                 * We need to make the page accessible if and only if we are
                 * going to access its content (the FOLL_PIN case).  Please
@@ -2284,14 +2283,13 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
                if (flags & FOLL_PIN) {
                        ret = arch_make_page_accessible(page);
                        if (ret) {
-                               unpin_user_page(page);
+                               gup_put_folio(folio, 1, flags);
                                goto pte_unmap;
                        }
                }
-               SetPageReferenced(page);
+               folio_set_referenced(folio);
                pages[*nr] = page;
                (*nr)++;
-
        } while (ptep++, addr += PAGE_SIZE, addr != end);
 
        ret = 1;