2014-12-16 16:36:40

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: [PATCH 0/2] workqueue: fix a bug when numa mapping is changed v4

This is v4. Thank you for hints/commentes to previous versions.

I think this versions only contains necessary things and not invasive.
Tested several patterns of node hotplug and seems to work well.

Changes since v3
- removed changes against get_unbound_pool()
- remvoed codes in cpu offline event.
- added node unregister callback.
clear wq_numa_possible_mask at node offline rather than cpu offline.
- updates per-cpu pool's pool-> node at node_(un)register.
- added more comments.
- almost all codes are under CONFIG_MEMORY_HOTPLUG

include/linux/memory_hotplug.h | 3 +
kernel/workqueue.c | 81 ++++++++++++++++++++++++++++++++++++++++-
mm/memory_hotplug.c | 6 ++-
3 files changed, 88 insertions(+), 2 deletions(-)

Original problem was a memory allocation failure because pool->node
points to not-online node. This happens when cpu<->node mapping changes.

Yasuaki Ishimatsu hit a allocation failure bug when the numa mapping
between CPU and node is changed. This was the last scene:
SLUB: Unable to allocate memory on node 2 (gfp=0x80d0)
cache: kmalloc-192, object size: 192, buffer size: 192, default order: 1, min order: 0
node 0: slabs: 6172, objs: 259224, free: 245741
node 1: slabs: 3261, objs: 136962, free: 127656


2014-12-16 16:46:05

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: [PATCH 1/2] workqueue: update numa affinity info at node hotplug

With node online/offline, cpu<->node relationship is established.
Workqueue uses a info which was established at boot time but
it may be changed by node hotpluging.

Once pool->node points to a stale node, following allocation failure
happens.
==
SLUB: Unable to allocate memory on node 2 (gfp=0x80d0)
cache: kmalloc-192, object size: 192, buffer size: 192, default
order:
1, min order: 0
node 0: slabs: 6172, objs: 259224, free: 245741
node 1: slabs: 3261, objs: 136962, free: 127656
==
This patch updates per cpu workqueue pool's node affinity and
updates wq_numa_possible_cpumask at node online/offline event.
This update of mask is very important because it affects cpumasks
and preferred node detection.

Unbound workqueue's per node pool are updated by
by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu, by existing code.
What important here is to avoid wrong node detection when a cpu get onlined.
And it's handled by wq_numa_possible_cpumask update introduced by this patch.

Changelog v3->v4:
- added workqueue_node_unregister
- clear wq_numa_possible_cpumask at node offline.
- merged a patch which handles per cpu pools.
- clear per-cpu-pool's pool->node at node offlining.
- set per-cpu-pool's pool->node at node onlining.
- dropped modification to get_unbound_pool()
- dropped per-cpu-pool handling at cpu online/offline.

Reported-by: Yasuaki Ishimatsu <[email protected]>
Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
---
include/linux/memory_hotplug.h | 3 +++
kernel/workqueue.c | 58 +++++++++++++++++++++++++++++++++++++++++-
mm/memory_hotplug.c | 6 ++++-
3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 8f1a419..7b4a292 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -270,4 +270,7 @@ extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms)
extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
unsigned long pnum);

+/* update for workqueues */
+void workqueue_node_register(int node);
+void workqueue_node_unregister(int node);
#endif /* __LINUX_MEMORY_HOTPLUG_H */
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 6202b08..f6ad05a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -266,7 +266,7 @@ struct workqueue_struct {
static struct kmem_cache *pwq_cache;

static cpumask_var_t *wq_numa_possible_cpumask;
- /* possible CPUs of each node */
+ /* PL: possible CPUs of each node */

static bool wq_disable_numa;
module_param_named(disable_numa, wq_disable_numa, bool, 0444);
@@ -4563,6 +4563,62 @@ static void restore_unbound_workers_cpumask(struct worker_pool *pool, int cpu)
WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
pool->attrs->cpumask) < 0);
}
+#ifdef CONFIG_MEMORY_HOTPLUG
+
+static void workqueue_update_cpu_numa_affinity(int cpu, int node)
+{
+ struct worker_pool *pool;
+
+ if (node != cpu_to_node(cpu))
+ return;
+ cpumask_set_cpu(cpu, wq_numa_possible_cpumask[node]);
+ for_each_cpu_worker_pool(pool, cpu)
+ pool->node = node;
+}
+
+/*
+ * When a cpu is physically added, cpu<->node relationship is established
+ * based on firmware info. We can catch the whole view when a new NODE_DATA()
+ * coming up (a node is added).
+ * If we don't update the info, pool->node will points to a not-online node
+ * and the kernel will have allocation failure.
+ *
+ * Update wp_numa_possible_mask at online and clear it at offline.
+ */
+void workqueue_node_register(int node)
+{
+ int cpu;
+
+ mutex_lock(&wq_pool_mutex);
+ for_each_possible_cpu(cpu)
+ workqueue_update_cpu_numa_affinity(cpu, node);
+ /* unbound workqueue will be updated when the 1st cpu comes up.*/
+ mutex_unlock(&wq_pool_mutex);
+}
+
+void workqueue_node_unregister(int node)
+{
+ struct worker_pool *pool;
+ int cpu;
+
+ mutex_lock(&wq_pool_mutex);
+ cpumask_clear(wq_numa_possible_cpumask[node]);
+ for_each_possible_cpu(cpu) {
+ if (node == cpu_to_node(cpu))
+ for_each_cpu_worker_pool(pool, cpu)
+ pool->node = NUMA_NO_NODE;
+ }
+ /*
+ * unbound workqueue's per-node pwqs are already refleshed
+ * by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu
+ * on this node, because all cpus of this node went down.
+ * (see wq_calc_node_cpumask()). per-node unbound pwqs has been replaced
+ * with wq->dfl_pwq, already.
+ */
+ mutex_unlock(&wq_pool_mutex);
+}
+
+#endif

/*
* Workqueues should be brought up before normal priority CPU notifiers.
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 9fab107..a0cb5c1 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1122,6 +1122,9 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
*/
reset_node_present_pages(pgdat);

+ /* Update workqueue's numa affinity info. */
+ workqueue_node_register(nid);
+
return pgdat;
}

@@ -1958,7 +1961,8 @@ void try_offline_node(int nid)

if (check_and_unmap_cpu_on_node(pgdat))
return;
-
+ /* update workqueue's numa affinity info. */
+ workqueue_node_unregister(nid);
/*
* all memory/cpu of this node are removed, we can offline this
* node now.
--
1.8.3.1


2014-12-16 16:51:57

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: [PATCH 2/2] workqueue: update cpumask at CPU_ONLINE if necessary

In some case, cpu's numa affinity will be changed in cpu_up().
It happens after a new node is onlined.
(in x86, online cpus are tied to onlined node at boot.
so, if memory is added later, cpu mapping can be changed at cpu_up()

Although wq_numa_possible_cpumask at el. are maintained against
node hotplug, this case should be handled.

Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
---
kernel/workqueue.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index f6ad05a..59d8be5 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4618,6 +4618,27 @@ void workqueue_node_unregister(int node)
mutex_unlock(&wq_pool_mutex);
}

+static void workqueue_may_update_numa_affinity(int cpu)
+{
+ int curnode = cpu_to_node(cpu);
+ int node;
+
+ if (likely(cpumask_test_cpu(cpu, wq_numa_possible_cpumask[curnode])))
+ return;
+
+ /* cpu<->node relationship is changed in cpu_up() */
+ for_each_node_state(node, N_POSSIBLE)
+ cpumask_clear_cpu(cpu, wq_numa_possible_cpumask[node]);
+
+ workqueue_update_cpu_numa_affinity(cpu, curnode);
+}
+#else
+
+static void workqueue_may_update_numa_affinity(int cpu)
+{
+ return;
+}
+
#endif

/*
@@ -4647,6 +4668,8 @@ static int workqueue_cpu_up_callback(struct notifier_block *nfb,
case CPU_ONLINE:
mutex_lock(&wq_pool_mutex);

+ workqueue_may_update_numa_affinity(cpu);
+
for_each_pool(pool, pi) {
mutex_lock(&pool->attach_mutex);

--
1.8.3.1


2014-12-17 01:32:29

by Lai Jiangshan

[permalink] [raw]
Subject: Re: [PATCH 1/2] workqueue: update numa affinity info at node hotplug

On 12/17/2014 12:45 AM, Kamezawa Hiroyuki wrote:
> With node online/offline, cpu<->node relationship is established.
> Workqueue uses a info which was established at boot time but
> it may be changed by node hotpluging.
>
> Once pool->node points to a stale node, following allocation failure
> happens.
> ==
> SLUB: Unable to allocate memory on node 2 (gfp=0x80d0)
> cache: kmalloc-192, object size: 192, buffer size: 192, default
> order:
> 1, min order: 0
> node 0: slabs: 6172, objs: 259224, free: 245741
> node 1: slabs: 3261, objs: 136962, free: 127656
> ==
> This patch updates per cpu workqueue pool's node affinity and
> updates wq_numa_possible_cpumask at node online/offline event.
> This update of mask is very important because it affects cpumasks
> and preferred node detection.
>
> Unbound workqueue's per node pool are updated by
> by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu, by existing code.
> What important here is to avoid wrong node detection when a cpu get onlined.
> And it's handled by wq_numa_possible_cpumask update introduced by this patch.
>
> Changelog v3->v4:
> - added workqueue_node_unregister
> - clear wq_numa_possible_cpumask at node offline.
> - merged a patch which handles per cpu pools.
> - clear per-cpu-pool's pool->node at node offlining.
> - set per-cpu-pool's pool->node at node onlining.
> - dropped modification to get_unbound_pool()
> - dropped per-cpu-pool handling at cpu online/offline.
>
> Reported-by: Yasuaki Ishimatsu <[email protected]>
> Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
> ---
> include/linux/memory_hotplug.h | 3 +++
> kernel/workqueue.c | 58 +++++++++++++++++++++++++++++++++++++++++-
> mm/memory_hotplug.c | 6 ++++-
> 3 files changed, 65 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
> index 8f1a419..7b4a292 100644
> --- a/include/linux/memory_hotplug.h
> +++ b/include/linux/memory_hotplug.h
> @@ -270,4 +270,7 @@ extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms)
> extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
> unsigned long pnum);
>
> +/* update for workqueues */
> +void workqueue_node_register(int node);
> +void workqueue_node_unregister(int node);
> #endif /* __LINUX_MEMORY_HOTPLUG_H */
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 6202b08..f6ad05a 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -266,7 +266,7 @@ struct workqueue_struct {
> static struct kmem_cache *pwq_cache;
>
> static cpumask_var_t *wq_numa_possible_cpumask;
> - /* possible CPUs of each node */
> + /* PL: possible CPUs of each node */
>
> static bool wq_disable_numa;
> module_param_named(disable_numa, wq_disable_numa, bool, 0444);
> @@ -4563,6 +4563,62 @@ static void restore_unbound_workers_cpumask(struct worker_pool *pool, int cpu)
> WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
> pool->attrs->cpumask) < 0);
> }
> +#ifdef CONFIG_MEMORY_HOTPLUG
> +
> +static void workqueue_update_cpu_numa_affinity(int cpu, int node)
> +{
> + struct worker_pool *pool;
> +
> + if (node != cpu_to_node(cpu))
> + return;
> + cpumask_set_cpu(cpu, wq_numa_possible_cpumask[node]);
> + for_each_cpu_worker_pool(pool, cpu)
> + pool->node = node;

Again, You need to check and update all the wq->numa_pwq_tbl[oldnode],
but in this patchset, the required information is lost and we can't find out oldnode.


cpus of oldnode, 16-31(online),48,56,64,72(offline,randomly assigned to the oldnode by numa_init_array())

and then cpu#48 is allocated for newnode and online

Now, the wq->numa_pwq_tbl[oldnode]'s cpumask still have cpu#48, and it may be scheduled to cpu#48.
See the information of my patch 4/5


> +}
> +
> +/*
> + * When a cpu is physically added, cpu<->node relationship is established
> + * based on firmware info. We can catch the whole view when a new NODE_DATA()
> + * coming up (a node is added).
> + * If we don't update the info, pool->node will points to a not-online node
> + * and the kernel will have allocation failure.
> + *
> + * Update wp_numa_possible_mask at online and clear it at offline.
> + */
> +void workqueue_node_register(int node)
> +{
> + int cpu;
> +
> + mutex_lock(&wq_pool_mutex);
> + for_each_possible_cpu(cpu)
> + workqueue_update_cpu_numa_affinity(cpu, node);
> + /* unbound workqueue will be updated when the 1st cpu comes up.*/
> + mutex_unlock(&wq_pool_mutex);
> +}
> +
> +void workqueue_node_unregister(int node)
> +{
> + struct worker_pool *pool;
> + int cpu;
> +
> + mutex_lock(&wq_pool_mutex);
> + cpumask_clear(wq_numa_possible_cpumask[node]);
> + for_each_possible_cpu(cpu) {
> + if (node == cpu_to_node(cpu))
> + for_each_cpu_worker_pool(pool, cpu)
> + pool->node = NUMA_NO_NODE;
> + }
> + /*
> + * unbound workqueue's per-node pwqs are already refleshed
> + * by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu
> + * on this node, because all cpus of this node went down.
> + * (see wq_calc_node_cpumask()). per-node unbound pwqs has been replaced
> + * with wq->dfl_pwq, already.
> + */
> + mutex_unlock(&wq_pool_mutex);
> +}
> +
> +#endif
>
> /*
> * Workqueues should be brought up before normal priority CPU notifiers.
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 9fab107..a0cb5c1 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1122,6 +1122,9 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
> */
> reset_node_present_pages(pgdat);
>
> + /* Update workqueue's numa affinity info. */
> + workqueue_node_register(nid);
> +
> return pgdat;
> }
>
> @@ -1958,7 +1961,8 @@ void try_offline_node(int nid)
>
> if (check_and_unmap_cpu_on_node(pgdat))
> return;
> -
> + /* update workqueue's numa affinity info. */
> + workqueue_node_unregister(nid);
> /*
> * all memory/cpu of this node are removed, we can offline this
> * node now.

2014-12-17 03:23:10

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: Re: [PATCH 1/2] workqueue: update numa affinity info at node hotplug

(2014/12/17 10:36), Lai Jiangshan wrote:
> On 12/17/2014 12:45 AM, Kamezawa Hiroyuki wrote:
>> With node online/offline, cpu<->node relationship is established.
>> Workqueue uses a info which was established at boot time but
>> it may be changed by node hotpluging.
>>
>> Once pool->node points to a stale node, following allocation failure
>> happens.
>> ==
>> SLUB: Unable to allocate memory on node 2 (gfp=0x80d0)
>> cache: kmalloc-192, object size: 192, buffer size: 192, default
>> order:
>> 1, min order: 0
>> node 0: slabs: 6172, objs: 259224, free: 245741
>> node 1: slabs: 3261, objs: 136962, free: 127656
>> ==
>> This patch updates per cpu workqueue pool's node affinity and
>> updates wq_numa_possible_cpumask at node online/offline event.
>> This update of mask is very important because it affects cpumasks
>> and preferred node detection.
>>
>> Unbound workqueue's per node pool are updated by
>> by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu, by existing code.
>> What important here is to avoid wrong node detection when a cpu get onlined.
>> And it's handled by wq_numa_possible_cpumask update introduced by this patch.
>>
>> Changelog v3->v4:
>> - added workqueue_node_unregister
>> - clear wq_numa_possible_cpumask at node offline.
>> - merged a patch which handles per cpu pools.
>> - clear per-cpu-pool's pool->node at node offlining.
>> - set per-cpu-pool's pool->node at node onlining.
>> - dropped modification to get_unbound_pool()
>> - dropped per-cpu-pool handling at cpu online/offline.
>>
>> Reported-by: Yasuaki Ishimatsu <[email protected]>
>> Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
>> ---
>> include/linux/memory_hotplug.h | 3 +++
>> kernel/workqueue.c | 58 +++++++++++++++++++++++++++++++++++++++++-
>> mm/memory_hotplug.c | 6 ++++-
>> 3 files changed, 65 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
>> index 8f1a419..7b4a292 100644
>> --- a/include/linux/memory_hotplug.h
>> +++ b/include/linux/memory_hotplug.h
>> @@ -270,4 +270,7 @@ extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms)
>> extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
>> unsigned long pnum);
>>
>> +/* update for workqueues */
>> +void workqueue_node_register(int node);
>> +void workqueue_node_unregister(int node);
>> #endif /* __LINUX_MEMORY_HOTPLUG_H */
>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>> index 6202b08..f6ad05a 100644
>> --- a/kernel/workqueue.c
>> +++ b/kernel/workqueue.c
>> @@ -266,7 +266,7 @@ struct workqueue_struct {
>> static struct kmem_cache *pwq_cache;
>>
>> static cpumask_var_t *wq_numa_possible_cpumask;
>> - /* possible CPUs of each node */
>> + /* PL: possible CPUs of each node */
>>
>> static bool wq_disable_numa;
>> module_param_named(disable_numa, wq_disable_numa, bool, 0444);
>> @@ -4563,6 +4563,62 @@ static void restore_unbound_workers_cpumask(struct worker_pool *pool, int cpu)
>> WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
>> pool->attrs->cpumask) < 0);
>> }
>> +#ifdef CONFIG_MEMORY_HOTPLUG
>> +
>> +static void workqueue_update_cpu_numa_affinity(int cpu, int node)
>> +{
>> + struct worker_pool *pool;
>> +
>> + if (node != cpu_to_node(cpu))
>> + return;
>> + cpumask_set_cpu(cpu, wq_numa_possible_cpumask[node]);
>> + for_each_cpu_worker_pool(pool, cpu)
>> + pool->node = node;
>
> Again, You need to check and update all the wq->numa_pwq_tbl[oldnode],
> but in this patchset, the required information is lost and we can't find out oldnode.
>
>
> cpus of oldnode, 16-31(online),48,56,64,72(offline,randomly assigned to the oldnode by numa_init_array())
>
> and then cpu#48 is allocated for newnode and online
>
> Now, the wq->numa_pwq_tbl[oldnode]'s cpumask still have cpu#48, and it may be scheduled to cpu#48.
> See the information of my patch 4/5
>

That will not cause page allocation failure, right ? If so, it's out of scope of this patch 1/2.

I think it's handled in patch 2/2, isn't it ?

Thanks,
-Kame



>
>> +}
>> +
>> +/*
>> + * When a cpu is physically added, cpu<->node relationship is established
>> + * based on firmware info. We can catch the whole view when a new NODE_DATA()
>> + * coming up (a node is added).
>> + * If we don't update the info, pool->node will points to a not-online node
>> + * and the kernel will have allocation failure.
>> + *
>> + * Update wp_numa_possible_mask at online and clear it at offline.
>> + */
>> +void workqueue_node_register(int node)
>> +{
>> + int cpu;
>> +
>> + mutex_lock(&wq_pool_mutex);
>> + for_each_possible_cpu(cpu)
>> + workqueue_update_cpu_numa_affinity(cpu, node);
>> + /* unbound workqueue will be updated when the 1st cpu comes up.*/
>> + mutex_unlock(&wq_pool_mutex);
>> +}
>> +
>> +void workqueue_node_unregister(int node)
>> +{
>> + struct worker_pool *pool;
>> + int cpu;
>> +
>> + mutex_lock(&wq_pool_mutex);
>> + cpumask_clear(wq_numa_possible_cpumask[node]);
>> + for_each_possible_cpu(cpu) {
>> + if (node == cpu_to_node(cpu))
>> + for_each_cpu_worker_pool(pool, cpu)
>> + pool->node = NUMA_NO_NODE;
>> + }
>> + /*
>> + * unbound workqueue's per-node pwqs are already refleshed
>> + * by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu
>> + * on this node, because all cpus of this node went down.
>> + * (see wq_calc_node_cpumask()). per-node unbound pwqs has been replaced
>> + * with wq->dfl_pwq, already.
>> + */
>> + mutex_unlock(&wq_pool_mutex);
>> +}
>> +
>> +#endif
>>
>> /*
>> * Workqueues should be brought up before normal priority CPU notifiers.
>> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
>> index 9fab107..a0cb5c1 100644
>> --- a/mm/memory_hotplug.c
>> +++ b/mm/memory_hotplug.c
>> @@ -1122,6 +1122,9 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
>> */
>> reset_node_present_pages(pgdat);
>>
>> + /* Update workqueue's numa affinity info. */
>> + workqueue_node_register(nid);
>> +
>> return pgdat;
>> }
>>
>> @@ -1958,7 +1961,8 @@ void try_offline_node(int nid)
>>
>> if (check_and_unmap_cpu_on_node(pgdat))
>> return;
>> -
>> + /* update workqueue's numa affinity info. */
>> + workqueue_node_unregister(nid);
>> /*
>> * all memory/cpu of this node are removed, we can offline this
>> * node now.
>

2014-12-17 04:57:08

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: Re: [PATCH 1/2] workqueue: update numa affinity info at node hotplug

(2014/12/17 12:22), Kamezawa Hiroyuki wrote:
> (2014/12/17 10:36), Lai Jiangshan wrote:
>> On 12/17/2014 12:45 AM, Kamezawa Hiroyuki wrote:
>>> With node online/offline, cpu<->node relationship is established.
>>> Workqueue uses a info which was established at boot time but
>>> it may be changed by node hotpluging.
>>>
>>> Once pool->node points to a stale node, following allocation failure
>>> happens.
>>> ==
>>> SLUB: Unable to allocate memory on node 2 (gfp=0x80d0)
>>> cache: kmalloc-192, object size: 192, buffer size: 192, default
>>> order:
>>> 1, min order: 0
>>> node 0: slabs: 6172, objs: 259224, free: 245741
>>> node 1: slabs: 3261, objs: 136962, free: 127656
>>> ==
>>> This patch updates per cpu workqueue pool's node affinity and
>>> updates wq_numa_possible_cpumask at node online/offline event.
>>> This update of mask is very important because it affects cpumasks
>>> and preferred node detection.
>>>
>>> Unbound workqueue's per node pool are updated by
>>> by wq_update_unbound_numa() at CPU_DOWN_PREPARE of the last cpu, by existing code.
>>> What important here is to avoid wrong node detection when a cpu get onlined.
>>> And it's handled by wq_numa_possible_cpumask update introduced by this patch.
>>>
>>> Changelog v3->v4:
>>> - added workqueue_node_unregister
>>> - clear wq_numa_possible_cpumask at node offline.
>>> - merged a patch which handles per cpu pools.
>>> - clear per-cpu-pool's pool->node at node offlining.
>>> - set per-cpu-pool's pool->node at node onlining.
>>> - dropped modification to get_unbound_pool()
>>> - dropped per-cpu-pool handling at cpu online/offline.
>>>
>>> Reported-by: Yasuaki Ishimatsu <[email protected]>
>>> Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
>>> ---
>>> include/linux/memory_hotplug.h | 3 +++
>>> kernel/workqueue.c | 58 +++++++++++++++++++++++++++++++++++++++++-
>>> mm/memory_hotplug.c | 6 ++++-
>>> 3 files changed, 65 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
>>> index 8f1a419..7b4a292 100644
>>> --- a/include/linux/memory_hotplug.h
>>> +++ b/include/linux/memory_hotplug.h
>>> @@ -270,4 +270,7 @@ extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms)
>>> extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
>>> unsigned long pnum);
>>>
>>> +/* update for workqueues */
>>> +void workqueue_node_register(int node);
>>> +void workqueue_node_unregister(int node);
>>> #endif /* __LINUX_MEMORY_HOTPLUG_H */
>>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>>> index 6202b08..f6ad05a 100644
>>> --- a/kernel/workqueue.c
>>> +++ b/kernel/workqueue.c
>>> @@ -266,7 +266,7 @@ struct workqueue_struct {
>>> static struct kmem_cache *pwq_cache;
>>>
>>> static cpumask_var_t *wq_numa_possible_cpumask;
>>> - /* possible CPUs of each node */
>>> + /* PL: possible CPUs of each node */
>>>
>>> static bool wq_disable_numa;
>>> module_param_named(disable_numa, wq_disable_numa, bool, 0444);
>>> @@ -4563,6 +4563,62 @@ static void restore_unbound_workers_cpumask(struct worker_pool *pool, int cpu)
>>> WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task,
>>> pool->attrs->cpumask) < 0);
>>> }
>>> +#ifdef CONFIG_MEMORY_HOTPLUG
>>> +
>>> +static void workqueue_update_cpu_numa_affinity(int cpu, int node)
>>> +{
>>> + struct worker_pool *pool;
>>> +
>>> + if (node != cpu_to_node(cpu))
>>> + return;
>>> + cpumask_set_cpu(cpu, wq_numa_possible_cpumask[node]);
>>> + for_each_cpu_worker_pool(pool, cpu)
>>> + pool->node = node;
>>
>> Again, You need to check and update all the wq->numa_pwq_tbl[oldnode],
>> but in this patchset, the required information is lost and we can't find out oldnode.
>>
>>
>> cpus of oldnode, 16-31(online),48,56,64,72(offline,randomly assigned to the oldnode by numa_init_array())
>>
>> and then cpu#48 is allocated for newnode and online
>>
>> Now, the wq->numa_pwq_tbl[oldnode]'s cpumask still have cpu#48, and it may be scheduled to cpu#48.
>> See the information of my patch 4/5
>>
>
> That will not cause page allocation failure, right ? If so, it's out of scope of this patch 1/2.
>
> I think it's handled in patch 2/2, isn't it ?

Let me correct my words. Main purpose of this patch 1/2 is handling a case "node disappers" after boot.
And try to handle physicall node hotplug caes.

Changes of cpu<->node relationship at CPU_ONLINE is handled in patch 2/2.

Thanks,
-Kame


2014-12-25 20:12:04

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 1/2] workqueue: update numa affinity info at node hotplug

On Wed, Dec 17, 2014 at 01:56:29PM +0900, Kamezawa Hiroyuki wrote:
> Let me correct my words. Main purpose of this patch 1/2 is handling a case "node disappers" after boot.
> And try to handle physicall node hotplug caes.
>
> Changes of cpu<->node relationship at CPU_ONLINE is handled in patch 2/2.

Can you please make numa code itself maintain the cpu to nodemask
maps? Let's make workqueue a simple consumer of that and we don't
have proper notification mechanism for node up/down events?

Thanks.

--
tejun