From 9bd3badff4e7b97209961875014053d6a292af99 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 18 Mar 2004 16:04:03 -0800 Subject: [PATCH] [PATCH] Hotplug CPUs: Kswapd Changes Keep track of kswapds: it's OK that they get moved off a node when the last CPU goes down, but when a CPU comes back, we should try to move the kswapd back onto its node. --- include/linux/mmzone.h | 1 + mm/vmscan.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 7056b88aad409..789d72e7773be 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -214,6 +214,7 @@ typedef struct pglist_data { int node_id; struct pglist_data *pgdat_next; wait_queue_head_t kswapd_wait; + struct task_struct *kswapd; } pg_data_t; #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) diff --git a/mm/vmscan.c b/mm/vmscan.c index be07be47f92b1..0b290c82c1f4a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -1102,13 +1104,39 @@ int shrink_all_memory(int nr_pages) } #endif +#ifdef CONFIG_HOTPLUG_CPU +/* It's optimal to keep kswapds on the same CPUs as their memory, but + not required for correctness. So if the last cpu in a node goes + away, we get changed to run anywhere: as the first one comes back, + restore their cpu bindings. */ +static int __devinit cpu_callback(struct notifier_block *nfb, + unsigned long action, + void *hcpu) +{ + pg_data_t *pgdat; + cpumask_t mask; + + if (action == CPU_ONLINE) { + for_each_pgdat(pgdat) { + mask = node_to_cpumask(pgdat->node_id); + if (any_online_cpu(mask) != NR_CPUS) + /* One of our CPUs online: restore mask */ + set_cpus_allowed(pgdat->kswapd, mask); + } + } + return NOTIFY_OK; +} +#endif /* CONFIG_HOTPLUG_CPU */ + static int __init kswapd_init(void) { pg_data_t *pgdat; swap_setup(); for_each_pgdat(pgdat) - kernel_thread(kswapd, pgdat, CLONE_KERNEL); + pgdat->kswapd + = find_task_by_pid(kernel_thread(kswapd, pgdat, CLONE_KERNEL)); total_memory = nr_free_pagecache_pages(); + hotcpu_notifier(cpu_callback, 0); return 0; } -- 2.53.0