Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/sparse: move sparse_init_one_section() to internal.h

While at it, convert the BUG_ON to a VM_WARN_ON_ONCE, avoid long lines,
and merge sparse_encode_mem_map() into its only caller
sparse_init_one_section().

Clarify the comment a bit, pointing at page_to_pfn().

[david@kernel.org: s/VM_WARN_ON/VM_WARN_ON_ONCE/]
Link: https://lkml.kernel.org/r/6b04c1a1-74e7-42e8-8523-a40802e5dacc@kernel.org
Link: https://lkml.kernel.org/r/20260320-sparsemem_cleanups-v2-13-096addc8800d@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand (Arm) and committed by
Andrew Morton
f62a3bf2 b551ed94

+23 -25
+1 -1
include/linux/mmzone.h
··· 1988 1988 /* 1989 1989 * This is, logically, a pointer to an array of struct 1990 1990 * pages. However, it is stored with some other magic. 1991 - * (see sparse.c::sparse_init_one_section()) 1991 + * (see sparse_init_one_section()) 1992 1992 * 1993 1993 * Additionally during early boot we encode node id of 1994 1994 * the location of the section here to guide allocation.
+22
mm/internal.h
··· 964 964 */ 965 965 #ifdef CONFIG_SPARSEMEM 966 966 void sparse_init(void); 967 + 968 + static inline void sparse_init_one_section(struct mem_section *ms, 969 + unsigned long pnum, struct page *mem_map, 970 + struct mem_section_usage *usage, unsigned long flags) 971 + { 972 + unsigned long coded_mem_map; 973 + 974 + BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT); 975 + 976 + /* 977 + * We encode the start PFN of the section into the mem_map such that 978 + * page_to_pfn() on !CONFIG_SPARSEMEM_VMEMMAP can simply subtract it 979 + * from the page pointer to obtain the PFN. 980 + */ 981 + coded_mem_map = (unsigned long)(mem_map - section_nr_to_pfn(pnum)); 982 + VM_WARN_ON_ONCE(coded_mem_map & ~SECTION_MAP_MASK); 983 + 984 + ms->section_mem_map &= ~SECTION_MAP_MASK; 985 + ms->section_mem_map |= coded_mem_map; 986 + ms->section_mem_map |= flags | SECTION_HAS_MEM_MAP; 987 + ms->usage = usage; 988 + } 967 989 #else 968 990 static inline void sparse_init(void) {} 969 991 #endif /* CONFIG_SPARSEMEM */
-24
mm/sparse.c
··· 256 256 memory_present(nid, start, end); 257 257 } 258 258 259 - /* 260 - * Subtle, we encode the real pfn into the mem_map such that 261 - * the identity pfn - section_mem_map will return the actual 262 - * physical page frame number. 263 - */ 264 - static unsigned long sparse_encode_mem_map(struct page *mem_map, unsigned long pnum) 265 - { 266 - unsigned long coded_mem_map = 267 - (unsigned long)(mem_map - (section_nr_to_pfn(pnum))); 268 - BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT); 269 - BUG_ON(coded_mem_map & ~SECTION_MAP_MASK); 270 - return coded_mem_map; 271 - } 272 - 273 - static void __meminit sparse_init_one_section(struct mem_section *ms, 274 - unsigned long pnum, struct page *mem_map, 275 - struct mem_section_usage *usage, unsigned long flags) 276 - { 277 - ms->section_mem_map &= ~SECTION_MAP_MASK; 278 - ms->section_mem_map |= sparse_encode_mem_map(mem_map, pnum) 279 - | SECTION_HAS_MEM_MAP | flags; 280 - ms->usage = usage; 281 - } 282 - 283 259 static unsigned long usemap_size(void) 284 260 { 285 261 return BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS) * sizeof(unsigned long);