mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, Breno Leitao <leitao@debian.org>,
	 kernel-team@meta.com, marco.crivellari@suse.com
Subject: [PATCH 2/6] workqueue: factor out alloc_and_link_percpu_pwqs()
Date: Fri, 31 Jul 2026 04:57:34 -0700	[thread overview]
Message-ID: <20260731-wq-pool-refactor-v1-2-8eaf71cdab5f@debian.org> (raw)
In-Reply-To: <20260731-wq-pool-refactor-v1-0-8eaf71cdab5f@debian.org>

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.

Now that the per-cpu branch returns a value through the helper, the
per-cpu, ordered and unbound cases share a single error-handling tail.
Turn the separate per-cpu block and the ordered/unbound if/else into one
if/else-if/else chain, dropping the early return and the duplicated goto.

No functional change.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 kernel/workqueue.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 63a39bb3f5e47..b386a457c0381 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5666,6 +5666,28 @@ static void unbound_wq_update_pwq(struct workqueue_struct *wq, int cpu)
 	put_pwq_unlocked(old_pwq);
 }
 
+static int alloc_and_link_percpu_pwqs(struct workqueue_struct *wq)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu);
+		struct worker_pool *pool = get_percpu_pool(wq, cpu);
+
+		*pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node);
+		if (!*pwq_p)
+			return -ENOMEM;
+
+		init_pwq(*pwq_p, wq, pool);
+
+		mutex_lock(&wq->mutex);
+		link_pwq(*pwq_p);
+		mutex_unlock(&wq->mutex);
+	}
+
+	return 0;
+}
+
 static int alloc_and_link_pwqs(struct workqueue_struct *wq)
 {
 	bool highpri = wq->flags & WQ_HIGHPRI;
@@ -5678,25 +5700,8 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
 		goto enomem;
 
 	if (!(wq->flags & WQ_UNBOUND)) {
-		for_each_possible_cpu(cpu) {
-			struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu);
-			struct worker_pool *pool = get_percpu_pool(wq, cpu);
-
-			*pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL,
-						       pool->node);
-			if (!*pwq_p)
-				goto enomem;
-
-			init_pwq(*pwq_p, wq, pool);
-
-			mutex_lock(&wq->mutex);
-			link_pwq(*pwq_p);
-			mutex_unlock(&wq->mutex);
-		}
-		return 0;
-	}
-
-	if (wq->flags & __WQ_ORDERED) {
+		ret = alloc_and_link_percpu_pwqs(wq);
+	} else if (wq->flags & __WQ_ORDERED) {
 		struct pool_workqueue *dfl_pwq;
 
 		ret = apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]);

-- 
2.53.0-Meta


  parent reply	other threads:[~2026-07-31 11:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 11:57 [PATCH 0/6] workqueue: base pwq pool release and nr_active on the backing pool Breno Leitao
2026-07-31 11:57 ` [PATCH 1/6] workqueue: factor out get_percpu_pool() Breno Leitao
2026-07-31 11:57 ` Breno Leitao [this message]
2026-07-31 11:57 ` [PATCH 3/6] workqueue: release pwq pools by pool type Breno Leitao
2026-08-03  0:31   ` Tejun Heo
2026-08-03 14:02     ` Breno Leitao
2026-08-03 16:50       ` Tejun Heo
2026-07-31 11:57 ` [PATCH 4/6] workqueue: account nr_active by the backing pool Breno Leitao
2026-08-03  0:34   ` Tejun Heo
2026-08-03 14:19     ` Breno Leitao
2026-07-31 11:57 ` [PATCH 5/6] workqueue: add a per-cpu backend for unbound pwqs Breno Leitao
2026-08-03  0:36   ` Tejun Heo
2026-08-03 16:35     ` Breno Leitao
2026-08-03 16:58       ` Tejun Heo
2026-07-31 11:57 ` [PATCH 6/6] workqueue: install per-cpu pwqs at creation for __WQ_PERCPU_POOLS Breno Leitao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260731-wq-pool-refactor-v1-2-8eaf71cdab5f@debian.org \
    --to=leitao@debian.org \
    --cc=jiangshanlai@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marco.crivellari@suse.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®