From: Nilay Vaish <nilayvaish@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>,
David Hildenbrand <david@kernel.org>,
Greg Thelen <gthelen@google.com>,
Roman Gushchin <kfree@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Nilay Vaish <nilayvaish@google.com>
Subject: [PATCH 12/15] mm/ksm, userfaultfd: replace &folio->page with folio_page()
Date: Tue, 29 Sep 2026 14:52:03 -0700 [thread overview]
Message-ID: <20260929215206.516490-13-nilayvaish@google.com> (raw)
In-Reply-To: <20260929215206.516490-1-nilayvaish@google.com>
As part of the memdescs effort, struct folio will be allocated
separately from struct page and will no longer overlay the head page.
Replace direct &folio->page, &kfolio->page, &tree_folio->page, and
&src_folio->page uses with folio_page(..., 0) across KSM tree
comparison/merging and userfaultfd page population/movement paths.
No functional change intended.
Assisted-by: LLM
Signed-off-by: Nilay Vaish <nilayvaish@google.com>
---
mm/ksm.c | 16 ++++++++++------
mm/userfaultfd.c | 14 ++++++++------
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index f33523a84a1a..bb8c564d9ffb 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1112,7 +1112,8 @@ struct ksm_stable_node *folio_stable_node(const struct folio *folio)
static inline void folio_set_stable_node(struct folio *folio,
struct ksm_stable_node *stable_node)
{
- VM_WARN_ON_FOLIO(folio_test_anon(folio) && PageAnonExclusive(&folio->page), folio);
+ VM_WARN_ON_FOLIO(folio_test_anon(folio) &&
+ PageAnonExclusive(folio_page(folio, 0)), folio);
WRITE_ONCE(folio->mapping,
(void *)((unsigned long)stable_node | FOLIO_MAPPING_KSM));
}
@@ -1324,7 +1325,7 @@ static int write_protect_page(struct vm_area_struct *vma, struct folio *folio,
if (unlikely(!pte_present(entry)))
goto out_unlock;
- anon_exclusive = PageAnonExclusive(&folio->page);
+ anon_exclusive = PageAnonExclusive(folio_page(folio, 0));
if (pte_write(entry) || pte_dirty(entry) ||
anon_exclusive || mm_tlb_flush_pending(mm)) {
swapped = folio_test_swapcache(folio);
@@ -1355,7 +1356,8 @@ static int write_protect_page(struct vm_area_struct *vma, struct folio *folio,
/* See folio_try_share_anon_rmap_pte(): clear PTE first. */
if (anon_exclusive &&
- folio_try_share_anon_rmap_pte(folio, &folio->page)) {
+ folio_try_share_anon_rmap_pte(folio,
+ folio_page(folio, 0))) {
set_pte_at(mm, pvmw.address, pvmw.pte, entry);
goto out_unlock;
}
@@ -1893,7 +1895,7 @@ static struct folio *stable_tree_search(struct page *page)
goto again;
}
- ret = memcmp_pages(page, &tree_folio->page);
+ ret = memcmp_pages(page, folio_page(tree_folio, 0));
folio_put(tree_folio);
parent = *new;
@@ -2100,7 +2102,8 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio)
goto again;
}
- ret = memcmp_pages(&kfolio->page, &tree_folio->page);
+ ret = memcmp_pages(folio_page(kfolio, 0),
+ folio_page(tree_folio, 0));
folio_put(tree_folio);
parent = *new;
@@ -2333,7 +2336,8 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
if (kfolio == ERR_PTR(-EBUSY))
return;
- err = try_to_merge_with_ksm_page(rmap_item, page, &kfolio->page);
+ err = try_to_merge_with_ksm_page(rmap_item, page,
+ folio_page(kfolio, 0));
if (!err) {
/*
* The page was successfully merged:
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 3c7fd39deb13..a39d7d40a76b 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -565,7 +565,7 @@ static int __mfill_atomic_pte(struct mfill_state *state,
goto err_folio_put;
}
} else if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE)) {
- clear_user_highpage(&folio->page, state->dst_addr);
+ clear_user_highpage(folio_page(folio, 0), state->dst_addr);
} else {
VM_WARN_ONCE(1, "Unknown UFFDIO operation, flags: %x", flags);
}
@@ -584,7 +584,7 @@ static int __mfill_atomic_pte(struct mfill_state *state,
}
ret = mfill_atomic_install_pte(state->pmd, state->vma, dst_addr,
- &folio->page, flags);
+ folio_page(folio, 0), flags);
if (ret)
goto err_filemap_remove;
@@ -1268,7 +1268,8 @@ static struct folio *check_ptes_for_batched_move(struct vm_area_struct *src_vma,
folio = vm_normal_folio(src_vma, src_addr, orig_src_pte);
if (!folio || !folio_trylock(folio))
return NULL;
- if (!PageAnonExclusive(&folio->page) || folio_test_large(folio)) {
+ if (!PageAnonExclusive(folio_page(folio, 0)) ||
+ folio_test_large(folio)) {
folio_unlock(folio);
return NULL;
}
@@ -1306,7 +1307,7 @@ static long move_present_ptes(struct mm_struct *mm,
}
if (folio_test_large(src_folio) ||
folio_maybe_dma_pinned(src_folio) ||
- !PageAnonExclusive(&src_folio->page)) {
+ !PageAnonExclusive(folio_page(src_folio, 0))) {
err = -EBUSY;
goto out;
}
@@ -1590,7 +1591,8 @@ static long move_pages_ptes(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd
}
folio = vm_normal_folio(src_vma, src_addr, orig_src_pte);
- if (!folio || !PageAnonExclusive(&folio->page)) {
+ if (!folio ||
+ !PageAnonExclusive(folio_page(folio, 0))) {
spin_unlock(src_ptl);
ret = -EBUSY;
goto out;
@@ -2072,7 +2074,7 @@ static ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
struct folio *folio = pmd_folio(*src_pmd);
if (!is_huge_zero_folio(folio) &&
- !PageAnonExclusive(&folio->page)) {
+ !PageAnonExclusive(folio_page(folio, 0))) {
spin_unlock(ptl);
err = -EBUSY;
break;
--
2.56.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-09-29 21:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 21:51 [PATCH 00/15] mm: eliminate &folio->page references in mm/ Nilay Vaish
2026-09-29 21:51 ` [PATCH 01/15] mm/khugepaged: drop redundant page parameter from set_huge_pmd() Nilay Vaish
2026-09-29 21:51 ` [PATCH 02/15] mm/huge_memory: use folio_page() in PMD/PUD rmap, zap, and migration Nilay Vaish
2026-09-29 21:51 ` [PATCH 03/15] mm/huge_memory: use folio_page() in THP split paths Nilay Vaish
2026-09-29 21:51 ` [PATCH 04/15] mm/hugetlb_vmemmap: use folio_page() for vmemmap address arithmetic Nilay Vaish
2026-09-29 21:51 ` [PATCH 05/15] mm/hugetlb_cma: use folio_page() in hugetlb_cma_free_frozen_folio() Nilay Vaish
2026-09-29 21:51 ` [PATCH 06/15] mm/hugetlb: replace &folio->page with folio_page() and VM_BUG_ON_FOLIO() Nilay Vaish
2026-09-29 21:51 ` [PATCH 07/15] mm/page_isolation: use folio_page() in page_is_unmovable() Nilay Vaish
2026-09-29 21:51 ` [PATCH 08/15] mm/compaction: stop casting free pages to struct folio Nilay Vaish
2026-09-29 21:52 ` [PATCH 09/15] mm/migrate, vmscan: use folio_page() for movable_ops helpers Nilay Vaish
2026-09-29 21:52 ` [PATCH 10/15] mm/memory: use folio_page() in fault and CoW paths Nilay Vaish
2026-09-29 21:52 ` [PATCH 11/15] mm/rmap, gup: use folio_page() for PageAnonExclusive and gup_must_unshare Nilay Vaish
2026-09-29 21:52 ` Nilay Vaish [this message]
2026-09-29 21:52 ` [PATCH 13/15] mm/page_alloc, folio: use folio_page() when freeing folios Nilay Vaish
2026-09-29 21:52 ` [PATCH 14/15] mm/page_owner, alloc_tag: use folio_page() for page_ext and codetag Nilay Vaish
2026-09-29 21:52 ` [PATCH 15/15] mm: replace remaining &folio->page uses with folio_page() and helpers Nilay Vaish
2026-09-30 10:17 ` [PATCH 00/15] mm: eliminate &folio->page references in mm/ David Hildenbrand (Arm)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260929215206.516490-13-nilayvaish@google.com \
--to=nilayvaish@google.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=gthelen@google.com \
--cc=kfree@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®