From mboxrd@z Thu Jan 1 00:00:00 1970 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 2F9883E4C9F for ; Fri, 31 Jul 2026 11:58:00 +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=1785499083; cv=none; b=pbp4rtZYowGBvNFuAsLm6GuFGFIyrb/Le+cKKvG7IxH1WZGCMl7a5hyFVPZvmKjwGNbx0zOOn1Gu/0zpKPwieP/nzDCeNOIbKhxfrPqvnt1btcjMtSYTa2GBI1JUysMWiJO6mBj+kkty41X+UcUWOLry523NNu7Q4TUF0/oVAd4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785499083; c=relaxed/simple; bh=Qw4VZnmbt957FurFjdRpCtYcTdsvBE1VOkwxR+8VlJI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C8i/bfy7evTrZkBS8VinyHI5b3ZcD3ItQschbVw98kPyw0QG0xNNIv6DMJrTNWkE0vNHvThLhYPIlOYnZZStu5s0sBj2tSUU/i0qow98uuVbF1C2krOaU+kg0SKU8e1vkrZ48Pvarl1zTZzqR6v0pgx6AQpSjJTyhi6z5+zliS4= 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=HmK9LsRE; 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="HmK9LsRE" 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=SFt5i19eclM1zEegOqGBo2n8sgiph5S6Qg+v1PM65yY=; b=HmK9LsREcu4gh5H+arKk6wQDJs M3rmgdTWkKXejZm2uwaP7wHxUyX+74QXdsdk3pGwCaLSMBLQLnHIuITFGltJX7/yF7NqiRejYdMX3 W6jD15SRSMKvgbT62UhJc8g07dsW+vfkEyhrKoNInWx992KF/1XxldzgIqPMEv7Nj99VdKWYyaog2 W3kxtP3bgd/69IX3TNduECmMaoZr9qVdtqrhr+/neeQmLpuVtqpKuwLHOmL8NMGFPNBgLhbgo3lD3 jGHYc3792NRGIZzo140cUJ8dTcWhQCLBq60sQ6nP5Xh7CDHkQQy/PYDQ2/u7wKGQcSVP1I66yQmoI JDZBv0VQ==; 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 1wplsE-009zcX-1O; Fri, 31 Jul 2026 11:57:58 +0000 From: Breno Leitao Date: Fri, 31 Jul 2026 04:57:34 -0700 Subject: [PATCH 2/6] 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: 7bit Message-Id: <20260731-wq-pool-refactor-v1-2-8eaf71cdab5f@debian.org> References: <20260731-wq-pool-refactor-v1-0-8eaf71cdab5f@debian.org> In-Reply-To: <20260731-wq-pool-refactor-v1-0-8eaf71cdab5f@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Breno Leitao , kernel-team@meta.com, marco.crivellari@suse.com X-Mailer: b4 0.16-dev-d5d98 X-Developer-Signature: v=1; a=openpgp-sha256; l=2439; i=leitao@debian.org; h=from:subject:message-id; bh=Qw4VZnmbt957FurFjdRpCtYcTdsvBE1VOkwxR+8VlJI=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqbI28mH5+wUUKSqnPT1vNMt31voXGsjjtbzTjj xwaHygY2QSJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCamyNvAAKCRA1o5Of/Hh3 bbUHEACp+4mvxYED4n+oz0R/TC9lFdBrjjw2xSrYThQ62X88xIHbZn8hlGIgfHaMVrCBKx4P0lZ DTpCPEzTsXk0CUmqMpUcXPPjVP7AeCuKF6614ZW1X8tQNqdIaqtmrXNxVjNv6CkXq0s40nekgHK 1XuyzcqUM8cLt584rPOaaJI7rUYyZVdAX9vITGvYUXVsBdEMLJ2IlRL5Z7U0Y+HQaKBI5PUCQkm n7HRpnaYM/1xqHOdU5dHx0XtqSrosJh6h6G4XQE+zkqfErPXnOVsqGSrrNBob8/+1uJe1q0EnqU jWojHG7FvROv3mg3E67ff2ch+nOvrj98micXOvMWvpcILObvHZxPYymnYfDBj1fEjzF+IapMS2t WDXczkpPRt9d3LpkG3BoD/L9G7wMbp447d00AxlBKG6YqaljjOIXZZ++W56huLgqJ5MJUCl5gob 5Sxadiuyz1IE+h9x3PoDtzpyljzQPA30NEI0KVTVH/Pu2S5oAp69JmIIdgvYSTZuBdwsqHwQPJU SPR4eWI3ikt1am9yQN9LZquiFxhNnDoM+ILqmyAmBazxJYgCTpJBH/gy+eby2kTn0QfHuLj1LKY 6JHOwzjPsXrssEfFPAeWcSuhyxstThyjexrBPozsJCmRVA93nHwEX/6R4GRbIN3nsF+XcA7VZG4 PoIs5+NekoD2HQg== 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 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 | 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