From nobody Sat Oct 4 14:36:17 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 6001F24C077 for ; Fri, 15 Aug 2025 09:48:51 +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=1755251333; cv=none; b=DGM2yE1FjC7/TAF15079HC5UM5a/Mg+epxpOLAxDDrscBu1f7HnioL0NXp+aOysrlBV6NKME/sp75psDZ8GD/apOnbzS5dW/ZXA0fBK5VAgxeJoaoc9asxVJK6kZ6KCui80fa/CiMJbIy28FRMXS3WxDGZhhgjnjAKff8rOMe1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755251333; c=relaxed/simple; bh=ApXFijJ9ifitsmoPMtx4eROfJLE/kj9jV/ZIIu7MUGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SGGN2RNop+eqYv9nxBIjTiJDzTfiGX9qPb26IRJyGN7+G49cDMuL+fyrt2qRpGHRQbialFT+53NMxJRhWmQAZOMgme820FnrumxPC32dw6PaaYz8qvhIHsV9WqRGxQRI2KkbSLA6nuamnDw8YtssLlUT+8IjIt56D/sP9ruqDCM= 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=VUCpQuuc; 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="VUCpQuuc" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3b9df0bffc3so1052663f8f.1 for ; Fri, 15 Aug 2025 02:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1755251329; x=1755856129; 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=8qTDwqJU1nmGKtl+X+8GsqFW5lzvu8oH1GJ2AavRkMc=; b=VUCpQuucv+tAzcTDKfjlXObqmJkjMuKwACW5SOOtqFhuxHW5dNV40AawiccX4Se+9c pQU6s3ErhIX/oMJ1htlw5nEmapBZPalbQeo4I7zXyDX2w2/uo2ad0oYgb2CtJSPo5XLC cGawniHl+GiwLtAsYZN0kKDrJHxUlzx7pQerSX8kfLbo+E5NfrYA9vPHbHh/WkW4fLB4 Ij1g8Mlnn4CCi0tewhYt7uCB0ht93Dm6GXqEj/Lervurf0Xz6Hc1gCYyJ21h/6fKgpVB R1qql3m62Iqdxzl/dT8wh+fNAOKLN9zxMGQGO/2OXadEZaPLLmm9wXQ10UBjtSXTe4b2 hSbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755251329; x=1755856129; 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=8qTDwqJU1nmGKtl+X+8GsqFW5lzvu8oH1GJ2AavRkMc=; b=CwagWwKNNnVaxisTB5St0EKI4+fizLqu5G/CHxo0ZzgIxMwJS2Mc1UveAvFtzl/iuc 3GJkBbjq3g0zoyXoewCQbcrwa5xk5iU55jeo9MPvIyzuTXYM2lP7IzgGAmEvVX/rHh1b orLqROD2o0FhwTnyDgFGZT45Fwx0zSelGDgtXIJINvffkIUAiPduEWoJy+vLOu7qAX9Z KdnubLBfoEgcNio2nLc5UwQDpihf+nzIY8iHlvComgpWDk8rk4jiorBB5lg+rUNJXxQp wBbEXXG+KoMF5hmDZQzI5zzuZz6ieTuEtNXEshWT6YOIcZPonQvoH62YkWeadGwMABa3 KiPA== X-Gm-Message-State: AOJu0YwPNjXJItDMJArUZkY1DyRZGsDg6KSC1371IKXMLffFyPVmjVA8 0y2z1nmINHojQmDRnyXhXQ1ks7Q5zL01B4GYgDwK4poGk/x9HwYyiy0iO0wYk7kDL6PL+kNppW9 ra1yd X-Gm-Gg: ASbGncuJubLo7ORxmsFpb4T27Qi0zhIWpr+V/Qvjpxh7ocwAyVV+VwwRaAtPASsMoVl H1jJfYK+54v8eqG+0A+rEwZ0cTAI1pHo7yNkZuZ3RLSCENn2Of3waNGo8/tk9IN6/nKySmVTq1X Gx7Ni5G8IOzl2rIwys6EqFOU0tW3keKMVwUQ2xNAR+a11MqYx+LGLy/YxscSnayLXt253cfTIBY hy/unR0nP89kOqa5mk7wPZ/u+oa51Pa8FmRWvIWfaxmxPJYnjQ4s26xOvMObLfz82Nc25S5o0op BjNplVXP94V1zy4R537jaGC1Q7sMtwK8Zyq7pZMfkZDmGeRmU5f77X2eNEOZfe31pNEpln/6BzG FN/ng0MvMOZ3lrAFwv1MVHGoyPqBR5A8ne2ANpYUAtxSNZQ== X-Google-Smtp-Source: AGHT+IHGexusHTIUA8LXz2AQhtbDX50PiccTmNsoRb+YSF+2WHeoBBr1PwoviEWMoQI3pnrSN7hHPA== X-Received: by 2002:a05:6000:430c:b0:3b7:8984:5134 with SMTP id ffacd0b85a97d-3bb66a3b2ddmr1065862f8f.16.1755251329463; Fri, 15 Aug 2025 02:48:49 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3bb64758441sm1313811f8f.13.2025.08.15.02.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Aug 2025 02:48:49 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Thomas Gleixner , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko , Andrew Morton Subject: [PATCH 1/2] Workqueue: mm: replace use of system_wq with system_percpu_wq Date: Fri, 15 Aug 2025 11:48:42 +0200 Message-ID: <20250815094843.55377-2-marco.crivellari@suse.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250815094843.55377-1-marco.crivellari@suse.com> References: <20250815094843.55377-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 to all the mm subsystem. The old wq will be kept for a few release cylces. Suggested-by: Tejun Heo Signed-off-by: Marco Crivellari --- mm/backing-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 783904d8c5ef..784605103202 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -966,7 +966,7 @@ static int __init cgwb_init(void) { /* * There can be many concurrent release work items overwhelming - * system_wq. Put them in a separate wq and limit concurrency. + * system_percpu_wq. Put them in a separate wq and limit concurrency. * There's no point in executing many of these in parallel. */ cgwb_release_wq =3D alloc_workqueue("cgwb_release", 0, 1); --=20 2.50.1 From nobody Sat Oct 4 14:36:17 2025 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 88DD927A11E for ; Fri, 15 Aug 2025 09:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755251334; cv=none; b=JevbIhvlc+yrv16BVP6ehXhWSdpSWEHRb/J+FmQ/UnYx9XtHDhrzrOvj55pZSnqLaaIM5Pe9yQvaKIqFVJL9fxee8WGHhPYZ+XPN+IMp/2kP0+zBIswDpGRhaLOpfzEmzMlfklzvITk7A38qo1eDLwoWBHh2tbhwUcgNuSKKF6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755251334; c=relaxed/simple; bh=vpMtMp//b0b8De85qCC3JA1iuWr7ernuXqJ4p27ur4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Eu6U2f48ggADh9Ma7AVf/Ydpr3evfdkwQevrjzlJQ4uJwxqGCRsP6FBGanuTSei/1v+5O4uruONLK+x9RCTmIHuPfFl0f+WTTT+PNelXbzL5s+30bZamDqIMmZ7t8UTeOncXTokjLxlkXzL0xwOkQwqSrSG3tFBv3LA3bT/0BW8= 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=eVeWcDYC; arc=none smtp.client-ip=209.85.221.47 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="eVeWcDYC" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3b9df0bffc3so1052674f8f.1 for ; Fri, 15 Aug 2025 02:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1755251331; x=1755856131; 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=mR5NkOjuGJ4ft4FhURCOTQDzGIwDt9G1P6tv9Keuhok=; b=eVeWcDYC6VVsXd8aWEN/h4e1s5WjC/Zpj3yTlAH9IKnWpBloxS8qdm3BQ0ib2Hy2j/ 3LxUzedoZvgu1Ky2CcU2rl1OKpoB5/qq6LqZERXyPy9hG1cSgIEomQN7rfksYOjQHm/J iIbvzqhoVdHID4UzPZRX2MomyJfWAV3LsGwDqXM5AkGBClEsEhZ7KIHW1bsr94nLdrOq IKfIa/pV6CUK6VGiitQEGJntHVuRZExnDJxAMrTKWztDtozP25ev5cnQnA19h+c5r5Gy U+lyRJbaMYiNoysZ6WpcgMW68AZOX6mws5gTmk2aQeiCXlwzoyx1FMtgRafFDL9X74Va NRRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755251331; x=1755856131; 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=mR5NkOjuGJ4ft4FhURCOTQDzGIwDt9G1P6tv9Keuhok=; b=hwiwvAw1wfdf7yjLxkFErYG79B085CLrar87DJ8d/TLkqnFnyHRmGiG2Q3rTJMK4gg 7+n8ibmlMHNopAL8jHCU+0WxNc0OX/1Vq4tJaSJ1yIx4B62Ws6v9xdYtVVRjZQztehYY HQHpueAhaj4iCIfJM1FgjVloXcx2Id/oe/okem6qsX9WmBEZ0zimOAZRjZVUqCCB5QLr Nj8KwzISyDJ8hkJRQdfCWfQSCK/R+OkOXUldyqYU7riJDg/LPIUfDaT2RDQEPAAZNpbA 7FJuKZXZBJub9VHSC3f6nUgkyMh9/frz0Bt2qx6WEwHlo9ffa3d1k/+oZwEHnQJENQ2X W18g== X-Gm-Message-State: AOJu0Yz+ipRmdmeZjeGK+AmQXf6WvgGwBVmAEUfXBJi+OmGG2J3/G90f ISAKyMhRkQIFauTbJJAfMQZJWzI7k62TNCIS7L8KkBrR8Ifrc8mcE50DGKdOvybwLVfALEj2i7i atc1g X-Gm-Gg: ASbGncuzyLNv9DzlnyIt9SbxOP1iU0lGhMZ1YxrzT3+7mSSy2/DTRa7WQnekqfDgW3y Xo4cazOOPFZPqMWXXbhsbXlUyvz3r1Y+OJSufWEmVVYx7Z15tcmKVt/vyQbUsIWNSnblIGpvYcq Zt7ZMpq3jDxpqxnlMtGFCa0FoOVp4iu0TIUU3ygGiDoNExOelnPg0gp2fq25afGBTFOf4IRGkCS Lr49XerIkjW9axToPE26NM7xxIKP1RdaKQ3lcXozynV2J3c4b6GR8Gcp/MiuJ1hrUpSqaMUriJ7 C8q2eX4ImErJzsYn70vCf/8sean1MkLeySLtrb2gBGT88/AHXnSVRLPb3RpKantHBhR+EIngamU UM/zmjXrVKxyb+iMnWCIEjcbOSTLRc14N1x4GmYKSWtJy4g== X-Google-Smtp-Source: AGHT+IGfwwmPP0cJ8NtKTDTzNgTk6p0HWcl0j/eyi7s50c7lb/H8mjXhYq/x38gt6gyqORGglfALjQ== X-Received: by 2002:a05:6000:250e:b0:3b7:9b4d:70e9 with SMTP id ffacd0b85a97d-3bb68c037a2mr1039377f8f.43.1755251330644; Fri, 15 Aug 2025 02:48:50 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3bb64758441sm1313811f8f.13.2025.08.15.02.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Aug 2025 02:48:50 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Thomas Gleixner , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko , Andrew Morton Subject: [PATCH 2/2] Workqueue: mm: WQ_PERCPU added to alloc_workqueue users Date: Fri, 15 Aug 2025 11:48:43 +0200 Message-ID: <20250815094843.55377-3-marco.crivellari@suse.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250815094843.55377-1-marco.crivellari@suse.com> References: <20250815094843.55377-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 all the mm subsystem users 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 --- mm/backing-dev.c | 2 +- mm/slub.c | 3 ++- mm/vmstat.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 784605103202..98fb7beddd4c 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -969,7 +969,7 @@ static int __init cgwb_init(void) * system_percpu_wq. Put them in a separate wq and limit concurrency. * There's no point in executing many of these in parallel. */ - cgwb_release_wq =3D alloc_workqueue("cgwb_release", 0, 1); + cgwb_release_wq =3D alloc_workqueue("cgwb_release", WQ_PERCPU, 1); if (!cgwb_release_wq) return -ENOMEM; =20 diff --git a/mm/slub.c b/mm/slub.c index b46f87662e71..cac9d5d7c924 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -6364,7 +6364,8 @@ void __init kmem_cache_init(void) void __init kmem_cache_init_late(void) { #ifndef CONFIG_SLUB_TINY - flushwq =3D alloc_workqueue("slub_flushwq", WQ_MEM_RECLAIM, 0); + flushwq =3D alloc_workqueue("slub_flushwq", WQ_MEM_RECLAIM | WQ_PERCPU, + 0); WARN_ON(!flushwq); #endif } diff --git a/mm/vmstat.c b/mm/vmstat.c index 4c268ce39ff2..57bf76b1d9d4 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -2244,7 +2244,8 @@ void __init init_mm_internals(void) { int ret __maybe_unused; =20 - mm_percpu_wq =3D alloc_workqueue("mm_percpu_wq", WQ_MEM_RECLAIM, 0); + mm_percpu_wq =3D alloc_workqueue("mm_percpu_wq", + WQ_MEM_RECLAIM | WQ_PERCPU, 0); =20 #ifdef CONFIG_SMP ret =3D cpuhp_setup_state_nocalls(CPUHP_MM_VMSTAT_DEAD, "mm/vmstat:dead", --=20 2.50.1