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: remove CONFIG_MEMORY_HOTPLUG-specific usemap allocation handling

In 2008, we added through commit 48c906823f39 ("memory hotplug: allocate
usemap on the section with pgdat") quite some complexity to try allocating
memory for the "usemap" (storing pageblock information per memory section)
for a memory section close to the memory of the "pgdat" of the node.

The goal was to make memory hotunplug of boot memory more likely to
succeed. That commit also added some checks for circular dependencies
between two memory sections, whereby two memory sections would contain
each others usemap, turning both boot memory sections un-removable.

However, in 2010, commit a4322e1bad91 ("sparsemem: Put usemap for one node
together") started allocating the usemap for multiple memory sections on
the same node in one chunk, effectively grouping all usemap allocations of
the same node in a single memblock allocation.

We don't really give guarantees about memory hotunplug of boot memory, and
with the change in 2010, it is impossible in practice to get any circular
dependencies.

So let's simply remove this complexity.

Link: https://lkml.kernel.org/r/20260320-sparsemem_cleanups-v2-10-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
dac89b15 22688ade

+1 -99
+1 -99
mm/sparse.c
··· 294 294 return sizeof(struct mem_section_usage) + usemap_size(); 295 295 } 296 296 297 - #ifdef CONFIG_MEMORY_HOTREMOVE 298 - static inline phys_addr_t pgdat_to_phys(struct pglist_data *pgdat) 299 - { 300 - #ifndef CONFIG_NUMA 301 - VM_BUG_ON(pgdat != &contig_page_data); 302 - return __pa_symbol(&contig_page_data); 303 - #else 304 - return __pa(pgdat); 305 - #endif 306 - } 307 - 308 - static struct mem_section_usage * __init 309 - sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, 310 - unsigned long size) 311 - { 312 - struct mem_section_usage *usage; 313 - unsigned long goal, limit; 314 - int nid; 315 - /* 316 - * A page may contain usemaps for other sections preventing the 317 - * page being freed and making a section unremovable while 318 - * other sections referencing the usemap remain active. Similarly, 319 - * a pgdat can prevent a section being removed. If section A 320 - * contains a pgdat and section B contains the usemap, both 321 - * sections become inter-dependent. This allocates usemaps 322 - * from the same section as the pgdat where possible to avoid 323 - * this problem. 324 - */ 325 - goal = pgdat_to_phys(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT); 326 - limit = goal + (1UL << PA_SECTION_SHIFT); 327 - nid = early_pfn_to_nid(goal >> PAGE_SHIFT); 328 - again: 329 - usage = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, goal, limit, nid); 330 - if (!usage && limit) { 331 - limit = MEMBLOCK_ALLOC_ACCESSIBLE; 332 - goto again; 333 - } 334 - return usage; 335 - } 336 - 337 - static void __init check_usemap_section_nr(int nid, 338 - struct mem_section_usage *usage) 339 - { 340 - unsigned long usemap_snr, pgdat_snr; 341 - static unsigned long old_usemap_snr; 342 - static unsigned long old_pgdat_snr; 343 - struct pglist_data *pgdat = NODE_DATA(nid); 344 - int usemap_nid; 345 - 346 - /* First call */ 347 - if (!old_usemap_snr) { 348 - old_usemap_snr = NR_MEM_SECTIONS; 349 - old_pgdat_snr = NR_MEM_SECTIONS; 350 - } 351 - 352 - usemap_snr = pfn_to_section_nr(__pa(usage) >> PAGE_SHIFT); 353 - pgdat_snr = pfn_to_section_nr(pgdat_to_phys(pgdat) >> PAGE_SHIFT); 354 - if (usemap_snr == pgdat_snr) 355 - return; 356 - 357 - if (old_usemap_snr == usemap_snr && old_pgdat_snr == pgdat_snr) 358 - /* skip redundant message */ 359 - return; 360 - 361 - old_usemap_snr = usemap_snr; 362 - old_pgdat_snr = pgdat_snr; 363 - 364 - usemap_nid = sparse_early_nid(__nr_to_section(usemap_snr)); 365 - if (usemap_nid != nid) { 366 - pr_info("node %d must be removed before remove section %ld\n", 367 - nid, usemap_snr); 368 - return; 369 - } 370 - /* 371 - * There is a circular dependency. 372 - * Some platforms allow un-removable section because they will just 373 - * gather other removable sections for dynamic partitioning. 374 - * Just notify un-removable section's number here. 375 - */ 376 - pr_info("Section %ld and %ld (node %d) have a circular dependency on usemap and pgdat allocations\n", 377 - usemap_snr, pgdat_snr, nid); 378 - } 379 - #else 380 - static struct mem_section_usage * __init 381 - sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, 382 - unsigned long size) 383 - { 384 - return memblock_alloc_node(size, SMP_CACHE_BYTES, pgdat->node_id); 385 - } 386 - 387 - static void __init check_usemap_section_nr(int nid, 388 - struct mem_section_usage *usage) 389 - { 390 - } 391 - #endif /* CONFIG_MEMORY_HOTREMOVE */ 392 - 393 297 #ifdef CONFIG_SPARSEMEM_VMEMMAP 394 298 unsigned long __init section_map_size(void) 395 299 { ··· 390 486 unsigned long pnum, unsigned long flags) 391 487 { 392 488 BUG_ON(!sparse_usagebuf || sparse_usagebuf >= sparse_usagebuf_end); 393 - check_usemap_section_nr(nid, sparse_usagebuf); 394 489 sparse_init_one_section(__nr_to_section(pnum), pnum, map, 395 490 sparse_usagebuf, SECTION_IS_EARLY | flags); 396 491 sparse_usagebuf = (void *)sparse_usagebuf + mem_section_usage_size(); ··· 400 497 unsigned long size; 401 498 402 499 size = mem_section_usage_size() * map_count; 403 - sparse_usagebuf = sparse_early_usemaps_alloc_pgdat_section( 404 - NODE_DATA(nid), size); 500 + sparse_usagebuf = memblock_alloc_node(size, SMP_CACHE_BYTES, nid); 405 501 if (!sparse_usagebuf) { 406 502 sparse_usagebuf_end = NULL; 407 503 return -ENOMEM;