From: Yuan Liu <yuan1.liu@intel.com>
To: David Hildenbrand <david@kernel.org>,
Oscar Salvador <osalvador@suse.de>,
Mike Rapoport <rppt@kernel.org>,
Wei Yang <richard.weiyang@gmail.com>
Cc: linux-mm@kvack.org, Yong Hu <yong.hu@intel.com>,
Nanhai Zou <nanhai.zou@intel.com>, Yuan Liu <yuan1.liu@intel.com>,
Tim Chen <tim.c.chen@linux.intel.com>,
Qiuxu Zhuo <qiuxu.zhuo@intel.com>,
Yu C Chen <yu.c.chen@intel.com>, Pan Deng <pan.deng@intel.com>,
Tianyou Li <tianyou.li@intel.com>,
Chen Zhang <zhangchen.kidd@jd.com>,
Jason Zeng <jason.zeng@intel.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v5 3/5] mm: remove the special early-section handling from pfn_valid() and for_each_valid_pfn()
Date: Wed, 20 May 2026 05:34:55 -0400 [thread overview]
Message-ID: <20260520093457.3719960-4-yuan1.liu@intel.com> (raw)
In-Reply-To: <20260520093457.3719960-1-yuan1.liu@intel.com>
Make pfn_valid() return 0 for PFNs that fall into invalid subsections
in early sections. Make for_each_valid_pfn() skip PFNs that fall into
invalid subsections in early sections.
This change is in preparation for optimizing zone contiguity checks
based on pages_with_online_memmap.
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Jason Zeng <jason.zeng@intel.com>
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
---
include/linux/mmzone.h | 13 ++++++-------
mm/sparse-vmemmap.c | 4 ++--
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 9adb2ad21da5..783084f8bbfe 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -2259,6 +2259,10 @@ void sparse_init_early_section(int nid, struct page *map, unsigned long pnum,
* there is actual usable memory at that @pfn. The struct page may
* represent a hole or an unusable page frame.
*
+ * Note that this function returns 0 for PFNs that fall into
+ * invalid subsections as part of early sections, even though there would
+ * currently be a memmap allocated (that should not be touched).
+ *
* Return: 1 for PFNs that have memory map entries and 0 otherwise
*/
static inline int pfn_valid(unsigned long pfn)
@@ -2283,11 +2287,7 @@ static inline int pfn_valid(unsigned long pfn)
rcu_read_unlock_sched();
return 0;
}
- /*
- * Traditionally early sections always returned pfn_valid() for
- * the entire section-sized span.
- */
- ret = early_section(ms) || pfn_section_valid(ms, pfn);
+ ret = pfn_section_valid(ms, pfn);
rcu_read_unlock_sched();
return ret;
@@ -2303,8 +2303,7 @@ static inline unsigned long first_valid_pfn(unsigned long pfn, unsigned long end
while (nr <= __highest_present_section_nr && pfn < end_pfn) {
struct mem_section *ms = __pfn_to_section(pfn);
- if (valid_section(ms) &&
- (early_section(ms) || pfn_section_first_valid(ms, &pfn))) {
+ if (valid_section(ms) && pfn_section_first_valid(ms, &pfn)) {
rcu_read_unlock_sched();
return pfn;
}
diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 6eadb9d116e4..c6eefbb6013f 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -771,8 +771,8 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
}
/*
- * The memmap of early sections is always fully populated. See
- * section_activate() and pfn_valid() .
+ * The memmap of early sections is currently always fully populated. See
+ * section_activate().
*/
if (!section_is_early) {
memmap_pages_add(-1L * (DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)));
--
2.47.3
next prev parent reply other threads:[~2026-05-20 9:35 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 9:34 [PATCH v5 0/5] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Yuan Liu
2026-05-20 9:34 ` [PATCH v5 1/5] mm: move mirrored memory overlap checking to the outer loop Yuan Liu
2026-05-21 3:33 ` Wei Yang
2026-05-22 7:43 ` Liu, Yuan1
2026-05-25 8:35 ` Wei Yang
2026-06-02 7:55 ` Liu, Yuan1
2026-06-12 2:44 ` Wei Yang
2026-06-25 12:04 ` David Hildenbrand (Arm)
2026-06-26 8:26 ` Liu, Yuan1
2026-07-02 13:19 ` David Hildenbrand (Arm)
2026-07-10 3:19 ` Liu, Yuan1
2026-05-20 9:34 ` [PATCH v5 2/5] mm: skip non-mirrored ZONE_NORMAL memory map init when kernelcore=mirror Yuan Liu
2026-05-20 9:34 ` Yuan Liu [this message]
2026-05-20 9:34 ` [PATCH v5 4/5] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Yuan Liu
2026-05-20 9:34 ` [PATCH v5 5/5] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Yuan Liu
2026-05-21 2:59 ` [PATCH v5 0/5] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Wei Yang
2026-05-21 5:16 ` Liu, Yuan1
2026-06-01 7:17 ` Mike Rapoport
2026-06-02 7:37 ` Liu, Yuan1
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=20260520093457.3719960-4-yuan1.liu@intel.com \
--to=yuan1.liu@intel.com \
--cc=david@kernel.org \
--cc=jason.zeng@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nanhai.zou@intel.com \
--cc=osalvador@suse.de \
--cc=pan.deng@intel.com \
--cc=qiuxu.zhuo@intel.com \
--cc=richard.weiyang@gmail.com \
--cc=rppt@kernel.org \
--cc=tianyou.li@intel.com \
--cc=tim.c.chen@linux.intel.com \
--cc=yong.hu@intel.com \
--cc=yu.c.chen@intel.com \
--cc=zhangchen.kidd@jd.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®