History

workqueue: Allocate the unbound pool using local node memory

Currently, get_unbound_pool() uses kzalloc() to allocate the worker pool. Actually, we can use the right node to do the allocation, achieving local memory access. This patch selects target node first, and uses kzalloc_node() instead.

Xunlei Pang committed 11 years ago

Commit e2273581 parent 25cb62b1 file · +14 −12Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+14−12
@@ -3199,6 +3199,7 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 3198 unmodified lines
31993199 u32 hash = wqattrs_hash(attrs);
32003200 struct worker_pool *pool;
32013201 int node;
3202+ int target_node = NUMA_NO_NODE;
32023203
32033204 lockdep_assert_held(&wq_pool_mutex);
32043205
@@ -3210,13 +3211,25 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 5 unmodified lines
32103211 }
32113212 }
32123213
3214+ /* if cpumask is contained inside a NUMA node, we belong to that node */
3215+ if (wq_numa_enabled) {
3216+ for_each_node(node) {
3217+ if (cpumask_subset(attrs->cpumask,
3218+ wq_numa_possible_cpumask[node])) {
3219+ target_node = node;
3220+ break;
3221+ }
3222+ }
3223+ }
3224+
32133225 /* nope, create a new one */
3214− pool = kzalloc(sizeof(*pool), GFP_KERNEL);
3226+ pool = kzalloc_node(sizeof(*pool), GFP_KERNEL, target_node);
32153227 if (!pool || init_worker_pool(pool) < 0)
32163228 goto fail;
32173229
32183230 lockdep_set_subclass(&pool->lock, 1); /* see put_pwq() */
32193231 copy_workqueue_attrs(pool->attrs, attrs);
3232+ pool->node = target_node;
32203233
32213234 /*
32223235 * no_numa isn't a worker_pool attribute, always clear it. See
@@ -3224,17 +3237,6 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 1 unmodified line
32243237 */
32253238 pool->attrs->no_numa = false;
32263239
3227− /* if cpumask is contained inside a NUMA node, we belong to that node */
3228− if (wq_numa_enabled) {
3229− for_each_node(node) {
3230− if (cpumask_subset(pool->attrs->cpumask,
3231− wq_numa_possible_cpumask[node])) {
3232− pool->node = node;
3233− break;
3234− }
3235− }
3236− }
3237−
32383240 if (worker_pool_assign_id(pool) < 0)
32393241 goto fail;
32403242