mm: convert split_huge_pages_pid() to use a folio
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 16 Aug 2023 15:12:01 +0000 (16:12 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 21 Aug 2023 21:28:45 +0000 (14:28 -0700)
Replaces five calls to compound_head with one.

Link: https://lkml.kernel.org/r/20230816151201.3655946-14-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Yanteng Si <siyanteng@loongson.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/huge_memory.c

index 2fe1ea187b6b4555e852c95c5cf10091ec2156b9..213bb1e3383094c1f731669d31d6ccc458e21450 100644 (file)
@@ -584,14 +584,11 @@ void folio_prep_large_rmappable(struct folio *folio)
        folio_set_large_rmappable(folio);
 }
 
-static inline bool is_transparent_hugepage(struct page *page)
+static inline bool is_transparent_hugepage(struct folio *folio)
 {
-       struct folio *folio;
-
-       if (!PageCompound(page))
+       if (!folio_test_large(folio))
                return false;
 
-       folio = page_folio(page);
        return is_huge_zero_page(&folio->page) ||
                folio_test_large_rmappable(folio);
 }
@@ -3012,6 +3009,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
        for (addr = vaddr_start; addr < vaddr_end; addr += PAGE_SIZE) {
                struct vm_area_struct *vma = vma_lookup(mm, addr);
                struct page *page;
+               struct folio *folio;
 
                if (!vma)
                        break;
@@ -3028,22 +3026,23 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
                if (IS_ERR_OR_NULL(page))
                        continue;
 
-               if (!is_transparent_hugepage(page))
+               folio = page_folio(page);
+               if (!is_transparent_hugepage(folio))
                        goto next;
 
                total++;
-               if (!can_split_folio(page_folio(page), NULL))
+               if (!can_split_folio(folio, NULL))
                        goto next;
 
-               if (!trylock_page(page))
+               if (!folio_trylock(folio))
                        goto next;
 
-               if (!split_huge_page(page))
+               if (!split_folio(folio))
                        split++;
 
-               unlock_page(page);
+               folio_unlock(folio);
 next:
-               put_page(page);
+               folio_put(folio);
                cond_resched();
        }
        mmap_read_unlock(mm);