mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 15/15] mm: replace remaining &folio->page uses with folio_page() and helpers
Date: Tue, 29 Sep 2026 14:52:06 -0700	[thread overview]
Message-ID: <20260929215206.516490-16-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.

Convert the remaining &folio->page uses in mm/memory-failure.c,
mm/hwpoison-inject.c, mm/filemap.c, mm/gup_test.c, mm/memory_hotplug.c,
and mm/memremap.c to folio_page(folio, 0) (and folio_set_hwpoison() in
mf_generic_kill_procs()), and use ERR_CAST(folio) when returning an
error pointer as struct page * in do_read_cache_page() and
shmem_read_mapping_page_gfp().

In free_zone_device_folio() (mm/memremap.c), passing folio_page(folio, 0)
to wake_up_var() ensures the wake-up key continues to match the struct
page address that fs/dax.c waits on via ___wait_var_event(page, ...)
once struct folio is separated from struct page.

No functional change intended while struct folio overlays struct page.

Assisted-by: LLM
Signed-off-by: Nilay Vaish <nilayvaish@google.com>
---
 mm/filemap.c         | 6 +++---
 mm/gup_test.c        | 6 ++++--
 mm/hwpoison-inject.c | 2 +-
 mm/memory-failure.c  | 8 ++++----
 mm/memory_hotplug.c  | 2 +-
 mm/memremap.c        | 2 +-
 mm/shmem.c           | 2 +-
 7 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index b74bc1e5015c..02e0c2af594c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -156,7 +156,7 @@ static void filemap_unaccount_folio(struct address_space *mapping,
 	if (!IS_ENABLED(CONFIG_DEBUG_VM) && unlikely(folio_mapped(folio))) {
 		pr_alert("BUG: Bad page cache in process %s  pfn:%05lx\n",
 			 current->comm, folio_pfn(folio));
-		dump_page(&folio->page, "still mapped when deleted");
+		dump_page(folio_page(folio, 0), "still mapped when deleted");
 		dump_stack();
 		add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
 
@@ -3888,7 +3888,7 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf,
 		unsigned long *rss)
 {
 	vm_fault_t ret = 0;
-	struct page *page = &folio->page;
+	struct page *page = folio_page(folio, 0);
 
 	if (PageHWPoison(page))
 		goto out;
@@ -4239,7 +4239,7 @@ static struct page *do_read_cache_page(struct address_space *mapping,
 
 	folio = do_read_cache_folio(mapping, index, filler, file, gfp);
 	if (IS_ERR(folio))
-		return &folio->page;
+		return ERR_CAST(folio);
 	return folio_file_page(folio, index);
 }
 
diff --git a/mm/gup_test.c b/mm/gup_test.c
index ba74bf3f4104..337b58221c79 100644
--- a/mm/gup_test.c
+++ b/mm/gup_test.c
@@ -59,13 +59,15 @@ static void verify_dma_pinned(unsigned int cmd, struct page **pages,
 			if (WARN(!folio_maybe_dma_pinned(folio),
 				 "pages[%lu] is NOT dma-pinned\n", i)) {
 
-				dump_page(&folio->page, "gup_test failure");
+				dump_page(folio_page(folio, 0),
+					  "gup_test failure");
 				break;
 			} else if (cmd == PIN_LONGTERM_BENCHMARK &&
 				WARN(!folio_is_longterm_pinnable(folio),
 				     "pages[%lu] is NOT pinnable but pinned\n",
 				     i)) {
-				dump_page(&folio->page, "gup_test failure");
+				dump_page(folio_page(folio, 0),
+					  "gup_test failure");
 				break;
 			}
 		}
diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c
index a11222572f97..127e5d75aa0d 100644
--- a/mm/hwpoison-inject.c
+++ b/mm/hwpoison-inject.c
@@ -131,7 +131,7 @@ static int hwpoison_inject(void *data, u64 val)
 	 * the targeted owner (or on a free page).
 	 * memory_failure() will redo the check reliably inside page lock.
 	 */
-	err = hwpoison_filter(&folio->page);
+	err = hwpoison_filter(folio_page(folio, 0));
 	if (err)
 		return 0;
 
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 0c96eb511997..771a75eb5505 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1400,7 +1400,7 @@ static int __get_hwpoison_page(struct page *page, unsigned long flags)
 	 * unsupported type of folio in order to reduce the risk of unexpected
 	 * races caused by taking a folio refcount.
 	 */
-	if (!HWPoisonHandlable(&folio->page, flags))
+	if (!HWPoisonHandlable(folio_page(folio, 0), flags))
 		return -EBUSY;
 
 	if (folio_try_get(folio)) {
@@ -1777,7 +1777,7 @@ static int mf_generic_kill_procs(unsigned long long pfn, int flags,
 	if (!cookie)
 		return -EBUSY;
 
-	if (hwpoison_filter(&folio->page)) {
+	if (hwpoison_filter(folio_page(folio, 0))) {
 		rc = -EOPNOTSUPP;
 		goto unlock;
 	}
@@ -1799,7 +1799,7 @@ static int mf_generic_kill_procs(unsigned long long pfn, int flags,
 	 * Use this flag as an indication that the dax page has been
 	 * remapped UC to prevent speculative consumption of poison.
 	 */
-	SetPageHWPoison(&folio->page);
+	folio_set_hwpoison(folio);
 
 	/*
 	 * Unlike System-RAM there is no possibility to swap in a
@@ -1808,7 +1808,7 @@ static int mf_generic_kill_procs(unsigned long long pfn, int flags,
 	 * SIGBUS (i.e. MF_MUST_KILL)
 	 */
 	flags |= MF_ACTION_REQUIRED | MF_MUST_KILL;
-	collect_procs(folio, &folio->page, &to_kill, true);
+	collect_procs(folio, folio_page(folio, 0), &to_kill, true);
 
 	unmap_and_kill(&to_kill, pfn, folio->mapping, folio->index, flags);
 unlock:
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 796af1028ee2..47bf3b5d3ff2 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1952,7 +1952,7 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
 				if (__ratelimit(&migrate_rs)) {
 					pr_warn("migrating pfn %lx failed ret:%d\n",
 						folio_pfn(folio), ret);
-					dump_page(&folio->page,
+					dump_page(folio_page(folio, 0),
 						  "migration failure");
 				}
 			}
diff --git a/mm/memremap.c b/mm/memremap.c
index accba23aef28..70cfd3f05a25 100644
--- a/mm/memremap.c
+++ b/mm/memremap.c
@@ -467,7 +467,7 @@ void free_zone_device_folio(struct folio *folio)
 		break;
 
 	case MEMORY_DEVICE_FS_DAX:
-		wake_up_var(&folio->page);
+		wake_up_var(folio_page(folio, 0));
 		break;
 
 	case MEMORY_DEVICE_PCI_P2PDMA:
diff --git a/mm/shmem.c b/mm/shmem.c
index 07b2855dfb7b..1dca70978ac9 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -6195,7 +6195,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
 	struct page *page;
 
 	if (IS_ERR(folio))
-		return &folio->page;
+		return ERR_CAST(folio);
 
 	page = folio_file_page(folio, index);
 	if (PageHWPoison(page)) {
-- 
2.56.0.rc1.315.gc6ed9934b7-goog


      parent reply	other threads:[~2026-09-29 21:53 UTC|newest]

Thread overview: 16+ 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 ` [PATCH 12/15] mm/ksm, userfaultfd: replace &folio->page with folio_page() Nilay Vaish
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 ` Nilay Vaish [this message]

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-16-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®