From: Muchun Song <songmuchun@bytedance.com>
To: Alexander Potapenko <glider@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Marco Elver <elver@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Chris Down <chris@chrisdown.name>,
David Hildenbrand <david@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Brendan Jackman <brendan.jackman@linux.dev>,
Zi Yan <ziy@nvidia.com>, Muchun Song <muchun.song@linux.dev>,
Joerg Roedel <joerg.roedel@amd.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Pranjal Shrivastava <praan@google.com>,
Ketan <ketan.kishore@oss.qualcomm.com>,
Mostafa Saleh <smostafa@google.com>,
Sang-Heon Jeon <ekffu200098@gmail.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Sashiko <sashiko-bot@kernel.org>,
kasan-dev@googlegroups.com, workflows@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Muchun Song <songmuchun@bytedance.com>
Subject: [PATCH v3 4/7] mm/page_ext: use common allocation and initialization entry points
Date: Thu, 19 Nov 2026 14:58:09 +0800 [thread overview]
Message-ID: <20261119065812.89959-5-songmuchun@bytedance.com> (raw)
In-Reply-To: <20261119065812.89959-1-songmuchun@bytedance.com>
FLATMEM uses separate page_ext_init_flatmem() and
page_ext_init_flatmem_late() entry points, while SPARSEMEM performs its
work through page_ext_init(). This exposes the memory model in the
generic boot sequence and obscures the allocation and client
initialization phases.
Rename the early entry point to page_ext_alloc() and use
page_ext_init() for client callbacks in both memory models. SPARSEMEM
keeps its existing late allocation behavior for now; its
page_ext_alloc() remains an empty configuration stub.
This also moves FLATMEM client callbacks from immediately after
kmem_cache_init() to after vmalloc_init(). The callbacks still run
after the buddy and slab allocators are available, as required by
page_owner.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Chris Down <chris@chrisdown.name>
Tested-by: Chris Down <chris@chrisdown.name>
---
v3:
- Collect Reviewed-by from Mike Rapoport and Chris Down
- Collect Tested-by from Chris Down
v2:
- Split the common allocation and initialization entry points into a
preparatory patch
- Document the later FLATMEM client callback timing (noted by Chris
Down)
---
include/linux/page_ext.h | 20 +++++---------------
mm/mm_init.c | 7 +------
mm/page_ext.c | 5 ++---
3 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
index 79c53ec45dfa..911a84bbb3db 100644
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -62,13 +62,10 @@ static inline bool early_page_ext_enabled(void)
}
#ifdef CONFIG_SPARSEMEM
-static inline void page_ext_init_flatmem(void)
-{
-}
-extern void page_ext_init(void);
-static inline void page_ext_init_flatmem_late(void)
+static inline void page_ext_alloc(void)
{
}
+void page_ext_init(void);
static inline bool page_ext_iter_next_fast_possible(unsigned long next_pfn)
{
@@ -79,11 +76,8 @@ static inline bool page_ext_iter_next_fast_possible(unsigned long next_pfn)
return next_pfn % PAGES_PER_SECTION;
}
#else
-extern void page_ext_init_flatmem(void);
-extern void page_ext_init_flatmem_late(void);
-static inline void page_ext_init(void)
-{
-}
+void page_ext_alloc(void);
+void page_ext_init(void);
static inline bool page_ext_iter_next_fast_possible(unsigned long next_pfn)
{
@@ -205,11 +199,7 @@ static inline void page_ext_init(void)
{
}
-static inline void page_ext_init_flatmem_late(void)
-{
-}
-
-static inline void page_ext_init_flatmem(void)
+static inline void page_ext_alloc(void)
{
}
diff --git a/mm/mm_init.c b/mm/mm_init.c
index a9d848c92678..bcc4e7e8cd1f 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -2709,7 +2709,7 @@ void __init mm_core_init(void)
* page_ext requires contiguous pages,
* bigger than MAX_PAGE_ORDER unless SPARSEMEM.
*/
- page_ext_init_flatmem();
+ page_ext_alloc();
mem_debugging_and_hardening_init();
kfence_alloc_pool_and_metadata();
report_meminit();
@@ -2725,11 +2725,6 @@ void __init mm_core_init(void)
memblock_free_all();
mem_init();
kmem_cache_init();
- /*
- * page_owner must be initialized after buddy is ready, and also after
- * slab is ready so that stack_depot_init() works properly
- */
- page_ext_init_flatmem_late();
kmemleak_init();
ptlock_cache_init();
pgtable_cache_init();
diff --git a/mm/page_ext.c b/mm/page_ext.c
index 6196bab6868c..aff00f4e1bdd 100644
--- a/mm/page_ext.c
+++ b/mm/page_ext.c
@@ -185,7 +185,7 @@ static inline struct page_ext *get_entry(void *base, unsigned long index)
}
#ifndef CONFIG_SPARSEMEM
-void __init page_ext_init_flatmem_late(void)
+void __init page_ext_init(void)
{
invoke_init_callbacks();
}
@@ -243,9 +243,8 @@ static int __init alloc_node_page_ext(int nid)
return 0;
}
-void __init page_ext_init_flatmem(void)
+void __init page_ext_alloc(void)
{
-
int nid, fail;
if (!invoke_need_callbacks())
--
2.54.0
next prev parent reply other threads:[~2026-11-19 7:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 6:58 [PATCH v3 0/7] KMSAN: Move per-page metadata out of struct page Muchun Song
2026-11-19 6:58 ` [PATCH v3 1/7] kmsan: encapsulate per-page metadata access Muchun Song
2026-11-19 6:58 ` [PATCH v3 2/7] mm/page_ext: fix client data alignment Muchun Song
2026-11-19 8:00 ` Mike Rapoport
2026-11-19 6:58 ` [PATCH v3 3/7] mm/page_ext: always use vmalloc for section page extensions Muchun Song
2026-11-19 6:58 ` Muchun Song [this message]
2026-11-19 6:58 ` [PATCH v3 5/7] mm/page_ext: allocate page extensions early for SPARSEMEM Muchun Song
2026-11-19 6:58 ` [PATCH v3 6/7] mm/page_ext: inline unchecked page extension lookup Muchun Song
2026-11-19 7:56 ` Mike Rapoport
2026-11-19 6:58 ` [PATCH v3 7/7] kmsan: fix metadata loss during HugeTLB struct page reinitialization Muchun Song
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=20261119065812.89959-5-songmuchun@bytedance.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=baolu.lu@linux.intel.com \
--cc=brendan.jackman@linux.dev \
--cc=chris@chrisdown.name \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=dvyukov@google.com \
--cc=ekffu200098@gmail.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=hannes@cmpxchg.org \
--cc=joerg.roedel@amd.com \
--cc=kasan-dev@googlegroups.com \
--cc=ketan.kishore@oss.qualcomm.com \
--cc=liam@infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=praan@google.com \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=smostafa@google.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=workflows@vger.kernel.org \
--cc=ziy@nvidia.com \
/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®