History

workqueue: determine NUMA node of workers accourding to the allowed cpumask

When worker tasks are created using kthread_create_on_node(), currently only per-cpu ones have the matching NUMA node specified. All unbound workers are always created with NUMA_NO_NODE. Now that an unbound worker pool may have an arbitrary cpumask associated with it, this isn't optimal. Add pool->node which is determined by the pool's cpumask. If the pool's cpumask is contained inside a NUMA node proper, the pool is associated with that node, and all workers of the pool are created on that node. This currently only makes difference for unbound worker pools with cpumask contained inside single NUMA node, but this will serve as foundation for making all unbound pools NUMA-affine.

Tejun Heo committed 13 years ago

Commit f3f90ad1 parent e3c916a1 file · +16 −2Browse files

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

Unified · Split

kernel/workqueue.c+16−2
@@ -138,6 +138,7 @@ enum { · 137 unmodified lines
138138 struct worker_pool {
139139 spinlock_t lock; /* the pool lock */
140140 int cpu; /* I: the associated cpu */
141+ int node; /* I: the associated node ID */
141142 int id; /* I: pool ID */
142143 unsigned int flags; /* X: flags */
143144
@@ -1645,7 +1646,6 @@ static struct worker *alloc_worker(void) · 1501 unmodified lines
16451646 static struct worker *create_worker(struct worker_pool *pool)
16461647 {
16471648 struct worker *worker = NULL;
1648− int node = pool->cpu >= 0 ? cpu_to_node(pool->cpu) : NUMA_NO_NODE;
16491649 int id = -1;
16501650 char id_buf[16];
16511651
@@ -1678,7 +1678,7 @@ static struct worker *create_worker(struct worker_pool *pool) · 26 unmodified lines
16781678 else
16791679 snprintf(id_buf, sizeof(id_buf), "u%d:%d", pool->id, id);
16801680
1681− worker->task = kthread_create_on_node(worker_thread, worker, node,
1681+ worker->task = kthread_create_on_node(worker_thread, worker, pool->node,
16821682 "kworker/%s", id_buf);
16831683 if (IS_ERR(worker->task))
16841684 goto fail;
@@ -3360,6 +3360,7 @@ static int init_worker_pool(struct worker_pool *pool) · 1675 unmodified lines
33603360 spin_lock_init(&pool->lock);
33613361 pool->id = -1;
33623362 pool->cpu = -1;
3363+ pool->node = NUMA_NO_NODE;
33633364 pool->flags |= POOL_DISASSOCIATED;
33643365 INIT_LIST_HEAD(&pool->worklist);
33653366 INIT_LIST_HEAD(&pool->idle_list);
@@ -3465,6 +3466,7 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 99 unmodified lines
34653466 {
34663467 u32 hash = wqattrs_hash(attrs);
34673468 struct worker_pool *pool;
3469+ int node;
34683470
34693471 lockdep_assert_held(&wq_pool_mutex);
34703472
@@ -3487,6 +3489,17 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 16 unmodified lines
34873489 lockdep_set_subclass(&pool->lock, 1); /* see put_pwq() */
34883490 copy_workqueue_attrs(pool->attrs, attrs);
34893491
3492+ /* if cpumask is contained inside a NUMA node, we belong to that node */
3493+ if (wq_numa_enabled) {
3494+ for_each_node(node) {
3495+ if (cpumask_subset(pool->attrs->cpumask,
3496+ wq_numa_possible_cpumask[node])) {
3497+ pool->node = node;
3498+ break;
3499+ }
3500+ }
3501+ }
3502+
34903503 if (worker_pool_assign_id(pool) < 0)
34913504 goto fail;
34923505
@@ -4480,6 +4493,7 @@ static int __init init_workqueues(void) · 987 unmodified lines
44804493 pool->cpu = cpu;
44814494 cpumask_copy(pool->attrs->cpumask, cpumask_of(cpu));
44824495 pool->attrs->nice = std_nice[i++];
4496+ pool->node = cpu_to_node(cpu);
44834497
44844498 /* alloc pool ID */
44854499 mutex_lock(&wq_pool_mutex);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t