diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 90a9052b8384..531e47b6eed3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1372,6 +1372,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf) pmd_t entry; page_move_anon_rmap(page, vma); + SetPageAnonExclusive(page); folio_unlock(folio); reuse: if (unlikely(unshare)) { diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4b517a75f8fe..011effee5f62 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5581,8 +5581,10 @@ retry_avoidcopy: * owner and can reuse this page. */ if (page_mapcount(old_page) == 1 && PageAnon(old_page)) { - if (!PageAnonExclusive(old_page)) + if (!PageAnonExclusive(old_page)) { page_move_anon_rmap(old_page, vma); + SetPageAnonExclusive(old_page); + } if (likely(!unshare)) set_huge_ptep_writable(vma, haddr, ptep); diff --git a/mm/memory.c b/mm/memory.c index ee80a70947f8..921de73f5b21 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3561,6 +3561,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) * sunglasses. Hit it. */ page_move_anon_rmap(vmf->page, vma); + SetPageAnonExclusive(vmf->page); folio_unlock(folio); reuse: if (unlikely(unshare)) { diff --git a/mm/rmap.c b/mm/rmap.c index 992502845a7d..c80af87c3376 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1140,7 +1140,6 @@ void page_move_anon_rmap(struct page *page, struct vm_area_struct *vma) * folio_test_anon()) will not see one without the other. */ WRITE_ONCE(folio->mapping, anon_vma); - SetPageAnonExclusive(page); } /**