Skip to content

Commit 9adb62a

Browse files
Jiang Liutorvalds
authored andcommitted
mm/hotplug: correctly setup fallback zonelists when creating new pgdat
When hotadd_new_pgdat() is called to create new pgdat for a new node, a fallback zonelist should be created for the new node. There's code to try to achieve that in hotadd_new_pgdat() as below: /* * The node we allocated has no zone fallback lists. For avoiding * to access not-initialized zonelist, build here. */ mutex_lock(&zonelists_mutex); build_all_zonelists(pgdat, NULL); mutex_unlock(&zonelists_mutex); But it doesn't work as expected. When hotadd_new_pgdat() is called, the new node is still in offline state because node_set_online(nid) hasn't been called yet. And build_all_zonelists() only builds zonelists for online nodes as: for_each_online_node(nid) { pg_data_t *pgdat = NODE_DATA(nid); build_zonelists(pgdat); build_zonelist_cache(pgdat); } Though we hope to create zonelist for the new pgdat, but it doesn't. So add a new parameter "pgdat" the build_all_zonelists() to build pgdat for the new pgdat too. Signed-off-by: Jiang Liu <[email protected]> Signed-off-by: Xishi Qiu <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Rusty Russell <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: Tony Luck <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: KOSAKI Motohiro <[email protected]> Cc: David Rientjes <[email protected]> Cc: Keping Chen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent da92c47 commit 9adb62a

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

include/linux/mmzone.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ typedef struct pglist_data {
721721
#include <linux/memory_hotplug.h>
722722

723723
extern struct mutex zonelists_mutex;
724-
void build_all_zonelists(void *data);
724+
void build_all_zonelists(pg_data_t *pgdat, struct zone *zone);
725725
void wakeup_kswapd(struct zone *zone, int order, enum zone_type classzone_idx);
726726
bool zone_watermark_ok(struct zone *z, int order, unsigned long mark,
727727
int classzone_idx, int alloc_flags);

init/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ asmlinkage void __init start_kernel(void)
506506
setup_per_cpu_areas();
507507
smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
508508

509-
build_all_zonelists(NULL);
509+
build_all_zonelists(NULL, NULL);
510510
page_alloc_init();
511511

512512
printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);

kernel/cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ int __cpuinit cpu_up(unsigned int cpu)
416416

417417
if (pgdat->node_zonelists->_zonerefs->zone == NULL) {
418418
mutex_lock(&zonelists_mutex);
419-
build_all_zonelists(NULL);
419+
build_all_zonelists(NULL, NULL);
420420
mutex_unlock(&zonelists_mutex);
421421
}
422422
#endif

mm/memory_hotplug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages)
513513
zone->present_pages += onlined_pages;
514514
zone->zone_pgdat->node_present_pages += onlined_pages;
515515
if (need_zonelists_rebuild)
516-
build_all_zonelists(zone);
516+
build_all_zonelists(NULL, zone);
517517
else
518518
zone_pcp_update(zone);
519519

@@ -562,7 +562,7 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
562562
* to access not-initialized zonelist, build here.
563563
*/
564564
mutex_lock(&zonelists_mutex);
565-
build_all_zonelists(NULL);
565+
build_all_zonelists(pgdat, NULL);
566566
mutex_unlock(&zonelists_mutex);
567567

568568
return pgdat;

mm/page_alloc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,7 +3032,7 @@ int numa_zonelist_order_handler(ctl_table *table, int write,
30323032
user_zonelist_order = oldval;
30333033
} else if (oldval != user_zonelist_order) {
30343034
mutex_lock(&zonelists_mutex);
3035-
build_all_zonelists(NULL);
3035+
build_all_zonelists(NULL, NULL);
30363036
mutex_unlock(&zonelists_mutex);
30373037
}
30383038
}
@@ -3415,10 +3415,17 @@ static __init_refok int __build_all_zonelists(void *data)
34153415
{
34163416
int nid;
34173417
int cpu;
3418+
pg_data_t *self = data;
34183419

34193420
#ifdef CONFIG_NUMA
34203421
memset(node_load, 0, sizeof(node_load));
34213422
#endif
3423+
3424+
if (self && !node_online(self->node_id)) {
3425+
build_zonelists(self);
3426+
build_zonelist_cache(self);
3427+
}
3428+
34223429
for_each_online_node(nid) {
34233430
pg_data_t *pgdat = NODE_DATA(nid);
34243431

@@ -3463,7 +3470,7 @@ static __init_refok int __build_all_zonelists(void *data)
34633470
* Called with zonelists_mutex held always
34643471
* unless system_state == SYSTEM_BOOTING.
34653472
*/
3466-
void __ref build_all_zonelists(void *data)
3473+
void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone)
34673474
{
34683475
set_zonelist_order();
34693476

@@ -3475,10 +3482,10 @@ void __ref build_all_zonelists(void *data)
34753482
/* we have to stop all cpus to guarantee there is no user
34763483
of zonelist */
34773484
#ifdef CONFIG_MEMORY_HOTPLUG
3478-
if (data)
3479-
setup_zone_pageset((struct zone *)data);
3485+
if (zone)
3486+
setup_zone_pageset(zone);
34803487
#endif
3481-
stop_machine(__build_all_zonelists, NULL, NULL);
3488+
stop_machine(__build_all_zonelists, pgdat, NULL);
34823489
/* cpuset refresh routine should be here */
34833490
}
34843491
vm_total_pages = nr_free_pagecache_pages();

0 commit comments

Comments
 (0)