History

workqueue: factor out alloc_and_link_percpu_pwqs()

Move the per-cpu pwq allocation loop out of alloc_and_link_pwqs() into a helper. The inner allocation-failure path now returns -ENOMEM and the caller jumps to the existing enomem cleanup, equivalent to the previous goto. No functional change.

Breno Leitao committed 3 months ago

Commit a6a80c11 parent 79f23601 file · +24 −19Browse files

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

Unified · Split

kernel/workqueue.c+24−19
@@ -5666,6 +5666,28 @@ out_unlock: · 5665 unmodified lines
56665666 put_pwq_unlocked(old_pwq);
56675667 }
56685668
5669+static int alloc_and_link_percpu_pwqs(struct workqueue_struct *wq)
5670+{
5671+ int cpu;
5672+
5673+ for_each_possible_cpu(cpu) {
5674+ struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu);
5675+ struct worker_pool *pool = get_percpu_pool(wq, cpu);
5676+
5677+ *pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node);
5678+ if (!*pwq_p)
5679+ return -ENOMEM;
5680+
5681+ init_pwq(*pwq_p, wq, pool);
5682+
5683+ mutex_lock(&wq->mutex);
5684+ link_pwq(*pwq_p);
5685+ mutex_unlock(&wq->mutex);
5686+ }
5687+
5688+ return 0;
5689+}
5690+
56695691 static int alloc_and_link_pwqs(struct workqueue_struct *wq)
56705692 {
56715693 bool highpri = wq->flags & WQ_HIGHPRI;
@@ -5678,25 +5700,8 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq) · 6 unmodified lines
56785700 goto enomem;
56795701
56805702 if (!(wq->flags & WQ_UNBOUND)) {
5681− for_each_possible_cpu(cpu) {
5682− struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu);
5683− struct worker_pool *pool = get_percpu_pool(wq, cpu);
5684−
5685− *pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL,
5686− pool->node);
5687− if (!*pwq_p)
5688− goto enomem;
5689−
5690− init_pwq(*pwq_p, wq, pool);
5691−
5692− mutex_lock(&wq->mutex);
5693− link_pwq(*pwq_p);
5694− mutex_unlock(&wq->mutex);
5695− }
5696− return 0;
5697− }
5698−
5699− if (wq->flags & __WQ_ORDERED) {
5703+ ret = alloc_and_link_percpu_pwqs(wq);
5704+ } else if (wq->flags & __WQ_ORDERED) {
57005705 struct pool_workqueue *dfl_pwq;
57015706
57025707 ret = apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]);