From nobody Tue Sep 9 21:31:39 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E81B30FC25 for ; Fri, 5 Sep 2025 09:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757063617; cv=none; b=AO0y5UrlQn9B5L+RwWzDjT1gB9pSq7zogEPQCgcGxxXiWQNU0AiiqBVIGKZJLhKvj5awNVBnUVYzcUSNBuWnMCLl7CycVfSj0ooxTO963X5D2Ai71bGCyzttWunQPdbUmGR9riWbaf4p0i/s3AVPZocM2eg8LWbVivZpH6YcCpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757063617; c=relaxed/simple; bh=J3wwsw1G96j/nFfeExdI2sMpIUubrqdNrNeAL9nfLMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MLY1THIlNxzAwNj4KzBc6/WwFcd30w4kdTuYtrMW/yYjoF/StDE0UbkRrN76VsEuffAmUcsEtWvXcc8R7AqYkoiQ5KBrl/OhVowogyg1ZbMpUI0q8mKCQ+/D1OO9IR8ggZLH6By50mqlwy6b+20JT3w6CGtqAjumWYYYApiQeKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Y/+L8ppb; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Y/+L8ppb" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3df15fdf0caso1532877f8f.0 for ; Fri, 05 Sep 2025 02:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757063613; x=1757668413; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eyvQ6R3XCDNf8BXEIqulKiYHytEcOGEOeWktLjCu/+I=; b=Y/+L8ppbmIOmXKw9p/6ydGDjSD2s+2fMLyoCbBq67nDC+0zETDr4qTgdsmtRkZ3w0R x1UQHUqD7NuOV3tGhu7PEBRm6WX82Gki92PoYlC5GOjKgE4mqT1D7/ssRq7CnNHVsWsj DPtbzHUEdGimKpeXmpDuevbi18f/olAeuleVF9KLmSfcoM0v+p9iGgXN3ehjntsJvxHr uZrq+UqmmdW8KWnoat9oyIUf7gdRsKg/awVeg7TxBMEmX9WsJOpZ7PoBnAeg/+5+/e+d H0rNoCuYq2//ysM3KdsTFgxRp7sXS6vQYS9jtIlN3EV/sbQRDZojiru5wREqNQ1K0EpI 9/qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757063613; x=1757668413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eyvQ6R3XCDNf8BXEIqulKiYHytEcOGEOeWktLjCu/+I=; b=CPlcusDkcUXM/FD6Sx4sXm/GVsk3gcdKgUb0xAojvxJFCQTDU5D77HL6IYXEKk6niK ZUVaSTiG2+/pZTUn6tLYVf9f+NZ5T2ifcciKV6xYtbG4aO6fnfYjAcyjiCGtKb8TLjWZ bew6DeBP8r6yOkxr33dbt4mNBAN4nBS8XFr8U5bgIkddrJ0Rn0Gj77J4+rLfjiXrtZYh OTj0N/KBr+IOCbEpBwZ6Z5LhIuEKf8VkbM7lZyXMPshyIQMd7nRovAG4NvDNXeAu8mdo ol53ZflcDstFEy7lyiUVKt3TXZlJj6nGSqtUfj0Vqp186gzaCL2jLxGCzIK6AcPxLzG4 CpXA== X-Gm-Message-State: AOJu0YxCofVtCZSMOrYZ1pQcHGdWEwbPyQV7PEA9N/iQ6yN/DIezJ8DY 9cFcXyDZwOm5xuoUacuGJKLV+JRLthbvSePspnS6GjCF8miRz2VCV/QUsSgwDLh+Z9IVmKgKkhj iVrGUViE= X-Gm-Gg: ASbGncuppKWyHyuODaskESpCJiq+wjpJlQkCJ1e+/QVdXPpwETYej9TaZFvwMg6nGMC SkXtIK8YozDEbfjjA1RfVGCZVJlK/N7t9O4omXgeXdmvyczkBIlJZtVAgmH5AoaKcVfLiveoJhA cO4h6cHWYJ7XdusKPhbsz0hqcrgeRvdudfYFGKrxvJXtJRlq/KG9Ib3u9Fem+zP6P+LTmsCtOn8 wzWn0QiW64i26sfEpri388svEtIT5xQ1CLhrQKIuUUMwH5hygXKJj3pF8CuBtxGfxXzogd6fuoD IPL2brO4TpVHRo2Y72pLLkVaGjmn7O/aVZcgCQXY09Q87ywr77QIjfzJVxJBPw7ioMm+u45LhiA 56BF3aXqEJvKIag7TS7cdiMQMKahAhk1ZsqxKiiLHtfNiBstBAp5aKCEgcg== X-Google-Smtp-Source: AGHT+IE88+5Y2AKOXc8JHubbgaGZ6Smb2LWsmd0BVmStEEthfRNWZwWMQXbUQ20cKjiwD76bBKDFQA== X-Received: by 2002:a05:6000:2509:b0:3e2:e079:86cf with SMTP id ffacd0b85a97d-3e2e0799704mr2577219f8f.36.1757063613387; Fri, 05 Sep 2025 02:13:33 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e4e2c3fe44sm167477f8f.0.2025.09.05.02.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 02:13:32 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko Subject: [PATCH 1/3] workqueue: replace use of system_unbound_wq with system_dfl_wq Date: Fri, 5 Sep 2025 11:13:23 +0200 Message-ID: <20250905091325.112168-2-marco.crivellari@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250905091325.112168-1-marco.crivellari@suse.com> References: <20250905091325.112168-1-marco.crivellari@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND. This lack of consistentcy cannot be addressed without refactoring the API. system_unbound_wq should be the default workqueue so as not to enforce locality constraints for random work whenever it's not required. Adding system_dfl_wq to encourage its use when unbound work should be used. queue_work() / queue_delayed_work() / mod_delayed_work() will now use the new unbound wq: whether the user still use the old wq a warn will be printed along with a wq redirect to the new one. The old system_unbound_wq will be kept for a few release cycles. Suggested-by: Tejun Heo Signed-off-by: Marco Crivellari --- include/linux/workqueue.h | 4 ++-- kernel/workqueue.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index f19072605faa..0e14d78fb970 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -779,8 +779,8 @@ extern void __warn_flushing_systemwide_wq(void) _wq =3D=3D system_highpri_wq) || \ (__builtin_constant_p(_wq =3D=3D system_long_wq) && \ _wq =3D=3D system_long_wq) || \ - (__builtin_constant_p(_wq =3D=3D system_unbound_wq) && \ - _wq =3D=3D system_unbound_wq) || \ + (__builtin_constant_p(_wq =3D=3D system_dfl_wq) && \ + _wq =3D=3D system_dfl_wq) || \ (__builtin_constant_p(_wq =3D=3D system_freezable_wq) && \ _wq =3D=3D system_freezable_wq) || \ (__builtin_constant_p(_wq =3D=3D system_power_efficient_wq) && \ diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 62f020050de1..687285701655 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2936,7 +2936,7 @@ static void idle_worker_timeout(struct timer_list *t) raw_spin_unlock_irq(&pool->lock); =20 if (do_cull) - queue_work(system_unbound_wq, &pool->idle_cull_work); + queue_work(system_dfl_wq, &pool->idle_cull_work); } =20 /** --=20 2.51.0 From nobody Tue Sep 9 21:31:39 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7246130507F for ; Fri, 5 Sep 2025 09:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757063619; cv=none; b=G/aP5/K3osTjnXfjDZzaJh1MNHRoVPeLlcsO3UaJ9agMAw6ovtUGB08F1LfOlE3rjVb4Cxgl/r/fdTK1+5IUHW/49zhb9ZY0/IjHQyaaKAYZGSl5rzsb9fj7VBZcMrMbLEBFQjnS1oKT6kkBHoRcsWaNCGcyUFhSBcZxYfmJBkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757063619; c=relaxed/simple; bh=m0nF1hgIpqmzkV/Wes5siML6Pi7yBWHGWMcNN12UAnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mv0XaChVmCOOljTwTeUlKlZVd25nNVllyXao/PHvEFgG4F45q2l3yV5YZhz6CtZMoiG9R/6xw0Ixju37nlt6T0JU8rLl8Cvj+Mq+Uux6mQrS+EaE+U+3AnP+E5xGggyMcE8sl0wP3OCv9zz3LDQtg9bYo2nY8L7ZIRvJU+QK6iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=HZQwQvO4; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="HZQwQvO4" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3e249a4d605so1208031f8f.3 for ; Fri, 05 Sep 2025 02:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757063614; x=1757668414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sR2xqRJLV5wcc1BaVz4hew+xeHnmtpMPVb/CKMgOX6U=; b=HZQwQvO4rWnCy2YRplBTl0l7huY1XjMpawWgcxKxS9AlFe+ej47sl59Du66tyX38DS PBsItGjoL9uaSL78cAUJuL572ootuQnSlsRB2ELFBj2GoujpNyoXs7sc1xnaE3luE6y+ 0x0/NKB6ywT5oAjtu+VbkqQlhIv1SVncPL3IRTzxTXbaImrNzWIkEeNRV2uRxDM3mnP+ qk5lDQUA+asbnCi9VJYmZ2jIsrBI2CEtdtr3UVQDx2AO1M2oo+nof2f6U0mbrW488f3v 4mkOtoUIL1GsFIkwg8j5m2GkA2RRG1PYRFB5rHxWukjUkCzEl5Jw9yQpIIM5sG0uqZcx L5+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757063614; x=1757668414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sR2xqRJLV5wcc1BaVz4hew+xeHnmtpMPVb/CKMgOX6U=; b=Uqo7iucoNZAYjC2JhYUFzrEpyAFb5MWaLxPDtwu2t5z87zaEEJ/rP2bVnxuY1XtnfX QwxgRvnyl7KwHoyE6SIsF74w98dxHjtZ371h+Mau2HY+MZ3NryOwG81ZkZ7zFpSL7Squ XMbN2AcNw61X8ZlRWa7gGtUJ/Zy4Iac4ISF+95ls9iwZgSPc0W8kIOsMBoOwacbQRQnW 5qNqM+nVCrr5iSD4x7YfZTHLtLGu/onufK0IWF1q5MJNcosI+3JbPMmGGlxqD/OT41Vs jDOnRCW3x8qa6xUrksft3364VhAYv3Bdi0KDwOlCiG07+OwFAp3JLzRJgz/7leupR7pp e6BA== X-Gm-Message-State: AOJu0YwlYauA+5nyvtNjzdp6hNosscmaVEUQM8iLe9xc3bT02PiCqEyN q0P/vd4rh6CsrgOwG7aR3RAIC+ngECSRUkpKwBGgZBjulaZBE06oXSXsAh/hZRSZcxpdKAbx9uz cQZoliW8= X-Gm-Gg: ASbGncsMRVavX86DLAhzyweHhQfvnMf24+hzphc6NG6jpKXKs1UEDMhkuw/NxJpzIc5 ZE/vOhoLdXS2+X/pc/8Q7rtEYBnQHFuZ632+puSdxcz6WycLIRZGOkSe1+YAyN/dSgEVA4OvYfJ M02w2nvW7j6sG9bvwHSE2x8xiG+1WL10lwrTlydMWeLCD4EhQUsJxQR1tMjvB0CSE555fwpSGC/ s61g5NMjIp/lkX0HzOq+iuFWhTGlY8e6hu7LTTLV7G8MiYQRSPk/MbeeQpnXS7xLOm4DVvuNVGs TIozRbda1ID32zrr6KlmaGT9M4P2W6p4/E5pDrQ9kvuFXlgVCQWgemOmckZOKuXZH5kgS46R8fR ZoPT6RToZw3aOd8cPrlvlLkeTwIvjE+2YPZrPXwZFeujm2NIjghrHMnen7A== X-Google-Smtp-Source: AGHT+IEu8cEB81VVj3TQ5rAeg3WZ9lkLlX8//hH2/Xy1UYV2yyb47JyuAh8SbhYq2wWfAc8Y6I0tRQ== X-Received: by 2002:a5d:5f50:0:b0:3b7:8da6:1bb4 with SMTP id ffacd0b85a97d-3d1df53be89mr16859127f8f.58.1757063614271; Fri, 05 Sep 2025 02:13:34 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e4e2c3fe44sm167477f8f.0.2025.09.05.02.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 02:13:33 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko Subject: [PATCH 2/3] workqueue: replace use of system_wq with system_percpu_wq Date: Fri, 5 Sep 2025 11:13:24 +0200 Message-ID: <20250905091325.112168-3-marco.crivellari@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250905091325.112168-1-marco.crivellari@suse.com> References: <20250905091325.112168-1-marco.crivellari@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND. This lack of consistentcy cannot be addressed without refactoring the API. system_wq is a per-CPU worqueue, yet nothing in its name tells about that CPU affinity constraint, which is very often not required by users. Make it clear by adding a system_percpu_wq. queue_work() / queue_delayed_work() mod_delayed_work() will now use the new per-cpu wq: whether the user still stick on the old name a warn will be printed along a wq redirect to the new one. This patch add the new system_percpu_wq except for mm, fs and net subsystem, whom are handled in separated patches. The old wq will be kept for a few release cylces. Suggested-by: Tejun Heo Signed-off-by: Marco Crivellari --- include/linux/workqueue.h | 22 +++++++++++----------- kernel/workqueue.c | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 0e14d78fb970..542529d3b41b 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -433,10 +433,10 @@ enum wq_consts { * short queue flush time. Don't queue works which can run for too * long. * - * system_highpri_wq is similar to system_wq but for work items which + * system_highpri_wq is similar to system_percpu_wq but for work items whi= ch * require WQ_HIGHPRI. * - * system_long_wq is similar to system_wq but may host long running + * system_long_wq is similar to system_percpu_wq but may host long running * works. Queue flushing might take relatively long. * * system_dfl_wq is unbound workqueue. Workers are not bound to @@ -444,13 +444,13 @@ enum wq_consts { * executed immediately as long as max_active limit is not reached and * resources are available. * - * system_freezable_wq is equivalent to system_wq except that it's + * system_freezable_wq is equivalent to system_percpu_wq except that it's * freezable. * * *_power_efficient_wq are inclined towards saving power and converted * into WQ_UNBOUND variants if 'wq_power_efficient' is enabled; otherwise, * they are same as their non-power-efficient counterparts - e.g. - * system_power_efficient_wq is identical to system_wq if + * system_power_efficient_wq is identical to system_percpu_wq if * 'wq_power_efficient' is disabled. See WQ_POWER_EFFICIENT for more info. * * system_bh[_highpri]_wq are convenience interface to softirq. BH work it= ems @@ -704,7 +704,7 @@ static inline bool mod_delayed_work(struct workqueue_st= ruct *wq, */ static inline bool schedule_work_on(int cpu, struct work_struct *work) { - return queue_work_on(cpu, system_wq, work); + return queue_work_on(cpu, system_percpu_wq, work); } =20 /** @@ -723,7 +723,7 @@ static inline bool schedule_work_on(int cpu, struct wor= k_struct *work) */ static inline bool schedule_work(struct work_struct *work) { - return queue_work(system_wq, work); + return queue_work(system_percpu_wq, work); } =20 /** @@ -766,15 +766,15 @@ extern void __warn_flushing_systemwide_wq(void) #define flush_scheduled_work() \ ({ \ __warn_flushing_systemwide_wq(); \ - __flush_workqueue(system_wq); \ + __flush_workqueue(system_percpu_wq); \ }) =20 #define flush_workqueue(wq) \ ({ \ struct workqueue_struct *_wq =3D (wq); \ \ - if ((__builtin_constant_p(_wq =3D=3D system_wq) && \ - _wq =3D=3D system_wq) || \ + if ((__builtin_constant_p(_wq =3D=3D system_percpu_wq) && \ + _wq =3D=3D system_percpu_wq) || \ (__builtin_constant_p(_wq =3D=3D system_highpri_wq) && \ _wq =3D=3D system_highpri_wq) || \ (__builtin_constant_p(_wq =3D=3D system_long_wq) && \ @@ -803,7 +803,7 @@ extern void __warn_flushing_systemwide_wq(void) static inline bool schedule_delayed_work_on(int cpu, struct delayed_work *= dwork, unsigned long delay) { - return queue_delayed_work_on(cpu, system_wq, dwork, delay); + return queue_delayed_work_on(cpu, system_percpu_wq, dwork, delay); } =20 /** @@ -817,7 +817,7 @@ static inline bool schedule_delayed_work_on(int cpu, st= ruct delayed_work *dwork, static inline bool schedule_delayed_work(struct delayed_work *dwork, unsigned long delay) { - return queue_delayed_work(system_wq, dwork, delay); + return queue_delayed_work(system_percpu_wq, dwork, delay); } =20 #ifndef CONFIG_SMP diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 687285701655..89839eebb359 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -7660,7 +7660,7 @@ static int wq_watchdog_param_set_thresh(const char *v= al, if (ret) return ret; =20 - if (system_wq) + if (system_percpu_wq) wq_watchdog_set_thresh(thresh); else wq_watchdog_thresh =3D thresh; --=20 2.51.0 From nobody Tue Sep 9 21:31:39 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74A9130FC3F for ; Fri, 5 Sep 2025 09:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757063619; cv=none; b=Q80qqr7OnRWiYnIKGuy1tgO5ENcd/qhpyFTg9Y1XP1tlkgUhsvKkapjDaY1thwPx1B148x0QlkYOgnBWN7wt5lj4FaYlWPOCHaarf6xyqOclLv3uu2zHwtztem3RlXNLkR7HAp0Fcs5MuExNNKzCfuiD47ce6HH8TiLxFTYehaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757063619; c=relaxed/simple; bh=rcxNftRyzyKRzD1KQZIlmsH18h9h4Fz0l2lqKze0U5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M2vYthF7MYZidlxbEV5HTqa/lEqUZRUySWbgQ++X+hz4F092XZsP0ZBmiLQOJrlBmmS0UYk/B2h6Pgbga3H2ZQh0yPKowBZr000Cpef2TM4scg12Rrnr5WPtVsXRrGLbz+UIcGDHu1/Mj7hGu4CMbUW/MS4HoE4huqtoh37VVSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Js014Lja; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Js014Lja" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-45b8b2712d8so17499855e9.3 for ; Fri, 05 Sep 2025 02:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757063615; x=1757668415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z3io79lXNPai/LjSUe9hCwspF7/+HpxLi4SOZ36MG78=; b=Js014LjaY6huhU7PaIpG/ZhRU6bITkUs+au88Bn5XB/KflrTIb9sVzo9zfEYrxt/iK ImmiSUsZcsee4FaMeFBV+IwlDk7OxOD5PdANvkuwWn22Z/g7aTL7JZ3J+1jfU7sl1W5g jVCa0bkgvVKtMcW64ZATeBQEOhR94/RXYONIzHoPKWacI+Q/fHrW9P52nBYCeoupF4oo hXzJpsmOwoTb15lHAXMuvsm968vr5I7OBntB61Z9evbPslKM6wzyzqCZTX1/Y39TAhpG Z4SGZ9jbkdM4CLepSEmGllWT9B3OvTyLlCL6pJpr7g0c6lUVG5Um3R9ZxySiHNJhDWB9 YzWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757063615; x=1757668415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z3io79lXNPai/LjSUe9hCwspF7/+HpxLi4SOZ36MG78=; b=agSqYOk+/71mB3sM9NEtHy+iJxlcaGzcSaJaVM7UUKGjIt1zwBCZSPZPNIHgVPnOKT HKEK03Z6htPEOHBgGiyzUGldoYj82bX6PcsI3kBXZvFCv9HnZ6u2upxGS92WMeaWymEq MN7hOHShZEUG2UivvYVC7zjILNNzznr9l5zW3BXGgwcPF6u+Qd9cEasLhXiRIRnrmjB1 BOy6BnX8oTZnTy/NPURElB1nd1mxMWTy25Gp8TXGxxH9DbRvW2eIt4jl1f2sryllvz4e jCPQUaNQy+2OC0a6R87h1FyCo2E6CVyoHpvRgm2bVsrL3T5ckVA/bkFG4xBwrkz1M0xk 5DEg== X-Gm-Message-State: AOJu0YxYjGstEu5W3wnsX/5kZh+XKLnQm7KAN83ttKfX+KdkDJ9Y8aUa edgTQCUU0OLTBgASFocTKDIAwSbP7dN2fFJnHYRyy5DXBgv2SUnSYCWpZh0T1DPvCNdVordTuZU b2bkMiHM= X-Gm-Gg: ASbGnct8KwmaL4CCQM2QR3Sj+DKz1XSNT+5yDgqz3rGAuqMPBIuQztYNjAOErcnE+/W 3TpIpE38lPqH2TQgoMTA6eaqa88oUm/rbAEnk8lZ++/G7gRGnCJgdy50btfT/nnGhGFdjhdnivG v0/Qvp3rmklpFXQtVD7r7HKyCheyQG0C6wUqlfBOJjbwTbI2PROpG0RCU/30G8FxoFfDTv/29Mt 7YYtIcF85o7y0g31ItNlVOpB9hnvoKQnHB5QZQVVp8WU+w/332u+iHJ34mlU/mcBbKkqmJwknd5 kh2xgW1PNaR+LB/kWRPleI3ZT8Wnz2mWBzAGqCzGLYur60cpExw2fiP5QCqEvwZD7z9Qd5xz8XB eN79PEIoTUyvWAj3oVgrlCfKggcasY0At2hxFiCZSkLNgMdg= X-Google-Smtp-Source: AGHT+IH6zMRnskyEZE33ZiL3c38eS7NFBPeRZlf8prmvM+d41FKQ2hbJMSl1mRuTfLjCWbVh8q+U5g== X-Received: by 2002:a05:6000:2287:b0:3cd:edee:c7f8 with SMTP id ffacd0b85a97d-3d1dfcfbc70mr16146016f8f.29.1757063615202; Fri, 05 Sep 2025 02:13:35 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e4e2c3fe44sm167477f8f.0.2025.09.05.02.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 02:13:34 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko Subject: [PATCH 3/3] workqueue: WQ_PERCPU added to alloc_workqueue users Date: Fri, 5 Sep 2025 11:13:25 +0200 Message-ID: <20250905091325.112168-4-marco.crivellari@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250905091325.112168-1-marco.crivellari@suse.com> References: <20250905091325.112168-1-marco.crivellari@suse.com> 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 Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND. This lack of consistentcy cannot be addressed without refactoring the API. alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND. This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they=E2=80=99re needed= and reducing noise when CPUs are isolated. This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they=E2=80=99re needed= and reducing noise when CPUs are isolated. This patch adds a new WQ_PERCPU flag to explicitly request the use of the per-CPU behavior. Both flags coexist for one release cycle to allow callers to transition their calls. Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default. With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn=E2=80=99t explicitly specify WQ_UNB= OUND must now use WQ_PERCPU. All existing users have been updated accordingly. Suggested-by: Tejun Heo Signed-off-by: Marco Crivellari --- include/linux/workqueue.h | 4 ++-- kernel/workqueue.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 542529d3b41b..4db59f886656 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -409,7 +409,7 @@ enum wq_flags { __WQ_LEGACY =3D 1 << 18, /* internal: create*_workqueue() */ =20 /* BH wq only allows the following flags */ - __WQ_BH_ALLOWS =3D WQ_BH | WQ_HIGHPRI, + __WQ_BH_ALLOWS =3D WQ_BH | WQ_HIGHPRI | WQ_PERCPU, }; =20 enum wq_consts { @@ -568,7 +568,7 @@ alloc_workqueue_lockdep_map(const char *fmt, unsigned i= nt flags, int max_active, alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args) =20 #define create_workqueue(name) \ - alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, 1, (name)) + alloc_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_PERCPU, 1, (name)) #define create_freezable_workqueue(name) \ alloc_workqueue("%s", __WQ_LEGACY | WQ_FREEZABLE | WQ_UNBOUND | \ WQ_MEM_RECLAIM, 1, (name)) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 89839eebb359..d33ca6acc5a5 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -7819,22 +7819,23 @@ void __init workqueue_init_early(void) ordered_wq_attrs[i] =3D attrs; } =20 - system_wq =3D alloc_workqueue("events", 0, 0); - system_percpu_wq =3D alloc_workqueue("events", 0, 0); - system_highpri_wq =3D alloc_workqueue("events_highpri", WQ_HIGHPRI, 0); - system_long_wq =3D alloc_workqueue("events_long", 0, 0); + system_wq =3D alloc_workqueue("events", WQ_PERCPU, 0); + system_percpu_wq =3D alloc_workqueue("events", WQ_PERCPU, 0); + system_highpri_wq =3D alloc_workqueue("events_highpri", + WQ_HIGHPRI | WQ_PERCPU, 0); + system_long_wq =3D alloc_workqueue("events_long", WQ_PERCPU, 0); system_unbound_wq =3D alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MA= X_ACTIVE); system_dfl_wq =3D alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_AC= TIVE); system_freezable_wq =3D alloc_workqueue("events_freezable", - WQ_FREEZABLE, 0); + WQ_FREEZABLE | WQ_PERCPU, 0); system_power_efficient_wq =3D alloc_workqueue("events_power_efficient", WQ_POWER_EFFICIENT, 0); system_freezable_power_efficient_wq =3D alloc_workqueue("events_freezable= _pwr_efficient", - WQ_FREEZABLE | WQ_POWER_EFFICIENT, - 0); - system_bh_wq =3D alloc_workqueue("events_bh", WQ_BH, 0); + WQ_FREEZABLE | WQ_POWER_EFFICIENT, 0); + system_bh_wq =3D alloc_workqueue("events_bh", WQ_BH | WQ_PERCPU, 0); system_bh_highpri_wq =3D alloc_workqueue("events_bh_highpri", - WQ_BH | WQ_HIGHPRI, 0); + WQ_BH | WQ_HIGHPRI | WQ_PERCPU, 0); + BUG_ON(!system_wq || !system_percpu_wq || !system_highpri_wq || !system_l= ong_wq || !system_unbound_wq || !system_dfl_wq || !system_freezable_wq || !system_power_efficient_wq || --=20 2.51.0