[PATCH 4/4] workqueue: Handle cpu-node affinity change at CPU_ONLINE.

Kamezawa Hiroyuki
2014-12-15T11:22:29Z

This is a corner case fix. In general, cpu-to-node relationship is
fixed when cpu/memory are visible to kernel based on firmware
information. But in some case, cpu-to-node relationship is updated
at CPU_ONLINE.

In arch/x86/mm/numa.c::numa_init_array(), a cpu will be tied to
a random numa node if the node firmware tells is memry-less node.
Such cpu's cpu affinity can be changed in cpu_up().

For example,
step 1. boot with mem= boot option, hide memory.
step 2. online hidden memory with using memory hot-add.
step 3. offline cpus.
step 4. online cpus.

In step 4, cpu's numa node affinity can be modified if memory-less
node turns out to be an usual node by step 2.

This patch handles the event in CPU_ONLINE callback of workqueue.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
kernel/workqueue.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 5499b76..cc0e1d4 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4583,6 +4583,20 @@ void workqueue_node_register(int node)
}
mutex_unlock(&wq_pool_mutex);
}
+/*
+ * When a cpu boot up with a memory less node, the cpu is be tied
+ * a random node (see arch/x86/mm/numa.c::numa_init_array()).
+ * The relationship is fixed when a proper memory node comes up and
+ * it's visible after CPU_ONLINE. check and reflesh it.
+ */
+void check_reflesh_node_cpumask(int cpu)
+{
+ int node = cpu_to_node(cpu);
+
+ if (likely(cpumask_test_cpu(cpu, wq_numa_possible_cpumask[node])))
+ return;
+ reflesh_wq_possible_mask(cpu, node);
+}

#endif

@@ -4617,6 +4631,7 @@ static int workqueue_cpu_up_callback(struct notifier_block *nfb,
*/
for_each_cpu_worker_pool(pool, cpu)
pool->node = cpu_to_node(cpu);
+ check_reflesh_node_cpumask(cpu);

for_each_pool(pool, pi) {
mutex_lock(&pool->attach_mutex);
--
1.8.3.1