mm/sparse: remove SECTION_MARKED_PRESENT and further cleanups
Subsystems (12)
David Hildenbrand (Arm)
maintainerv2 cover mm/sparse: remove SECTION_MARKED_PRESENT and further cleanups
SECTION_MARKED_PRESENT is really only needed during boot, where we can instead just rely on SECTION_IS_EARLY_BIT by setting that flag earlier.
Some preparations for doing that conversion and some cleanups in the same (sparse) area.
Tested on x86 with and without memory hotplug through virtio-mem.
---
Changes in v2:
- Rebased to mm-unstable
- Add "scripts/gdb: mm.py: remove fallbacks for SECTION_HAS_MEM_MAP and SECTION_IS_EARLY"
- Improve comment in mmzone.h for __highest_used_section_nr
- Improve comment in fs/proc/page.c for get_max_dump_pfn()
- Move __highest_used_section_nr handling directly into
__section_mark_present() callers and use max()
- Make pfn const in sparse_metadata_init_nid()
- Take care of .clang_format
- Smaller patch description fixes
- Link to v1: https://patch.msgid.link/[email protected]
To: Andrew Morton <[email protected]>
To: David Hildenbrand <[email protected]>
To: Lorenzo Stoakes <[email protected]>
To: "Liam R. Howlett" <[email protected]>
To: Vlastimil Babka <[email protected]>
To: Mike Rapoport <[email protected]>
To: Suren Baghdasaryan <[email protected]>
To: Michal Hocko <[email protected]>
To: Kairui Song <[email protected]>
To: Qi Zheng <[email protected]>
To: Shakeel Butt <[email protected]>
To: Barry Song <[email protected]>
To: Axel Rasmussen <[email protected]>
To: Yuanchu Xie <[email protected]>
To: Wei Xu <[email protected]>
To: Baoquan He <[email protected]>
To: Baolin Wang <[email protected]>
To: Brendan Jackman <[email protected]>
To: Johannes Weiner <[email protected]>
To: Zi Yan <[email protected]>
To: Jan Kiszka <[email protected]>
To: Kieran Bingham <[email protected]>
To: Oscar Salvador <[email protected]>
To: Greg Kroah-Hartman <[email protected]>
To: "Rafael J. Wysocki" <[email protected]>
To: Danilo Krummrich <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
David Hildenbrand (Arm) (13):
mm/sparse: move mem_section init to sparse_extreme_init()
mm/sparse: refactor sparse_sections_init()
mm/sparse: move initialization of section metadata to sparse_metadata_init() mm/sparse: rename and cleanup sparse_init_nid()
mm/sparse: cleanup sparse_init_one_section()
mm/sparse: rename __highest_present_section_nr to __highest_used_section_nr mm/sparse: remove pfn_in_present_section()
mm/sparse: move __highest_used_section_nr handling
scripts/gdb: mm.py: remove fallbacks for SECTION_HAS_MEM_MAP and SECTION_IS_EARLY mm/sparse: remove SECTION_MARKED_PRESENT
mm/sparse: remove flags parameter from sparse_init_one_section() fs/proc/page: clarify comment in get_max_dump_pfn()
mm/memory_hotplug: drop CONFIG_HAVE_ARCH_PFN_VALID handling from pfn_to_online_page()
.clang-format | 2 +- drivers/base/memory.c | 2 +- fs/proc/page.c | 7 +-- include/linux/cache.h | 1 + include/linux/mmzone.h | 43 ++++--------- mm/compaction.c | 2 +- mm/memory_hotplug.c | 9 +-- mm/sparse-vmemmap.c | 4 +- mm/sparse.c | 160 +++++++++++++++++++++++------------------------- mm/sparse.h | 19 ++---- scripts/gdb/linux/mm.py | 8 +-- 11 files changed, 108 insertions(+), 149 deletions(-)
---
base-commit: 8d61431ed2607386b427752505379536eb634ce8
change-id: 20260814-b4-sparsemem_cleanups-8bc4b47014c3
--
Cheers,
David
David Hildenbrand (Arm)
maintainerPATCH v2 1/13 mm/sparse: move mem_section init to sparse_extreme_init()
Let's just avoid another pair of ifdef inside a function. While at it, switch to INTERNODE_CACHE_BYTES by just defining a fallback in cache.h as well, given that the x86 variant already provides one.
--- include/linux/cache.h | 1 + mm/sparse.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-)
include/linux/cache.h +1 -0
@@ -89,6 +89,7 @@*/ #ifndef INTERNODE_CACHE_SHIFT #define INTERNODE_CACHE_SHIFT L1_CACHE_SHIFT +#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)#endif #if !defined(____cacheline_internodealigned_in_smp)
mm/sparse.c +12 -7
@@ -103,11 +103,22 @@ int __meminit sparse_index_init(unsigned long section_nr, int nid) return 0; } + +static void __init sparse_extreme_init (void ) +{ +const unsigned long size =sizeof (struct mem_section *) *NR_SECTION_ROOTS ; + + mem_section =memblock_alloc_or_panic (size,INTERNODE_CACHE_BYTES ); +}#else /* !SPARSEMEM_EXTREME */ int __meminit sparse_index_init (unsigned long section_nr,int nid) {return 0 ; } + +static void __init sparse_extreme_init (void ) +{ +}#endif /*
@@ -196,13 +207,7 @@ void __init sparse_sections_init(void)unsigned long start, end;int i, nid; -#ifdef CONFIG_SPARSEMEM_EXTREME -unsigned long size, align; - - size =sizeof (struct mem_section *) *NR_SECTION_ROOTS ; - align =1 << (INTERNODE_CACHE_SHIFT ); - mem_section =memblock_alloc_or_panic (size, align); -#endif +sparse_extreme_init ();for_each_mem_pfn_range (i,MAX_NUMNODES , &start, &end, &nid)memory_present (nid, start, end);
Signature · 1 line
2.43.0
Re: [PATCH v2 01/13] mm/sparse: move mem_section init to sparse_extreme_init()
Quoted 4 lines · David Hildenbrand (Arm)
Let's just avoid another pair of ifdef inside a function. While at it, switch to
INTERNODE_CACHE_BYTESby just defining a fallback incache.has well, given that the x86 variant already provides one.
Quoted 9 lines
Acked-by Oscar Salvador <[email protected]>Reviewed-by Lorenzo Stoakes (ARM) <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>--- include/linux/cache.h | 1 + mm/sparse.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-)
LGTM.
Signature · 2 lines
Best Regards, Yan, Zi
David Hildenbrand (Arm)
maintainerPATCH v2 2/13 mm/sparse: refactor sparse_sections_init()
In reply to David Hildenbrand (Arm)memory_present() really identifies+prepares all early sections so the initialization in sparse_init() can properly iterating them to initialize metadata.
Let's just inline memory_present() into sparse_sections_init() and cleaning up the code a bit while at it: make it clear that we are operating on pfns.
Note that we call set_section_nid() now only if the section was not already created earlier. Now, there is no more inconsistency between what we (temporarily) store in ms->section_mem_map and what we store in our section->nid array.
--- mm/sparse.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-)
mm/sparse.c +17 -24
@@ -179,40 +179,33 @@ static inline unsigned long first_present_section_nr(void)return next_present_section_nr (-1 ); } -/* Record a memory area against a node. */ -static void __init memory_present (int nid,unsigned long start,unsigned long end) +void __init sparse_sections_init (void ) { -unsigned long pfn; +unsigned long pfn, start_pfn, end_pfn; +int i, nid; + +sparse_extreme_init (); - start &=PAGE_SECTION_MASK ; -mminit_validate_memmodel_limits (&start, &end); -for (pfn = start; pfn < end; pfn +=PAGES_PER_SECTION ) { -unsigned long section_nr =pfn_to_section_nr (pfn); -struct mem_section *ms; +for_each_mem_pfn_range (i,MAX_NUMNODES , &start_pfn, &end_pfn, &nid) { + start_pfn &=PAGE_SECTION_MASK ; +mminit_validate_memmodel_limits (&start_pfn, &end_pfn); -sparse_index_init (section_nr, nid); -set_section_nid (section_nr, nid); +for (pfn = start_pfn; pfn < end_pfn; pfn +=PAGES_PER_SECTION ) { +unsigned long section_nr =pfn_to_section_nr (pfn); +struct mem_section *ms; - ms =__nr_to_section (section_nr); -if (!ms->section_mem_map) { +sparse_index_init (section_nr, nid); + ms =__nr_to_section (section_nr); +if (ms->section_mem_map) +continue ; + +set_section_nid (section_nr, nid); ms->section_mem_map =sparse_encode_early_nid (nid) |SECTION_IS_ONLINE ;__section_mark_present (ms, section_nr); } } } - -void __init sparse_sections_init (void ) -{ -unsigned long start, end; -int i, nid; - -sparse_extreme_init (); - -for_each_mem_pfn_range (i,MAX_NUMNODES , &start, &end, &nid) -memory_present (nid, start, end); -} -#ifndef CONFIG_SPARSEMEM_VMEMMAP struct page __init *__populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap,
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 3/13 mm/sparse: move initialization of section metadata to sparse_metadata_init()
In reply to David Hildenbrand (Arm)Let's move the code responsible for initializing sparse metadata (usemap, memmap) into a helper. Cleanup the variable while at it (e.g., "map_count").
Drop the rather obvious code comments.
No functional change intended.
--- mm/sparse.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
mm/sparse.c +22 -21
@@ -255,38 +255,39 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin, } } +static void __init sparse_metadata_init (void ) +{ +unsigned long start_section_nr =first_present_section_nr (); +int nid_begin =sparse_early_nid (__nr_to_section (start_section_nr)); +unsigned long section_nr, nr_sections =1 ; + +for_each_present_section_nr (start_section_nr +1 , section_nr) { +const int nid =sparse_early_nid (__nr_to_section (section_nr)); + +if (nid == nid_begin) { + nr_sections++; +continue ; + } +sparse_init_nid (nid_begin, start_section_nr, section_nr, nr_sections); + nid_begin = nid; + start_section_nr = section_nr; + nr_sections =1 ; + } +sparse_init_nid (nid_begin, start_section_nr, section_nr, nr_sections); +} +/* * Allocate the accumulated non-linear sections, allocate a mem_map * for each and record the physical to section mapping. */ void __init sparse_init (void ) { -unsigned long pnum_end, pnum_begin, map_count =1 ; -int nid_begin; -if (compound_info_has_mask ()) {VM_WARN_ON_ONCE (!IS_ALIGNED ((unsigned long )pfn_to_page (0 ),MAX_FOLIO_VMEMMAP_ALIGN )); } - pnum_begin =first_present_section_nr (); - nid_begin =sparse_early_nid (__nr_to_section (pnum_begin)); - -for_each_present_section_nr (pnum_begin +1 , pnum_end) { -int nid =sparse_early_nid (__nr_to_section (pnum_end)); - -if (nid == nid_begin) { - map_count++; -continue ; - } -/* Init node with sections in range [pnum_begin, pnum_end) */ -sparse_init_nid (nid_begin, pnum_begin, pnum_end, map_count); - nid_begin = nid; - pnum_begin = pnum_end; - map_count =1 ; - } -/* cover the last node */ -sparse_init_nid (nid_begin, pnum_begin, pnum_end, map_count); +sparse_metadata_init ();sparse_init_subsection_map ();vmemmap_populate_print_last (); }
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 4/13 mm/sparse: rename and cleanup sparse_init_nid()
In reply to David Hildenbrand (Arm)Let's rename it to "sparse_metadata_init_nid", avoid the "pnum" terminology and drop the function comment. Further, rename the "map" variable to "mem_map" for consistency with other functions.
--- mm/sparse.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-)
mm/sparse.c +20 -21
@@ -221,36 +221,33 @@ void __weak __meminit vmemmap_populate_print_last(void) { } -/* -* Initialize sparse on a specific node. The node spans [pnum_begin, pnum_end) -* And number of present sections in this node is map_count. -*/ -static void __init sparse_init_nid (int nid,unsigned long pnum_begin, -unsigned long pnum_end, -unsigned long map_count) +static void __init sparse_metadata_init_nid (int nid, +unsigned long start_section_nr,unsigned long end_section_nr, +unsigned long nr_sections) { -unsigned long pnum;struct mem_section_usage *usage; +unsigned long section_nr; - usage =memblock_alloc_node (map_count *mem_section_usage_size (), + usage =memblock_alloc_node (nr_sections *mem_section_usage_size (),SMP_CACHE_BYTES , nid);if (!usage)panic ("Failed to allocate usemap for node %d\n" , nid); -for_each_present_section_nr (pnum_begin, pnum) { -unsigned long pfn =section_nr_to_pfn (pnum); -struct page *map; +for_each_present_section_nr (start_section_nr, section_nr) { +const unsigned long pfn =section_nr_to_pfn (section_nr); +struct page *mem_map; -if (pnum >= pnum_end) +if (section_nr >= end_section_nr)break ; - map =__populate_section_memmap (pfn,PAGES_PER_SECTION , - nid,NULL ,NULL ); -if (!map) -panic ("Failed to allocate memmap for section %lu\n" , pnum); + mem_map =__populate_section_memmap (pfn,PAGES_PER_SECTION , nid, +NULL ,NULL ); +if (!mem_map) +panic ("Failed to allocate memmap for section %lu\n" , + section_nr);memmap_boot_pages_add (section_nr_vmemmap_pages (pfn,PAGES_PER_SECTION )); -sparse_init_one_section (__nr_to_section (pnum), pnum, map, usage, -SECTION_IS_EARLY ); +sparse_init_one_section (__nr_to_section (section_nr), section_nr, + mem_map, usage,SECTION_IS_EARLY ); usage = (void *)usage +mem_section_usage_size (); } }
@@ -268,12 +265,14 @@ static void __init sparse_metadata_init(void) nr_sections++;continue ; } -sparse_init_nid (nid_begin, start_section_nr, section_nr, nr_sections); +sparse_metadata_init_nid (nid_begin, start_section_nr, + section_nr, nr_sections); nid_begin = nid; start_section_nr = section_nr; nr_sections =1 ; } -sparse_init_nid (nid_begin, start_section_nr, section_nr, nr_sections); +sparse_metadata_init_nid (nid_begin, start_section_nr, section_nr, + nr_sections); }/*
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 5/13 mm/sparse: cleanup sparse_init_one_section()
In reply to David Hildenbrand (Arm)Let's avoid the "pnum" terminology.
--- mm/sparse.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/sparse.h +2 -2
@@ -20,7 +20,7 @@ void sparse_sections_init(void);int sparse_index_init (unsigned long section_nr,int nid);static inline void sparse_init_one_section (struct mem_section *ms, -unsigned long pnum,struct page *mem_map, +unsigned long section_nr,struct page *mem_map,struct mem_section_usage *usage,unsigned long flags) {unsigned long coded_mem_map;
@@ -32,7 +32,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,* page_to_pfn() on !CONFIG_SPARSEMEM_VMEMMAP can simply subtract it * from the page pointer to obtain the PFN. */ - coded_mem_map = (unsigned long )(mem_map -section_nr_to_pfn (pnum)); + coded_mem_map = (unsigned long )(mem_map -section_nr_to_pfn (section_nr));VM_WARN_ON_ONCE (coded_mem_map & ~SECTION_MAP_MASK ); ms->section_mem_map &= ~SECTION_MAP_MASK ;
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 6/13 mm/sparse: rename __highest_present_section_nr to __highest_used_section_nr
In reply to David Hildenbrand (Arm)In preparation for getting rid of SECTION_MARKED_PRESENT, rename __highest_present_section_nr and clarify the comment.
--- include/linux/mmzone.h | 6 +++--- mm/compaction.c | 2 +- mm/sparse.c | 12 ++++-------- mm/sparse.h | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-)
include/linux/mmzone.h +3 -3
@@ -2181,7 +2181,7 @@ static inline struct mem_section *__pfn_to_section(unsigned long pfn)return __nr_to_section (pfn_to_section_nr (pfn)); } -extern unsigned long __highest_present_section_nr; +extern unsigned long __highest_used_section_nr;static inline int subsection_map_index (unsigned long pfn) {
@@ -2280,7 +2280,7 @@ static inline unsigned long first_valid_pfn(unsigned long pfn, unsigned long endrcu_read_lock_sched (); -while (nr <= __highest_present_section_nr && pfn < end_pfn) { +while (nr <= __highest_used_section_nr && pfn < end_pfn) {struct mem_section *ms =__pfn_to_section (pfn); if (valid_section(ms) &&
@@ -2335,7 +2335,7 @@ static inline int pfn_in_present_section(unsigned long pfn)static inline unsigned long next_present_section_nr (unsigned long section_nr) { -while (++section_nr <= __highest_present_section_nr) { +while (++section_nr <= __highest_used_section_nr) {if (present_section_nr (section_nr))return section_nr; }
mm/compaction.c +1 -1
@@ -216,7 +216,7 @@ static unsigned long skip_offline_sections(unsigned long start_pfn)if (online_section_nr (start_nr))return 0 ; -while (++start_nr <= __highest_present_section_nr) { +while (++start_nr <= __highest_used_section_nr) {if (online_section_nr (start_nr))return section_nr_to_pfn (start_nr); }
mm/sparse.c +4 -8
@@ -164,15 +164,11 @@ static void __init mminit_validate_memmodel_limits(unsigned long *start_pfn, }/* -* There are a number of times that we loop over NR_MEM_SECTIONS, -* looking for section_present() on each. But, when we have very -* large physical address spaces, NR_MEM_SECTIONS can also be -* very large which makes the loops quite long. -* -* Keeping track of this gives us an easy way to break out of -* those loops early. +* Looping over all possible memory sections is expensive, especially if +* NR_MEM_SECTIONS is large but only a fraction is actually used. Keep track of +* the highest section number we ever used. */ -unsigned long __highest_present_section_nr; +unsigned long __highest_used_section_nr;static inline unsigned long first_present_section_nr (void ) {
mm/sparse.h +2 -2
@@ -44,8 +44,8 @@ static inline void sparse_init_one_section(struct mem_section *ms,static inline void __section_mark_present (struct mem_section *ms,unsigned long section_nr) { -if (section_nr > __highest_present_section_nr) - __highest_present_section_nr = section_nr; +if (section_nr > __highest_used_section_nr) + __highest_used_section_nr = section_nr; ms->section_mem_map |=SECTION_MARKED_PRESENT ; }
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 7/13 mm/sparse: remove pfn_in_present_section()
In reply to David Hildenbrand (Arm)Unused, let's remove it.
--- include/linux/mmzone.h | 10 ---------- 1 file changed, 10 deletions(-)
include/linux/mmzone.h +0 -10
@@ -2326,13 +2326,6 @@ static inline unsigned long next_valid_pfn(unsigned long pfn, unsigned long end_#endif -static inline int pfn_in_present_section (unsigned long pfn) -{ -if (pfn_to_section_nr (pfn) >=NR_MEM_SECTIONS ) -return 0 ; -return present_section (__pfn_to_section (pfn)); -} -static inline unsigned long next_present_section_nr (unsigned long section_nr) {while (++section_nr <= __highest_used_section_nr) {
@@ -2362,9 +2355,6 @@ static inline unsigned long next_present_section_nr(unsigned long section_nr)#else #define pfn_to_nid (pfn) (0)#endif - -#else -#define pfn_in_present_section pfn_valid#endif /* CONFIG_SPARSEMEM */ /*
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 8/13 mm/sparse: move __highest_used_section_nr handling
In reply to David Hildenbrand (Arm)In preparation for removing __section_mark_present(), let's move __highest_used_section_nr handling into its callers. Verify in sparse_init_one_section() that it was properly updated.
In sparse_sections_init() we can just set it to the last processed section_nr.
No functional change intended.
--- mm/sparse-vmemmap.c | 1 + mm/sparse.c | 5 +++-- mm/sparse.h | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-)
mm/sparse-vmemmap.c +1 -0
@@ -865,6 +865,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,page_init_poison (memmap,sizeof (struct page ) * nr_pages);__section_mark_present (ms, section_nr); + __highest_used_section_nr =max (section_nr, __highest_used_section_nr);/* Align memmap to section boundary in the subsection case */ if (section_nr_to_pfn (section_nr) != start_pfn)
mm/sparse.c +3 -2
@@ -177,7 +177,7 @@ static inline unsigned long first_present_section_nr(void)void __init sparse_sections_init (void ) { -unsigned long pfn, start_pfn, end_pfn; +unsigned long pfn, start_pfn, end_pfn, section_nr;int i, nid;sparse_extreme_init ();
@@ -187,9 +187,9 @@ void __init sparse_sections_init(void)mminit_validate_memmodel_limits (&start_pfn, &end_pfn);for (pfn = start_pfn; pfn < end_pfn; pfn +=PAGES_PER_SECTION ) { -unsigned long section_nr =pfn_to_section_nr (pfn);struct mem_section *ms; + section_nr =pfn_to_section_nr (pfn);sparse_index_init (section_nr, nid); ms =__nr_to_section (section_nr);if (ms->section_mem_map)
@@ -201,6 +201,7 @@ void __init sparse_sections_init(void)__section_mark_present (ms, section_nr); } } + __highest_used_section_nr = section_nr; }#ifndef CONFIG_SPARSEMEM_VMEMMAP struct page __init *__populate_section_memmap(unsigned long pfn,
mm/sparse.h +1 -3
@@ -26,6 +26,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,unsigned long coded_mem_map;BUILD_BUG_ON (SECTION_MAP_LAST_BIT >PFN_SECTION_SHIFT ); +VM_WARN_ON_ONCE (section_nr > __highest_used_section_nr);/* * We encode the start PFN of the section into the mem_map such that
@@ -44,9 +45,6 @@ static inline void sparse_init_one_section(struct mem_section *ms,static inline void __section_mark_present (struct mem_section *ms,unsigned long section_nr) { -if (section_nr > __highest_used_section_nr) - __highest_used_section_nr = section_nr; - ms->section_mem_map |=SECTION_MARKED_PRESENT ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 08/13] mm/sparse: move __highest_used_section_nr handling
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mm: uninitialized variable section_nr leads to build failure and logic error --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: uninitialized variable section_nr leads to build failure and logic error --
commit c9ec175770a339f5cfe5ee3f81573978aba08b75
Author: David Hildenbrand (Arm) <[email protected]>
mm/sparse: move __highest_used_section_nr handling
This commit prepares for removing __section_mark_present() by moving __highest_used_section_nr handling into its callers. In sparse_sections_init(), it updates the highest used section number to the last processed section_nr.
Quoted 13 lines
mm/sparse.c +1
-1@@ -177,7 +177,7 @@ static inline unsigned long first_present_section_nr(void)void __init sparse_sections_init (void ) { -unsigned long pfn, start_pfn, end_pfn; +unsigned long pfn, start_pfn, end_pfn, section_nr;int i, nid;sparse_extreme_init ();
[ ... ]
Quoted 9 lines
mm/sparse.c +1
-1@@ -187,9 +187,9 @@ void __init sparse_sections_init(void)mminit_validate_memmodel_limits (&start_pfn, &end_pfn);for (pfn = start_pfn; pfn < end_pfn; pfn +=PAGES_PER_SECTION ) { -unsigned long section_nr =pfn_to_section_nr (pfn);struct mem_section *ms; + section_nr =pfn_to_section_nr (pfn);sparse_index_init (section_nr, nid);
[ ... ]
mm/sparse.c void __init sparse_sections_init(void) · line 204
Quoted 5 lines
mm/sparse.c +1
-0@@ -201,6 +201,7 @@ void __init sparse_sections_init(void)__section_mark_present (ms, section_nr); } } + __highest_used_section_nr = section_nr;
[Severity: Medium]
Does this assignment introduce a regression by copying an uninitialized stack value into __highest_used_section_nr?
In sparse_sections_init(), section_nr is declared without initialization. If no memory regions exist, or if mminit_validate_memmodel_limits() clamps start_pfn such that start_pfn >= end_pfn, the inner loop will not execute.
When the outer loops conclude, this unconditionally copies the potentially uninitialized stack value into a global state variable. Because __highest_used_section_nr bounds many loops across the mm subsystem, this regression could cause infinite loops and kernel hangs during boot.
Additionally, without static proof that the loops execute at least once, compilers might issue a -Wmaybe-uninitialized warning that breaks kernel builds enforcing CONFIG_WERROR.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH v2 08/13] mm/sparse: move __highest_used_section_nr handling
In reply to David Hildenbrand (Arm)Quoted 11 lines · David Hildenbrand (Arm)
In preparation for removing
__section_mark_present(), let's move__highest_used_section_nrhandling into its callers. Verify insparse_init_one_section()that it was properly updated.In
sparse_sections_init()we can just set it to the last processedsection_nr.No functional change intended.
Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>
Quoted 1 line
---
...
mm/sparse.h static inline void sparse_init_one_section(struct mem_section *ms, · line 29
Quoted 7 lines
mm/sparse.h +1
-0@@ -26,6 +26,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,unsigned long coded_mem_map;BUILD_BUG_ON (SECTION_MAP_LAST_BIT >PFN_SECTION_SHIFT ); +VM_WARN_ON_ONCE (section_nr > __highest_used_section_nr);
I wonder, have we seen this in the wild?
Signature · 2 lines
Oscar Salvador SUSE Labs
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 08/13] mm/sparse: move __highest_used_section_nr handling
Quoted 22 lines · Oscar Salvador (SUSE)
Quoted 11 lines · David Hildenbrand (Arm)
In preparation for removing
__section_mark_present(), let's move__highest_used_section_nrhandling into its callers. Verify insparse_init_one_section()that it was properly updated.In
sparse_sections_init()we can just set it to the last processedsection_nr.No functional change intended.
Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>Acked-by Oscar Salvador <[email protected]>Quoted 1 line
---
...
Quoted 5 lines
mm/sparse.h +0
-0@@ -26,6 +26,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,unsigned long coded_mem_map;
Quoted 4 lines
mm/sparse.h static inline void sparse_init_one_section(struct mem_section *ms, · line 29
Quoted 2 lines
mm/sparse.h +1
-0BUILD_BUG_ON (SECTION_MAP_LAST_BIT >PFN_SECTION_SHIFT ); +VM_WARN_ON_ONCE (section_nr > __highest_used_section_nr);I wonder, have we seen this in the wild?
No, it would be highly unexpected (thus VM_WARN_ON_ONCE).
Thanks!
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerPATCH v2 9/13 scripts/gdb: mm.py: remove fallbacks for SECTION_HAS_MEM_MAP and SECTION_IS_EARLY
In reply to David Hildenbrand (Arm)There is no reason to handle the absence of the corresponding BIT values. So let's remove the fallbacks.
--- scripts/gdb/linux/mm.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
scripts/gdb/linux/mm.py +2 -6
@@ -71,12 +71,8 @@ class x86_page_ops(): self.NR_SECTION_ROOTS = DIV_ROUND_UP(self.NR_MEM_SECTIONS, self.SECTIONS_PER_ROOT) - try: - self.SECTION_HAS_MEM_MAP = 1 << int(gdb.parse_and_eval('SECTION_HAS_MEM_MAP_BIT')) - self.SECTION_IS_EARLY = 1 << int(gdb.parse_and_eval('SECTION_IS_EARLY_BIT')) - except: - self.SECTION_HAS_MEM_MAP = 1 << 0 - self.SECTION_IS_EARLY = 1 << 3 + self.SECTION_HAS_MEM_MAP = 1 << int(gdb.parse_and_eval('SECTION_HAS_MEM_MAP_BIT')) + self.SECTION_IS_EARLY = 1 << int(gdb.parse_and_eval('SECTION_IS_EARLY_BIT')) self.SUBSECTION_SHIFT = 21 self.PAGES_PER_SUBSECTION = 1 << (self.SUBSECTION_SHIFT - self.PAGE_SHIFT)
Signature · 1 line
2.43.0
Re: [PATCH v2 09/13] scripts/gdb: mm.py: remove fallbacks for SECTION_HAS_MEM_MAP and SECTION_IS_EARLY
Quoted 32 lines · David Hildenbrand (Arm)
There is no reason to handle the absence of the corresponding BIT values. So let's remove the fallbacks.
Link https://lore.kernel.org/r/vpz5zqg5nwbpolxbkip45vxxdt3lni7j2haal7q42skc3b57tu@uh4cec4x32dq open hereCc Seongjun Hong <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>--- scripts/gdb/linux/mm.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)scripts/gdb/linux/mm.py +2
-6@@ -71,12 +71,8 @@ class x86_page_ops(): self.NR_SECTION_ROOTS = DIV_ROUND_UP(self.NR_MEM_SECTIONS, self.SECTIONS_PER_ROOT) - try: - self.SECTION_HAS_MEM_MAP = 1 << int(gdb.parse_and_eval('SECTION_HAS_MEM_MAP_BIT')) - self.SECTION_IS_EARLY = 1 << int(gdb.parse_and_eval('SECTION_IS_EARLY_BIT')) - except: - self.SECTION_HAS_MEM_MAP = 1 << 0 - self.SECTION_IS_EARLY = 1 << 3 + self.SECTION_HAS_MEM_MAP = 1 << int(gdb.parse_and_eval('SECTION_HAS_MEM_MAP_BIT')) + self.SECTION_IS_EARLY = 1 << int(gdb.parse_and_eval('SECTION_IS_EARLY_BIT')) self.SUBSECTION_SHIFT = 21 self.PAGES_PER_SUBSECTION = 1 << (self.SUBSECTION_SHIFT - self.PAGE_SHIFT)Signature · 2 lines
-- 2.43.0
It looks nice.
Thanks! :)
Signature · 2 lines
Best regards, Seongjun Hong
David Hildenbrand (Arm)
maintainerPATCH v2 10/13 mm/sparse: remove SECTION_MARKED_PRESENT
In reply to David Hildenbrand (Arm)All present section iterators run before memory hotplug added any further memory sections, Therefore, we can simply use the SECTION_IS_EARLY flag by setting that flag earlier in sparse_sections_init().
Get rid of SECTION_MARKED_PRESENT entirely and rename for_each_present_section_nr() to for_each_early_section_nr().
Take care of the .clang-format for_each_present_section_nr() handling.
No functional change intended.
--- .clang-format | 2 +- drivers/base/memory.c | 2 +- include/linux/mmzone.h | 27 ++++++++++----------------- mm/sparse-vmemmap.c | 1 - mm/sparse.c | 17 ++++++++--------- mm/sparse.h | 6 ------ 6 files changed, 20 insertions(+), 35 deletions(-)
.clang-format +1 -1
@@ -282,6 +282,7 @@ ForEachMacros: - 'for_each_dpcm_fe' - 'for_each_drhd_unit' - 'for_each_dss_dev' + - 'for_each_early_section_nr' - 'for_each_efi_memory_desc' - 'for_each_efi_memory_desc_in_map' - 'for_each_element'
@@ -403,7 +404,6 @@ ForEachMacros: - 'for_each_possible_cpu_wrap' - 'for_each_present_blessed_reg' - 'for_each_present_cpu' - - 'for_each_present_section_nr' - 'for_each_prime_number' - 'for_each_prime_number_from' - 'for_each_probe_cache_entry'
drivers/base/memory.c +1 -1
@@ -972,7 +972,7 @@ void __init memory_dev_init(void)* block so that it can be covered. */ block_id =ULONG_MAX ; -for_each_present_section_nr (0 , nr) { +for_each_early_section_nr (0 , nr) {if (block_id !=ULONG_MAX &&memory_block_id (nr) == block_id)continue ;
include/linux/mmzone.h +10 -17
@@ -2085,7 +2085,6 @@ static inline struct mem_section *__nr_to_section(unsigned long nr)* accommodate SECTION_MAP_LAST_BIT. We use BUILD_BUG_ON() to ensure this. */ enum { -SECTION_MARKED_PRESENT_BIT ,SECTION_HAS_MEM_MAP_BIT ,SECTION_IS_ONLINE_BIT ,SECTION_IS_EARLY_BIT ,
@@ -2095,7 +2094,6 @@ enum { SECTION_MAP_LAST_BIT, }; -#define SECTION_MARKED_PRESENT BIT(SECTION_MARKED_PRESENT_BIT)#define SECTION_HAS_MEM_MAP BIT(SECTION_HAS_MEM_MAP_BIT)#define SECTION_IS_ONLINE BIT(SECTION_IS_ONLINE_BIT)#define SECTION_IS_EARLY BIT(SECTION_IS_EARLY_BIT)
@@ -2112,16 +2110,6 @@ static inline struct page *__section_mem_map_addr(struct mem_section *section)return (struct page *)map; } -static inline int present_section (const struct mem_section *section) -{ -return (section && (section->section_mem_map &SECTION_MARKED_PRESENT )); -} - -static inline int present_section_nr (unsigned long nr) -{ -return present_section (__nr_to_section (nr)); -} -static inline int valid_section (const struct mem_section *section) {return (section && (section->section_mem_map &SECTION_HAS_MEM_MAP ));
@@ -2137,6 +2125,11 @@ static inline int valid_section_nr(unsigned long nr)return valid_section (__nr_to_section (nr)); } +static inline int early_section_nr (unsigned long nr) +{ +return early_section (__nr_to_section (nr)); +} +static inline int online_section (const struct mem_section *section) {return (section && (section->section_mem_map &SECTION_IS_ONLINE ));
@@ -2326,20 +2319,20 @@ static inline unsigned long next_valid_pfn(unsigned long pfn, unsigned long end_#endif -static inline unsigned long next_present_section_nr (unsigned long section_nr) +static inline unsigned long next_early_section_nr (unsigned long section_nr) {while (++section_nr <= __highest_used_section_nr) { -if (present_section_nr (section_nr)) +if (early_section_nr (section_nr))return section_nr; }return -1 ; } -#define for_each_present_section_nr (start, section_nr) \ - for (section_nr = next_present_section_nr(start - 1); \ +#define for_each_early_section_nr (start, section_nr) \ + for (section_nr = next_early_section_nr(start - 1); \ section_nr != -1; \ - section_nr = next_present_section_nr(section_nr)) + section_nr = next_early_section_nr(section_nr))/* * These are _only_ used during initialisation, therefore they
mm/sparse-vmemmap.c +0 -1
@@ -864,7 +864,6 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,if (!section_vmemmap_optimizable (ms))page_init_poison (memmap,sizeof (struct page ) * nr_pages); -__section_mark_present (ms, section_nr); __highest_used_section_nr =max (section_nr, __highest_used_section_nr);/* Align memmap to section boundary in the subsection case */
mm/sparse.c +8 -9
@@ -170,13 +170,14 @@ static void __init mminit_validate_memmodel_limits(unsigned long *start_pfn,*/ unsigned long __highest_used_section_nr; -static inline unsigned long first_present_section_nr (void ) +static inline unsigned long first_early_section_nr (void ) { -return next_present_section_nr (-1 ); +return next_early_section_nr (-1 ); }void __init sparse_sections_init (void ) { +const unsigned long flags =SECTION_IS_EARLY |SECTION_IS_ONLINE ;unsigned long pfn, start_pfn, end_pfn, section_nr;int i, nid;
@@ -196,9 +197,7 @@ void __init sparse_sections_init(void)continue ;set_section_nid (section_nr, nid); - ms->section_mem_map =sparse_encode_early_nid (nid) | -SECTION_IS_ONLINE ; -__section_mark_present (ms, section_nr); + ms->section_mem_map =sparse_encode_early_nid (nid) | flags; } } __highest_used_section_nr = section_nr;
@@ -230,7 +229,7 @@ static void __init sparse_metadata_init_nid(int nid,if (!usage)panic ("Failed to allocate usemap for node %d\n" , nid); -for_each_present_section_nr (start_section_nr, section_nr) { +for_each_early_section_nr (start_section_nr, section_nr) {const unsigned long pfn =section_nr_to_pfn (section_nr);struct page *mem_map;
@@ -244,18 +243,18 @@ static void __init sparse_metadata_init_nid(int nid, section_nr);memmap_boot_pages_add (section_nr_vmemmap_pages (pfn,PAGES_PER_SECTION ));sparse_init_one_section (__nr_to_section (section_nr), section_nr, - mem_map, usage,SECTION_IS_EARLY ); + mem_map, usage,0 ); usage = (void *)usage +mem_section_usage_size (); } }static void __init sparse_metadata_init (void ) { -unsigned long start_section_nr =first_present_section_nr (); +unsigned long start_section_nr =first_early_section_nr ();int nid_begin =sparse_early_nid (__nr_to_section (start_section_nr));unsigned long section_nr, nr_sections =1 ; -for_each_present_section_nr (start_section_nr +1 , section_nr) { +for_each_early_section_nr (start_section_nr +1 , section_nr) {const int nid =sparse_early_nid (__nr_to_section (section_nr));if (nid == nid_begin) {
mm/sparse.h +0 -6
@@ -42,12 +42,6 @@ static inline void sparse_init_one_section(struct mem_section *ms, ms->usage = usage; } -static inline void __section_mark_present (struct mem_section *ms, -unsigned long section_nr) -{ - ms->section_mem_map |=SECTION_MARKED_PRESENT ; -} -static inline size_t mem_section_usage_size (void ) { return struct_size_t(struct mem_section_usage, pageblock_flags,
Signature · 1 line
2.43.0
Re: [PATCH v2 10/13] mm/sparse: remove SECTION_MARKED_PRESENT
include/linux/mmzone.h static inline struct mem_section *__nr_to_section(unsigned long nr) · line 2090
Quoted 5 lines · David Hildenbrand (Arm)
enum {
include/linux/mmzone.h +0
-1-SECTION_MARKED_PRESENT_BIT ,SECTION_HAS_MEM_MAP_BIT ,SECTION_IS_ONLINE_BIT , SECTION_IS_EARLY_BIT,
Hi David,
It seems dropping SECTION_MARKED_PRESENT_BIT shifts the other section flags down one bit. crash hardcodes SECTION_HAS_MEM_MAP as (1UL << 1) in pfn_to_map(), so it now tests SECTION_IS_ONLINE: offline and ZONE_DEVICE sections no longer resolve to a struct page. makedumpfile only checks bit 0 and is fine.
Keep bit 0 reserved, or export the bits via vmcoreinfo?
Cheers.
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 10/13] mm/sparse: remove SECTION_MARKED_PRESENT
Quoted 8 lines · David Carlier
include/linux/mmzone.h static inline struct mem_section *__nr_to_section(unsigned long nr) · line 2090
Quoted 5 lines · David Hildenbrand (Arm)
enum {
include/linux/mmzone.h +0
-1-SECTION_MARKED_PRESENT_BIT ,SECTION_HAS_MEM_MAP_BIT ,SECTION_IS_ONLINE_BIT , SECTION_IS_EARLY_BIT,Hi David,
Hi!
Quoted 6 lines
It seems dropping
SECTION_MARKED_PRESENT_BITshifts the other section flags down one bit. crash hardcodesSECTION_HAS_MEM_MAPas (1UL << 1) inpfn_to_map(), so it now testsSECTION_IS_ONLINE: offline andZONE_DEVICEsections no longer resolve to a struct page. makedumpfile only checks bit 0 and is fine.
Thanks. To be expected when relying on kernel internals.
Which makes me wonder why makedumpfile
(https://github.com/makedumpfile/makedumpfile) not require any such information.
Quoted 2 lines
Keep bit 0 reserved, or export the bits via vmcoreinfo?
We could export it, or crash can simply detect the change based on the kernel version. I remember the latter was done in makedumpfile in the past (although we export it).
I can send a separate patch to export it.
Signature · 3 lines
Cheers, David
Re: [PATCH v2 10/13] mm/sparse: remove SECTION_MARKED_PRESENT
Cced kexec list.
Quoted 25 lines · David Hildenbrand (Arm)
Quoted 8 lines · David Carlier
include/linux/mmzone.h static inline struct mem_section *__nr_to_section(unsigned long nr) · line 2090
Quoted 5 lines · David Hildenbrand (Arm)
enum {
include/linux/mmzone.h +0
-1-SECTION_MARKED_PRESENT_BIT ,SECTION_HAS_MEM_MAP_BIT ,SECTION_IS_ONLINE_BIT , SECTION_IS_EARLY_BIT,Hi David,
Hi!
Quoted 6 lines
It seems dropping
SECTION_MARKED_PRESENT_BITshifts the other section flags down one bit. crash hardcodesSECTION_HAS_MEM_MAPas (1UL << 1) inpfn_to_map(), so it now testsSECTION_IS_ONLINE: offline andZONE_DEVICEsections no longer resolve to a struct page. makedumpfile only checks bit 0 and is fine.Thanks. To be expected when relying on kernel internals.
Which makes me wonder why makedumpfile
(https://github.com/makedumpfile/makedumpfile) not require any such information.Quoted 1 line
Quoted 6 lines
Quoted 1 line
Keep bit 0 reserved, or export the bits via vmcoreinfo?
We could export it, or crash can simply detect the change based on the kernel version. I remember the latter was done in makedumpfile in the past (although we export it).
I can send a separate patch to export it.
Thanks David. Checking kernel internals via kernel version is not a good idea
due to the downstream kernels.
Quoted 5 lines
Signature · 4 lines
-- Cheers, David
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 10/13] mm/sparse: remove SECTION_MARKED_PRESENT
Quoted 23 lines · Dave Young
Cced kexec list.
Quoted 20 lines · David Hildenbrand (Arm)
Quoted 2 lines · David Carlier
Hi David,
Hi!
Quoted 6 lines
It seems dropping
SECTION_MARKED_PRESENT_BITshifts the other section flags down one bit. crash hardcodesSECTION_HAS_MEM_MAPas (1UL << 1) inpfn_to_map(), so it now testsSECTION_IS_ONLINE: offline andZONE_DEVICEsections no longer resolve to a struct page. makedumpfile only checks bit 0 and is fine.Thanks. To be expected when relying on kernel internals.
Which makes me wonder why makedumpfile
(https://github.com/makedumpfile/makedumpfile) not require any such information.Quoted 2 lines
Keep bit 0 reserved, or export the bits via vmcoreinfo?
Quoted 8 lines
Quoted 5 lines
We could export it, or crash can simply detect the change based on the kernel version. I remember the latter was done in makedumpfile in the past (although we export it).
I can send a separate patch to export it.
Thanks David. Checking kernel internals via kernel version is not a good idea
due to the downstream kernels.
Patch at:
https://lore.kernel.org/r/[email protected]
Signature · 3 lines
Cheers, David
Baoquan He
reviewerRe: [PATCH v2 10/13] mm/sparse: remove SECTION_MARKED_PRESENT
In reply to David Hildenbrand (Arm)Quoted 19 lines · David Hildenbrand (Arm)
Quoted 8 lines · David Carlier
include/linux/mmzone.h static inline struct mem_section *__nr_to_section(unsigned long nr) · line 2090
Quoted 5 lines · David Hildenbrand (Arm)
enum {
include/linux/mmzone.h +0
-1-SECTION_MARKED_PRESENT_BIT ,SECTION_HAS_MEM_MAP_BIT ,SECTION_IS_ONLINE_BIT , SECTION_IS_EARLY_BIT,Hi David,
Hi!
Quoted 6 lines
It seems dropping
SECTION_MARKED_PRESENT_BITshifts the other section flags down one bit. crash hardcodesSECTION_HAS_MEM_MAPas (1UL << 1) inpfn_to_map(), so it now testsSECTION_IS_ONLINE: offline andZONE_DEVICEsections no longer resolve to a struct page. makedumpfile only checks bit 0 and is fine.
Quoted 4 lines
Thanks. To be expected when relying on kernel internals.
Which makes me wonder why makedumpfile
(https://github.com/makedumpfile/makedumpfile) not require any such information.
Makedumpfile requires it too, while it doesn't ask for HAS_MEM_MAP. So checking MARKED_PRESENT becomes checking HAS_MEM_MAP's value, it luckily works.
# git grep MARKED_PRESENT
makedumpfile.c: if (!(map_mask & SECTION_MARKED_PRESENT)) {
makedumpfile.h:#define SECTION_MARKED_PRESENT (1UL<<0)Add makedumpfile maintainer Kazu here.
And add Dave Young here since I heard he is taking over Crash maintenance as a volunteer.
Quoted 13 lines
Quoted 3 lines
Keep bit 0 reserved, or export the bits via vmcoreinfo?
We could export it, or crash can simply detect the change based on the kernel version. I remember the latter was done in makedumpfile in the past (although we export it).
I can send a separate patch to export it.
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerPATCH v2 11/13 mm/sparse: remove flags parameter from sparse_init_one_section()
In reply to David Hildenbrand (Arm)The last user of the flags parameter that used to pass SECTION_IS_EARLY was removed, so let's remove the parameter.
--- mm/sparse-vmemmap.c | 2 +- mm/sparse.c | 2 +- mm/sparse.h | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-)
mm/sparse-vmemmap.c +1 -1
@@ -869,7 +869,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,/* Align memmap to section boundary in the subsection case */ if (section_nr_to_pfn (section_nr) != start_pfn) memmap =pfn_to_page (section_nr_to_pfn (section_nr)); -sparse_init_one_section (ms, section_nr, memmap, ms->usage,0 ); +sparse_init_one_section (ms, section_nr, memmap, ms->usage);return 0 ; }
mm/sparse.c +1 -1
@@ -243,7 +243,7 @@ static void __init sparse_metadata_init_nid(int nid, section_nr);memmap_boot_pages_add (section_nr_vmemmap_pages (pfn,PAGES_PER_SECTION ));sparse_init_one_section (__nr_to_section (section_nr), section_nr, - mem_map, usage,0 ); + mem_map, usage); usage = (void *)usage +mem_section_usage_size (); } }
mm/sparse.h +2 -3
@@ -21,7 +21,7 @@ int sparse_index_init(unsigned long section_nr, int nid);static inline void sparse_init_one_section (struct mem_section *ms,unsigned long section_nr,struct page *mem_map, -struct mem_section_usage *usage,unsigned long flags) +struct mem_section_usage *usage) {unsigned long coded_mem_map;
@@ -37,8 +37,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,VM_WARN_ON_ONCE (coded_mem_map & ~SECTION_MAP_MASK ); ms->section_mem_map &= ~SECTION_MAP_MASK ; - ms->section_mem_map |= coded_mem_map; - ms->section_mem_map |= flags |SECTION_HAS_MEM_MAP ; + ms->section_mem_map |= coded_mem_map |SECTION_HAS_MEM_MAP ; ms->usage = usage; }
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 12/13 fs/proc/page: clarify comment in get_max_dump_pfn()
In reply to David Hildenbrand (Arm)pfn_to_online_page() will only succeed on some PFNs within the same section, not necessarily all. Let's make that clearer.
While at it, rephrase it to "Allow inspection of".
--- fs/proc/page.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/proc/page.c +3 -4
@@ -31,10 +31,9 @@ static inline unsigned long get_max_dump_pfn(void) {#ifdef CONFIG_SPARSEMEM /* -* The memmap of early sections is completely populated and marked -* online even if max_pfn does not fall on a section boundary - -* pfn_to_online_page() will succeed on all pages. Allow inspecting -* these memmaps. +* If max_pfn does not fall on a section boundary, pfn_to_online_page() +* can succeed on PFNs beyond max_pfn within the same section. Allow +* inspection of these memmaps. */ return round_up (max_pfn,PAGES_PER_SECTION );#else
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerPATCH v2 13/13 mm/memory_hotplug: drop CONFIG_HAVE_ARCH_PFN_VALID handling from pfn_to_online_page()
In reply to David Hildenbrand (Arm)Drop CONFIG_HAVE_ARCH_PFN_VALID handling, as CONFIG_HAVE_ARCH_PFN_VALID is never used with CONFIG_MEMORY_HOTPLUG, as the latter depends on CONFIG_SPARSEMEM_VMEMMAP. Make sure it stays that way.
--- mm/memory_hotplug.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/memory_hotplug.c +2 -7
@@ -345,6 +345,8 @@ struct page *pfn_to_online_page(unsigned long pfn)struct dev_pagemap *pgmap;struct mem_section *ms; +BUILD_BUG_ON (IS_ENABLED (CONFIG_HAVE_ARCH_PFN_VALID )); +if (nr >=NR_MEM_SECTIONS )return NULL ;
@@ -352,13 +354,6 @@ struct page *pfn_to_online_page(unsigned long pfn)if (!online_section (ms))return NULL ; -/* -* Save some code text when online_section() + -* pfn_section_valid() are sufficient. -*/ -if (IS_ENABLED (CONFIG_HAVE_ARCH_PFN_VALID ) && !pfn_valid (pfn)) -return NULL ; -if (!pfn_section_valid (ms, pfn))return NULL ;
Signature · 1 line
2.43.0
Re: [PATCH v2 13/13] mm/memory_hotplug: drop CONFIG_HAVE_ARCH_PFN_VALID handling from pfn_to_online_page()
Quoted 7 lines · David Hildenbrand (Arm)
Drop
CONFIG_HAVE_ARCH_PFN_VALIDhandling, asCONFIG_HAVE_ARCH_PFN_VALIDis never used withCONFIG_MEMORY_HOTPLUG, as the latter depends onCONFIG_SPARSEMEM_VMEMMAP. Make sure it stays that way.Reviewed-by Lorenzo Stoakes (ARM) <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by David Hildenbrand (Arm) <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
Andrew Morton
maintainerQuoted 6 lines · On Mon, 21 Sep 2026 21:58:52 +0200 "David Hildenbrand (Arm)"…
SECTION_MARKED_PRESENTis really only needed during boot, where we can instead just rely onSECTION_IS_EARLY_BITby setting that flag earlier.Some preparations for doing that conversion and some cleanups in the same (sparse) area.
Added to mm-new, thanks.