Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/hugetlb: use a folio in hugetlb_wp()

We can replace nine implict calls to compound_head() with one by using
old_folio. The page we get back is always a head page, so we just convert
old_page to old_folio.

Link: https://lkml.kernel.org/r/20230606062013.2947002-3-zhangpeng362@huawei.com
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

ZhangPeng and committed by
Andrew Morton
959a78b6 ad27ce20

+16 -16
+16 -16
mm/hugetlb.c
··· 5540 5540 const bool unshare = flags & FAULT_FLAG_UNSHARE; 5541 5541 pte_t pte = huge_ptep_get(ptep); 5542 5542 struct hstate *h = hstate_vma(vma); 5543 - struct page *old_page; 5543 + struct folio *old_folio; 5544 5544 struct folio *new_folio; 5545 5545 int outside_reserve = 0; 5546 5546 vm_fault_t ret = 0; ··· 5571 5571 return 0; 5572 5572 } 5573 5573 5574 - old_page = pte_page(pte); 5574 + old_folio = page_folio(pte_page(pte)); 5575 5575 5576 5576 delayacct_wpcopy_start(); 5577 5577 ··· 5580 5580 * If no-one else is actually using this page, we're the exclusive 5581 5581 * owner and can reuse this page. 5582 5582 */ 5583 - if (page_mapcount(old_page) == 1 && PageAnon(old_page)) { 5584 - if (!PageAnonExclusive(old_page)) 5585 - page_move_anon_rmap(old_page, vma); 5583 + if (folio_mapcount(old_folio) == 1 && folio_test_anon(old_folio)) { 5584 + if (!PageAnonExclusive(&old_folio->page)) 5585 + page_move_anon_rmap(&old_folio->page, vma); 5586 5586 if (likely(!unshare)) 5587 5587 set_huge_ptep_writable(vma, haddr, ptep); 5588 5588 5589 5589 delayacct_wpcopy_end(); 5590 5590 return 0; 5591 5591 } 5592 - VM_BUG_ON_PAGE(PageAnon(old_page) && PageAnonExclusive(old_page), 5593 - old_page); 5592 + VM_BUG_ON_PAGE(folio_test_anon(old_folio) && 5593 + PageAnonExclusive(&old_folio->page), &old_folio->page); 5594 5594 5595 5595 /* 5596 5596 * If the process that created a MAP_PRIVATE mapping is about to ··· 5602 5602 * of the full address range. 5603 5603 */ 5604 5604 if (is_vma_resv_set(vma, HPAGE_RESV_OWNER) && 5605 - page_folio(old_page) != pagecache_folio) 5605 + old_folio != pagecache_folio) 5606 5606 outside_reserve = 1; 5607 5607 5608 - get_page(old_page); 5608 + folio_get(old_folio); 5609 5609 5610 5610 /* 5611 5611 * Drop page table lock as buddy allocator may be called. It will ··· 5627 5627 pgoff_t idx; 5628 5628 u32 hash; 5629 5629 5630 - put_page(old_page); 5630 + folio_put(old_folio); 5631 5631 /* 5632 5632 * Drop hugetlb_fault_mutex and vma_lock before 5633 5633 * unmapping. unmapping needs to hold vma_lock ··· 5642 5642 hugetlb_vma_unlock_read(vma); 5643 5643 mutex_unlock(&hugetlb_fault_mutex_table[hash]); 5644 5644 5645 - unmap_ref_private(mm, vma, old_page, haddr); 5645 + unmap_ref_private(mm, vma, &old_folio->page, haddr); 5646 5646 5647 5647 mutex_lock(&hugetlb_fault_mutex_table[hash]); 5648 5648 hugetlb_vma_lock_read(vma); ··· 5672 5672 goto out_release_all; 5673 5673 } 5674 5674 5675 - if (copy_user_large_folio(new_folio, page_folio(old_page), address, vma)) { 5675 + if (copy_user_large_folio(new_folio, old_folio, address, vma)) { 5676 5676 ret = VM_FAULT_HWPOISON_LARGE; 5677 5677 goto out_release_all; 5678 5678 } ··· 5694 5694 /* Break COW or unshare */ 5695 5695 huge_ptep_clear_flush(vma, haddr, ptep); 5696 5696 mmu_notifier_invalidate_range(mm, range.start, range.end); 5697 - page_remove_rmap(old_page, vma, true); 5697 + page_remove_rmap(&old_folio->page, vma, true); 5698 5698 hugepage_add_new_anon_rmap(new_folio, vma, haddr); 5699 5699 if (huge_pte_uffd_wp(pte)) 5700 5700 newpte = huge_pte_mkuffd_wp(newpte); 5701 5701 set_huge_pte_at(mm, haddr, ptep, newpte); 5702 5702 folio_set_hugetlb_migratable(new_folio); 5703 5703 /* Make the old page be freed below */ 5704 - new_folio = page_folio(old_page); 5704 + new_folio = old_folio; 5705 5705 } 5706 5706 spin_unlock(ptl); 5707 5707 mmu_notifier_invalidate_range_end(&range); ··· 5710 5710 * No restore in case of successful pagetable update (Break COW or 5711 5711 * unshare) 5712 5712 */ 5713 - if (new_folio != page_folio(old_page)) 5713 + if (new_folio != old_folio) 5714 5714 restore_reserve_on_error(h, vma, haddr, new_folio); 5715 5715 folio_put(new_folio); 5716 5716 out_release_old: 5717 - put_page(old_page); 5717 + folio_put(old_folio); 5718 5718 5719 5719 spin_lock(ptl); /* Caller expects lock to be held */ 5720 5720