[PATCH 11/15] mm/rmap, gup: use folio_page() for PageAnonExclusive and gup_must_unshare
From: Nilay Vaish
Date: Tue Sep 29 2026 - 17:55:01 EST
As part of the memdescs effort, struct folio will be allocated
separately from struct page and will no longer overlay the head page.
Replace &folio->page with folio_page(folio, 0) when checking or setting
PageAnonExclusive() in folio_add_new_anon_rmap(),
hugetlb_add_anon_rmap(), hugetlb_add_new_anon_rmap(), and
sanity_check_pinned_pages(), and when calling gup_must_unshare() in
gup_fast_pmd_leaf() and gup_fast_pud_leaf().
No functional change intended.
Assisted-by: LLM
Signed-off-by: Nilay Vaish <nilayvaish@xxxxxxxxxx>
---
mm/gup.c | 11 +++++++----
mm/rmap.c | 10 +++++-----
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index 8e9ef5ee7498..1ce7ea5e7abb 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -59,10 +59,11 @@ static inline void sanity_check_pinned_pages(struct page **pages,
!folio_test_anon(folio))
continue;
if (!folio_test_large(folio) || folio_test_hugetlb(folio))
- VM_WARN_ON_ONCE_FOLIO(!PageAnonExclusive(&folio->page), folio);
+ VM_WARN_ON_ONCE_FOLIO(!PageAnonExclusive(folio_page(folio, 0)),
+ folio);
else
/* Either a PTE-mapped or a PMD-mapped THP. */
- VM_WARN_ON_ONCE_PAGE(!PageAnonExclusive(&folio->page) &&
+ VM_WARN_ON_ONCE_PAGE(!PageAnonExclusive(folio_page(folio, 0)) &&
!PageAnonExclusive(page), page);
}
}
@@ -2957,7 +2958,8 @@ static unsigned long gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp,
gup_put_folio(folio, nr_pages, flags);
return 0;
}
- if (!pmd_write(orig) && gup_must_unshare(NULL, flags, &folio->page)) {
+ if (!pmd_write(orig) &&
+ gup_must_unshare(NULL, flags, folio_page(folio, 0))) {
gup_put_folio(folio, nr_pages, flags);
return 0;
}
@@ -2999,7 +3001,8 @@ static unsigned long gup_fast_pud_leaf(pud_t orig, pud_t *pudp,
return 0;
}
- if (!pud_write(orig) && gup_must_unshare(NULL, flags, &folio->page)) {
+ if (!pud_write(orig) &&
+ gup_must_unshare(NULL, flags, folio_page(folio, 0))) {
gup_put_folio(folio, nr_pages, flags);
return 0;
}
diff --git a/mm/rmap.c b/mm/rmap.c
index fbd66a2823b7..cd1cf570c770 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1668,7 +1668,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
/* increment count (starts at -1) */
atomic_set(&folio->_mapcount, 0);
if (exclusive)
- SetPageAnonExclusive(&folio->page);
+ SetPageAnonExclusive(folio_page(folio, 0));
} else if (!folio_test_pmd_mappable(folio)) {
int i;
@@ -1694,7 +1694,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT))
atomic_set(&folio->_nr_pages_mapped, ENTIRELY_MAPPED);
if (exclusive)
- SetPageAnonExclusive(&folio->page);
+ SetPageAnonExclusive(folio_page(folio, 0));
nr_pmdmapped = nr;
}
@@ -3187,9 +3187,9 @@ void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
atomic_inc(&folio->_entire_mapcount);
atomic_inc(&folio->_large_mapcount);
if (flags & RMAP_EXCLUSIVE)
- SetPageAnonExclusive(&folio->page);
+ SetPageAnonExclusive(folio_page(folio, 0));
VM_WARN_ON_FOLIO(folio_entire_mapcount(folio) > 1 &&
- PageAnonExclusive(&folio->page), folio);
+ PageAnonExclusive(folio_page(folio, 0)), folio);
}
void hugetlb_add_new_anon_rmap(struct folio *folio,
@@ -3203,6 +3203,6 @@ void hugetlb_add_new_anon_rmap(struct folio *folio,
atomic_set(&folio->_large_mapcount, 0);
folio_clear_hugetlb_restore_reserve(folio);
__folio_set_anon(folio, vma, address, true);
- SetPageAnonExclusive(&folio->page);
+ SetPageAnonExclusive(folio_page(folio, 0));
}
#endif /* CONFIG_HUGETLB_PAGE */
--
2.56.0.rc1.315.gc6ed9934b7-goog