From nobody Sat Jul 25 19:26:33 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AA6C37A83B for ; Tue, 14 Jul 2026 11:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029329; cv=none; b=CbiMglF5CVVbFdRkWjE2kERK1Gg5eCTofBfTkckDyF2CtebY3LAdr+sc0Y+TPlNLtOtu7/JnYTW5wKMOu8CjVHZJRMaC/2iBsX9gWbNUQjscOOByfXAP9BbFpgFfTpDDojhzBkGuX6iH5CK0jHldf9R51lB+4uVyRRXCvkCh8iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029329; c=relaxed/simple; bh=O5nG5dGY/0v3rta/SA4ljsRF6HsvrLtweQSMzPEU+eM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VMN1vPp3XvRnl3aP8a6CM8GuXf3DixVhHHwG4eBP/pGglX2Mcl14xm5poP9U/e97uFHC7mc1KMr4SUUx+sKHynUrFuFe34nmuInpviZn0/jEXlthdFEOVFrKx5LHHZU9+MPg7/F08Zum5p9Z5IWIjf59Wrl/5VJ9gegqL1gCDhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=r/g0bL4E; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="r/g0bL4E" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=bysurook0VEt/+rcFeZpuonxKanyjQDj/VlIc7vFigA=; b=r/g0bL4EZBb6DdOvW3OeHVKJg7 /4GGaSeUkXcr66QEgrR7y0TBAUVW5pSHfoK1GgPAiPHguBmu56Cu+NVGdBBaxfydY8WljeQAyindf +wzQEiscrGLUkRdBwVIb9sXzDoGrJSxmTk78ZyWCdLEyHI7YIZDjmQVXMLPNz1m6441A2hPbrB8LH 9t8lU9DutH3MRhpOjskvFsi+TG338cR4xeo2wMh87tVvnHwxxWTONxL1SOwVlGH6V6zCTKB0Xhy6Z LuafpyXycmpG8fYFNJJx21TM+P3IP5ffPlpJhO5OPJWeLObgV5L1Yj+YzGLbBCam+UVZfXf12Tzw/ GWmqcDOA==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wjbWO-002FZ9-1C; Tue, 14 Jul 2026 11:41:56 +0000 From: Breno Leitao Date: Tue, 14 Jul 2026 04:41:47 -0700 Subject: [PATCH RFC 1/3] workqueue: introduce alloc_pwq() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260714-tejun1-v1-1-024d59241386@debian.org> References: <20260714-tejun1-v1-0-024d59241386@debian.org> In-Reply-To: <20260714-tejun1-v1-0-024d59241386@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-d5d98 X-Developer-Signature: v=1; a=openpgp-sha256; l=4739; i=leitao@debian.org; h=from:subject:message-id; bh=O5nG5dGY/0v3rta/SA4ljsRF6HsvrLtweQSMzPEU+eM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqViB9IqmJHT7heKXIGA/BamjpD6AvvJK1r28mE P1q9Wgq44aJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCalYgfQAKCRA1o5Of/Hh3 bXCzEACoahvHqMPGaex2X2q+qIXcGg6JRcixh1xjtTkkCDvlQPa61tNio9sjgrUmBCuPZPaslKp pl/VrOSPV0gCDhW70VzTif+14nu5fLjwHKSKz0a04MyU471mTYP8Pn8Xj0s46K8KN0zaLOLczE0 nchBtpqGYaNveSS0BVwRHWt61feNfkEJegyTa6C68Nhxq3oSu+wFUQIY1fOHjOUzKI3eKRjb3wh 8GGFkvlf5F7ySgtfXQ502MiQ2mBnZ4R+Z43VojMb2x/YmUSLI01RiFTZXTpjJI1biqzyZUu4sCZ jkh0yNkpVvj9V1AqtqBiCX9o9KBIMWx0Unq3h91/Vo2QuL1yOzVVGgtHFS0sl2AnGRpCLdn3Uv/ dY9hCtiNtZWJkzQ6UMWF1WtglLDRqTOtjZRMqkDq7zHnNTf5E0nFxl8Hl9KBri4fKk7VWiCnrE/ m0MH6O18j66dixpXdr8A5YK5gUBo1nLD0Qw5epNNXkPHgEdyDQl+maojKVgfloWmssc6lEFOrHF 1W+Fxe5ITDBmrUI+WHD6hhefa3Lk54KNUhQuSZm3V0yMh07y3LMkhVGeyX/BkOEO1AFGmsEF8hJ FjvLqkv1gX0BgZS2z1dUNTCUe5wODWq9bwwKl0FAoubruBgGzzMn0EWdcQAN+RJ38Ju1ta6ojNQ iGU8pLsW0539qbg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Factor the static per-cpu pool lookup out of alloc_and_link_pwqs() into get_percpu_pool(), and add alloc_pwq() -- a common pwq allocator that picks the backing pool by workqueue type: a percpu workqueue uses the static per-cpu pool for @cpu (get_percpu_pool()), an unbound workqueue uses a pool matching @attrs (get_unbound_pool()). The paired put_pwq_pool() releases only unbound pools; static per-cpu pools are permanent. alloc_pwq() replaces alloc_unbound_pwq() and gives the workqueue core a single entry point that can produce a pwq pointing at either kind of pool -- the building block for unifying percpu and unbound workqueues. No functional change: the current alloc_pwq() callers only operate on unbound workqueues, so its percpu branch is not exercised yet. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 61 +++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 94f37ea762365..c32e173af2335 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5354,8 +5354,38 @@ static void link_pwq(struct pool_workqueue *pwq) list_add_tail_rcu(&pwq->pwqs_node, &wq->pwqs); } =20 -/* obtain a pool matching @attr and create a pwq associating the pool and = @wq */ -static struct pool_workqueue *alloc_unbound_pwq(struct workqueue_struct *w= q, +/* Return the static per-cpu worker_pool that backs @wq on @cpu. */ +static struct worker_pool *get_percpu_pool(struct workqueue_struct *wq, in= t cpu) +{ + struct worker_pool __percpu *pools; + bool highpri; + + WARN_ON(wq->flags & WQ_UNBOUND); + + highpri =3D wq->flags & WQ_HIGHPRI; + if (wq->flags & WQ_BH) + pools =3D bh_worker_pools; + else + pools =3D cpu_worker_pools; + + return &per_cpu_ptr(pools, cpu)[highpri]; +} + +/* release the pool obtained for @wq's pwq; only unbound pools are refcoun= ted */ +static void put_pwq_pool(struct workqueue_struct *wq, struct worker_pool *= pool) +{ + if (!(wq->flags & WQ_UNBOUND)) + return; + + put_unbound_pool(pool); +} + +/* + * Obtain the pool backing @wq on @cpu and create a pwq associating it wit= h @wq. + * A percpu @wq uses the static per-cpu pool for @cpu; an unbound @wq uses= a + * pool matching @attrs. + */ +static struct pool_workqueue *alloc_pwq(struct workqueue_struct *wq, int c= pu, const struct workqueue_attrs *attrs) { struct worker_pool *pool; @@ -5363,13 +5393,16 @@ static struct pool_workqueue *alloc_unbound_pwq(str= uct workqueue_struct *wq, =20 lockdep_assert_held(&wq_pool_mutex); =20 - pool =3D get_unbound_pool(attrs); + if (wq->flags & WQ_UNBOUND) + pool =3D get_unbound_pool(attrs); + else + pool =3D get_percpu_pool(wq, cpu); if (!pool) return NULL; =20 pwq =3D kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node); if (!pwq) { - put_unbound_pool(pool); + put_pwq_pool(wq, pool); return NULL; } =20 @@ -5478,7 +5511,7 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, copy_workqueue_attrs(new_attrs, attrs); wqattrs_actualize_cpumask(new_attrs, unbound_cpumask); cpumask_copy(new_attrs->__pod_cpumask, new_attrs->cpumask); - ctx->dfl_pwq =3D alloc_unbound_pwq(wq, new_attrs); + ctx->dfl_pwq =3D alloc_pwq(wq, -1, new_attrs); if (!ctx->dfl_pwq) goto out_free; =20 @@ -5488,7 +5521,7 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, ctx->pwq_tbl[cpu] =3D ctx->dfl_pwq; } else { wq_calc_pod_cpumask(new_attrs, cpu); - ctx->pwq_tbl[cpu] =3D alloc_unbound_pwq(wq, new_attrs); + ctx->pwq_tbl[cpu] =3D alloc_pwq(wq, cpu, new_attrs); if (!ctx->pwq_tbl[cpu]) goto out_free; } @@ -5632,7 +5665,7 @@ static void unbound_wq_update_pwq(struct workqueue_st= ruct *wq, int cpu) return; =20 /* create a new pwq */ - pwq =3D alloc_unbound_pwq(wq, target_attrs); + pwq =3D alloc_pwq(wq, cpu, target_attrs); if (!pwq) { pr_warn("workqueue: allocation failed while updating CPU pod affinity of= \"%s\"\n", wq->name); @@ -5668,19 +5701,9 @@ static int alloc_and_link_pwqs(struct workqueue_stru= ct *wq) goto enomem; =20 if (!(wq->flags & WQ_UNBOUND)) { - struct worker_pool __percpu *pools; - - if (wq->flags & WQ_BH) - pools =3D bh_worker_pools; - else - pools =3D cpu_worker_pools; - for_each_possible_cpu(cpu) { - struct pool_workqueue **pwq_p; - struct worker_pool *pool; - - pool =3D &(per_cpu_ptr(pools, cpu)[highpri]); - pwq_p =3D per_cpu_ptr(wq->cpu_pwq, cpu); + struct pool_workqueue **pwq_p =3D per_cpu_ptr(wq->cpu_pwq, cpu); + struct worker_pool *pool =3D get_percpu_pool(wq, cpu); =20 *pwq_p =3D kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node); --=20 2.53.0-Meta From nobody Sat Jul 25 19:26:33 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE8893845A2 for ; Tue, 14 Jul 2026 11:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029334; cv=none; b=K7XBW+gOcWtZq05TgW4gp5WjVVQ4ICJXDdx3+vKV6EeeqKgnb5vRxKGorl5Yl/h2Y8/aCovjUxF9Rf+JYn1QsZLOmEK+B6gjO0Vxpqn269ESrtMzmNcl7ugeqbntjPyRzLvOQLhFRs5FfNgBU13h4TQkXQk7Tm3xLKy0qGzXbNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029334; c=relaxed/simple; bh=Ci/F+btcp36I+3z2i1o5BD4BDvCN0o1CTvBe8N/qwOI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TeeQVP2+D7Cj5y8L2Ujvrht34AfNUZHFm2CskmpP4SmktJyS8Fi77X0AAgreEttaBfO1yPqZSFPwH0Pr3lX/JkpXJvvm+eWJLcr2ulzGsU+3rcS6YrFvdl7KhG7EbLeYsY9G4Lx4ksNMwq9/sMoOVS8KKCXwDF/gLlNHqOBrpXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=bL2Z1Evi; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="bL2Z1Evi" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=vxB4o+e47F8wE78A9xaCMTbiYexwMX39O+F4unlip3s=; b=bL2Z1EviKMFYaz7ryYvdXwUcem VlQo3NmkZa+P+oVHaX+mK4Qdnxdr1XJaSSuL3A+MUU4QYGgDg/KdoeaqbZsf6fS0qM/sran8UmFVM ZEDdA1F+5jtfapxXYTRFy8INuXUO2kA+w0u4RX/0CvkCCSNWMJ4Ux5qcOyiVuQ+DkNmvLBFTELtjD g/S+muaWh6qMRCxzsdjynYx2CQfd0X33HEQTpPq3SGcf0BuML6h/1BrLdxLmNg0l0uFvZwgMI/FVF aPaivtFwACPo9J/Mhdoz8XOjUoATyrF7dlVRQHs0rQ8/xJKB+SfifPmuWU8iagl0EVRPVITf0CHkr f/aS3fDA==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wjbWR-002FZK-2j; Tue, 14 Jul 2026 11:42:00 +0000 From: Breno Leitao Date: Tue, 14 Jul 2026 04:41:48 -0700 Subject: [PATCH RFC 2/3] workqueue: allocate percpu pwqs through alloc_pwq() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260714-tejun1-v1-2-024d59241386@debian.org> References: <20260714-tejun1-v1-0-024d59241386@debian.org> In-Reply-To: <20260714-tejun1-v1-0-024d59241386@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-d5d98 X-Developer-Signature: v=1; a=openpgp-sha256; l=1358; i=leitao@debian.org; h=from:subject:message-id; bh=Ci/F+btcp36I+3z2i1o5BD4BDvCN0o1CTvBe8N/qwOI=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqViB9A25NhlKR1BNHpMi9EfTPxMJxNTzO7Z34M WXHuui83eeJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCalYgfQAKCRA1o5Of/Hh3 bToGD/4n/ImUjcnV+zps6QvV/tYqGjHSIip3W2rg6KttA76jZHwSQCWyRAKOxwklxCdTzVCHnm1 j/ytJY+tc5vFxeel/9NqW4AZawQRiwhrOmJHsYTQEcOaTkzngublBiOflG4lsSKvqTPkY1JlaBD aDEeZp6EkTCJstpBwZzRUef8Z3RZrrhcJ4b0vDLAXcFXjOshAzclEiDPCAD3xdEh+16v4ITLBbH L3ZTSP+NrIxk0e/v/eSJnxMbGjs6TfZth2AttCCHvc5PN9OiudNLII+S+r7hWWp6pWk6ianiNEn v5acHVscVy6sTrloa9Kagy4SBi27vuEtopGgTz6djwNwM3aAa10qePLKIP8LK/H5aZn32w23PWR QiU2sG22bX7LfZ5BU0hOdp4Xrk+n5QBeYZkmJ1FxkSQQz0hsQb8y79IySaLGfV6ykpU4DjYtuPg 7Fs04ScgdiYz0u0yoqnYRbT3YjVg98QUDP9Hp48AZULCd9sTvNwIQk8fmLTKlZDDewe8wFNbTvB TaI7YwP4xy8mfGpUUi6ePkBv9GnX1FHYcvWyiyJFEZIEaPA0V6rfFBv2kMVCz/IVEWWDOJDTyJ8 eTi+YDniZtYzLQPRg7W3LKChnWQeFQBJxlpeNgLOqLV/RYprtpUpp8zLaPMhWKEIivPARRkSiim FYNAnFLj85bLQug== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Route the per-cpu pwq allocation loop in alloc_and_link_pwqs() through the common alloc_pwq() instead of open-coding get_percpu_pool() + pwq allocation + init_pwq(). alloc_pwq() is now the single entry point for both percpu and unbound pwq allocation, and its percpu branch is exercised for every percpu workqueue created. No functional change: alloc_pwq(wq, cpu, NULL) on a percpu workqueue selects the static per-cpu pool for @cpu, exactly as the open-coded path did. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index c32e173af2335..50baf4fe5fcf5 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5703,15 +5703,11 @@ static int alloc_and_link_pwqs(struct workqueue_str= uct *wq) if (!(wq->flags & WQ_UNBOUND)) { for_each_possible_cpu(cpu) { struct pool_workqueue **pwq_p =3D per_cpu_ptr(wq->cpu_pwq, cpu); - struct worker_pool *pool =3D get_percpu_pool(wq, cpu); =20 - *pwq_p =3D kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, - pool->node); + *pwq_p =3D alloc_pwq(wq, cpu, NULL); if (!*pwq_p) goto enomem; =20 - init_pwq(*pwq_p, wq, pool); - mutex_lock(&wq->mutex); link_pwq(*pwq_p); mutex_unlock(&wq->mutex); --=20 2.53.0-Meta From nobody Sat Jul 25 19:26:33 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E15DA380FE7 for ; Tue, 14 Jul 2026 11:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029329; cv=none; b=ektogCtKb/oUpiFI3jm8mOHY7tQ8eG7B7+SVYiEBWwfO/ZF62oOxkwlOpLHXZCtTfZ7JqUSrCdoC6AqoRhMMq+Mis3TKzofeT2KanHX3fcE8+NI5xKEs7IxUVPs7cYIK/ht5tED8FqA6Ba2rhzskGH7zC595W3YkyjGygZhvAHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784029329; c=relaxed/simple; bh=IUQTz2+psDeV1/AxvWu1Lsau7o6+qUlb/z/Goewyy10=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=n5SWRmjV4OCnrojES5650WzafeDVEVzp2wbB62vbOesii6K+8q69kv+VQOk0cXmHSNkoGkkM+D2wWV3U3i1jBtnIxZEtpqrowX+oiy8htV7ezPn3vIFzpm7e2mveJLsXh/5Alk6Twr0/y+QO/7SJetw9j1uHKCA1xwFkmHC0s2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=oeGQrkUQ; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="oeGQrkUQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=qv0L7we4jR4Ig+KGVqf/QIewzjKaDetknOtoVRS+Pd0=; b=oeGQrkUQBepuWZw0vRhV7xNFub /2wiLkYLzdAH/RXXR6AaC+Bn8ATW9OUhWQKtgZoe/e9OE7/QZ9nYspL2Vr+wMGWLiXxdHQusx0UAN A4gF3BeSI1rA9Uuy4gBrgl2Qrsm4k+/xga0hPARggxr+875G3EMoZXJmE8Vw+8iM6CXPuUr4grjlL Tibe2R/0zihAIlcJkIoUYCb9ZgD57m/P98CAErTtlURnurvemZQQB6ZZuoWSzM/K2rNl1Ccm6Sk4b 6zSl81ybSR6ufIxZQqIDSs8VVNowXjCXi8hHgyVo4hos3fDPPeTYq/j9cFXTBXiMHjKVagIIchliH fDuHBd3A==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wjbWV-002FZZ-1N; Tue, 14 Jul 2026 11:42:03 +0000 From: Breno Leitao Date: Tue, 14 Jul 2026 04:41:49 -0700 Subject: [PATCH RFC 3/3] workqueue: factor out alloc_and_link_percpu_pwqs() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260714-tejun1-v1-3-024d59241386@debian.org> References: <20260714-tejun1-v1-0-024d59241386@debian.org> In-Reply-To: <20260714-tejun1-v1-0-024d59241386@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.16-dev-d5d98 X-Developer-Signature: v=1; a=openpgp-sha256; l=2170; i=leitao@debian.org; h=from:subject:message-id; bh=IUQTz2+psDeV1/AxvWu1Lsau7o6+qUlb/z/Goewyy10=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqViB9gIE8W7oGcqx2eOi/CLNTej1442Gi1my7p tYlt2eilPuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCalYgfQAKCRA1o5Of/Hh3 bU5vD/0RmxD6vbahzIDh6gS9VG0INB7bDstGuVgC3xyj7arxfxxHDALEwKta00GiN1Ydia67F4x ZDafZQ5yhgGrQ2KTtow8YWcLba0Do2/FYZsNxHXAGdK6ioe23THT/uWK92GN8ci15EE5rvgFnYv crrjBjaHQ4AL86HXxS+L4kLX3FL/JptUhrCV3Wyg+jAZu3Sz30utaHXrmTO4u2hcNQWg0vItOiS VaITOI0aeRmc95dL70hS3+BKThXWZ2e0LbxRSwSaXZbQHg5w0acpc6+x/iA/5DOD86tMcDH/Nfx NH1/XNEGnhlmyFywQwdJhCvikuHKVGNN8+xPVrzvFPaY+kApWuB59j6luAzVpNCvCX+H+ugr7Du HMwE2EnninUZFSldmDxruKXze32PUjfeeoEGoi5xqsupewfk6ewQzJNMkY+ZHzJ3wk+UpIy8uQs odnRcYwBRN5jN+pM4QC8KM+xiG4M7mPkk9upM34sYpggcgoh0Dzf2kS5MHibWvLlSjr7aiD0OZJ TS942OxjCVd0Rs1BNsYth83bVVq0+71BhVBT97dB2KM60iPxkW8FYBhtLUeLXctEkHC7VFWDerk aV4GLsrUGDwDSEB2JlRIvbqWJcEQvQqdgw+Kbdc2R/oD6VHvnSmNByltV0DNyv+pkuOO1iSsBQl msQrEEczLvQfY/g== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao 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 can 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 --- kernel/workqueue.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 50baf4fe5fcf5..411e4bd105576 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5689,6 +5689,24 @@ static void unbound_wq_update_pwq(struct workqueue_s= truct *wq, int cpu) put_pwq_unlocked(old_pwq); } =20 +static int alloc_and_link_percpu_pwqs(struct workqueue_struct *wq) +{ + int cpu; + + for_each_possible_cpu(cpu) { + struct pool_workqueue **pwq_p =3D per_cpu_ptr(wq->cpu_pwq, cpu); + + *pwq_p =3D alloc_pwq(wq, cpu, NULL); + if (!*pwq_p) + return -ENOMEM; + + 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 =3D wq->flags & WQ_HIGHPRI; @@ -5701,21 +5719,8 @@ static int alloc_and_link_pwqs(struct workqueue_stru= ct *wq) goto enomem; =20 if (!(wq->flags & WQ_UNBOUND)) { - for_each_possible_cpu(cpu) { - struct pool_workqueue **pwq_p =3D per_cpu_ptr(wq->cpu_pwq, cpu); - - *pwq_p =3D alloc_pwq(wq, cpu, NULL); - if (!*pwq_p) - goto enomem; - - mutex_lock(&wq->mutex); - link_pwq(*pwq_p); - mutex_unlock(&wq->mutex); - } - return 0; - } - - if (wq->flags & __WQ_ORDERED) { + ret =3D alloc_and_link_percpu_pwqs(wq); + } else if (wq->flags & __WQ_ORDERED) { struct pool_workqueue *dfl_pwq; =20 ret =3D apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]); --=20 2.53.0-Meta