From: Yasunori Goto When node is hot-added, kswapd for the node should start. This export kswapd start function as kswapd_run() to use at add_memory(). Signed-off-by: Yasunori Goto Signed-off-by: KAMEZAWA Hiroyuki Cc: Dave Hansen Cc: "Brown, Len" Signed-off-by: Andrew Morton --- include/linux/swap.h | 2 ++ mm/vmscan.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff -puN include/linux/swap.h~pgdat-allocation-for-new-node-add-export-kswapd-start-func include/linux/swap.h --- a/include/linux/swap.h~pgdat-allocation-for-new-node-add-export-kswapd-start-func +++ a/include/linux/swap.h @@ -199,6 +199,8 @@ static inline int zone_reclaim(struct zo } #endif +extern int kswapd_run(int nid); + #ifdef CONFIG_MMU /* linux/mm/shmem.c */ extern int shmem_unuse(swp_entry_t entry, struct page *page); diff -puN mm/vmscan.c~pgdat-allocation-for-new-node-add-export-kswapd-start-func mm/vmscan.c --- a/mm/vmscan.c~pgdat-allocation-for-new-node-add-export-kswapd-start-func +++ a/mm/vmscan.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -1468,20 +1469,35 @@ static int cpu_callback(struct notifier_ } #endif /* CONFIG_HOTPLUG_CPU */ -static int __init kswapd_init(void) +/* + * This kswapd start function will be called by init and node-hot-add. + * On node-hot-add, kswapd will moved to proper cpus if cpus are hot-added. + */ +int kswapd_run(int nid) { - pg_data_t *pgdat; + pg_data_t *pgdat = NODE_DATA(nid); + int ret = 0; - swap_setup(); - for_each_online_pgdat(pgdat) { - pid_t pid; + if (pgdat->kswapd) + return 0; - pid = kernel_thread(kswapd, pgdat, CLONE_KERNEL); - BUG_ON(pid < 0); - read_lock(&tasklist_lock); - pgdat->kswapd = find_task_by_pid(pid); - read_unlock(&tasklist_lock); + pgdat->kswapd = kthread_run(kswapd, pgdat, "kswapd%d", nid); + if (IS_ERR(pgdat->kswapd)) { + /* failure at boot is fatal */ + BUG_ON(system_state == SYSTEM_BOOTING); + printk("Failed to start kswapd on node %d\n",nid); + ret = -1; } + return ret; +} + +static int __init kswapd_init(void) +{ + int nid; + + swap_setup(); + for_each_online_node(nid) + kswapd_run(nid); hotcpu_notifier(cpu_callback, 0); return 0; } _