Re: [PATCH v3 02/11] mm/mm_init: factor out common struct page initialization

From: Muchun Song

Date: Mon Nov 23 2026 - 03:25:21 EST




On 2026/11/23 15:00, Qi Zheng wrote:


On 11/20/26 6:08 PM, Muchun Song wrote:
Several struct page fields have the same initial values for every page in
a zone. __init_single_page() initializes this state as part of its
per-page setup, while the shared vmemmap tail path open-codes only a
subset.

Factor the PFN-independent state into memmap_init_page() and use it for
both regular and shared tail struct pages. Keep section-, PFN- and
instance-specific initialization in __init_single_page().

This also initializes the last cpupid and KASAN tag for shared tail
struct pages consistently with regular struct pages. Since
memmap_init_page() marks ZONE_DEVICE pages reserved, remove the redundant
update from the memory hotplug path.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
v3:
- Rename memmap_init_page_common() to memmap_init_page() (suggested by
   Mike Rapoport)
- Remove redundant ZONE_DEVICE reserved-page initialization (suggested by
   Mike Rapoport)

v2:
- Remove __meminit from memmap_init_page_common() so HVO shared tail
   pages can call it after init text is freed (reported by Sashiko).
---
  include/linux/mm.h  |  8 --------
  mm/mm_init.c        | 37 +++++++++++++++++++++----------------
  mm/mm_init.h        |  1 +
  mm/sparse-vmemmap.c |  7 +------
  4 files changed, 23 insertions(+), 30 deletions(-)

Reviewed-by: Qi Zheng <qi.zheng@xxxxxxxxx>

Thanks.


One nit below.


diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8883b780b76d..d8bafcd92791 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3096,14 +3096,6 @@ static inline void set_page_node(struct page *page, unsigned long node)
      page->flags.f |= (node & NODES_MASK) << NODES_PGSHIFT;
  }
  -static inline void set_page_links(struct page *page, enum zone_type zone,
-    unsigned long node, unsigned long pfn)
-{
-    set_page_zone(page, zone);
-    set_page_node(page, node);
-    set_page_section_from_pfn(page, pfn);
-}
-
  /**
   * folio_nr_pages - The number of pages in the folio.
   * @folio: The folio.
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 0129152b74d8..08d6e47bde22 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -602,15 +602,27 @@ static inline void vmemmap_optimization_verify_zone(struct page *page)
              page_zone_id(page));
  }
  -void __meminit __init_single_page(struct page *page, unsigned long pfn,
-                unsigned long zone, int nid)
+/* Initialize PFN-independent fields common to pages in the same zone. */
+void memmap_init_page(struct page *page, enum zone_type zone, int nid)
  {
      mm_zero_struct_page(page);
-    set_page_links(page, zone, nid, pfn);
-    init_page_count(page);
-    atomic_set(&page->_mapcount, -1);
+    set_page_zone(page, zone);
+    set_page_node(page, nid);
      page_cpupid_reset_last(page);
      page_kasan_tag_reset(page);
+    atomic_set(&page->_mapcount, -1);
+#ifdef CONFIG_ZONE_DEVICE
+    if (zone == ZONE_DEVICE)
+        __SetPageReserved(page);
+#endif
+}
+
+void __meminit __init_single_page(struct page *page, unsigned long pfn,
+        unsigned long zone, int nid)

                ^ enum zone_type zone?

You are right. But actually, I didn't modify this line, this should be a Git
display issue. Otherwise, this patch will end up mixing in the declaration
changes for this function. I think the right approach is to submit a
separate patch later to handle this cleanup.

Thanks,
Muchun



Thanks,
Qi