From patchwork Wed Dec 27 14:51:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 183484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1475088dyb; Wed, 27 Dec 2023 06:50:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnIeqX1OQ0haq4ckaRa5dQ0QnBz4PgPWZaUU8jD7z6FAggt/RlWkQ7fmQAPooAaWZ3fF19 X-Received: by 2002:aa7:8252:0:b0:6d9:8453:1b55 with SMTP id e18-20020aa78252000000b006d984531b55mr3282982pfn.0.1703688616063; Wed, 27 Dec 2023 06:50:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703688616; cv=none; d=google.com; s=arc-20160816; b=vjT6CnKSR2LMcnUGO9us8JByNKu0lYFkQvND3YwWsjG4bMX7m57Zp5q6LYAsZ9UrN8 AJ+MUgYGduVLUNS1APY9v7slBEkzjD2O+AgtS5qnGcTfBmRliZ3qEjAZJXB3fxOudpGo PJwtzzUeYeaYYgIa83qpPL5Zq7xxdaIzvutuk5mZs0h2HHmw7VSU/5KSppC/DXOlWw8I ajqSylp6Lr00yNgJ+mYRn1D3yS42OYSWsTi0l7gD7PB4J3j0OmnkkZ+PwkM2S82mq5zS CuyfyZOifLRHk5K7BEhSQ6pdCrLe4k5RFztsRaJxX53nFrEvOx6nHNEKIcnc0/O3r+vY q/Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bZIdcLBe5AtoEgMrZW8B5XtJiAwQZuHkmbazdIfOtJ0=; fh=nCHpoOmZzPFKkYnjB6DcQplzE6zNssY94haDgAefa7c=; b=Z/9xJq3FcZvSBQ5UXiB7XcyGr+lSJxnFReV8X1rmADkqcPxk6D1X7NsZwhePxNrkET LbLKOvTUm71CCXL9ysfqZPCcUCGNzg9+Ryq9XerAxF6YY01VKph+wxVwfyOHbIeB0Wjy 2X30BYtHvp+LQ1T3Iu3AyxaaG5opEyg8coLG+f2twYr0bUyWC/u+eOrPlZAA2qzCwEZU EqSUhT6415YZW+BkiZH59+alXit7se0Vt1b/Xfet43JMaZC4Qjwpup2Y+ApnSSzBdJyU lMYO5OhgLF5XupwT4nWXV6OEh3HRi5fGzEn6pugK7//8qT+VAmdFHfR7Mto+Af7lYaly HnTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gc3dgyBP; spf=pass (google.com: domain of linux-kernel+bounces-12061-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12061-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r5-20020a632b05000000b005ce016cce2bsi7390426pgr.190.2023.12.27.06.50.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 06:50:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12061-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gc3dgyBP; spf=pass (google.com: domain of linux-kernel+bounces-12061-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12061-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 336ADB214F5 for ; Wed, 27 Dec 2023 14:50:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3517B45BE7; Wed, 27 Dec 2023 14:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gc3dgyBP" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 7E0704596D for ; Wed, 27 Dec 2023 14:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5c229dabbb6so1345090a12.0 for ; Wed, 27 Dec 2023 06:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703688585; x=1704293385; 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=bZIdcLBe5AtoEgMrZW8B5XtJiAwQZuHkmbazdIfOtJ0=; b=gc3dgyBPaPukg07mXkuyXuXi/6QK3hl4RBw/D6GMUHyYjNGr7vrd4/sM0yCn9aLo9Q Qp9aT4IkXD88SVNGpxQuG4IsRqK8Pe4yy5j817CI6GvwwxJ5vAFviSakEzTtjIiOPEgD arXNIXNqY1FjtLvT2tj5Uh96TZEBXE2xcljKCqSXCunctj8iz2x2t2RnHyKCjhRqcHkp 0DtvjNmfCJDsureKMEeIvGvIkK1Fpxsl1EphQt8G5peKLu0JU0e9B0bTY+eJJP4HutSu dJsFcR3XpzfHEvoxAOlG/vJcCsZxe2ZwEXlat/pZXtAg/9rvxjjkPY+hKmijTAzcw//w X6XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703688585; x=1704293385; 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=bZIdcLBe5AtoEgMrZW8B5XtJiAwQZuHkmbazdIfOtJ0=; b=hR5bOFandLeNCGiSuaDdHCVkezYOHRyO7Ljplw/1aPyAU5emm451J429SJdtP14wdi 9jFMOKd2Q700lMymTBOL28Pu/XFivTh2cSsh1jTErVuVWsa+5St/gQii4scMdnx+KGlO mUgooqGxzd+hRuql8m4YO39MVdYA6bmwlOD5NU5xxGOu12Vda3EZmU7qZ4BIDo2hey0t 0Pejjt73tlTuGb2S7mDnPzhceOkl6/lil+3tgHXqGFG8MsgY08iioAE7+HnDW48SX2xI XlFVW4yv2YrqjaQueW5BQdVLWUSJ0bx1aSF+Cg1AcxIlEuc/T0dFSKiRU76Z/+GnBJEg YZ3Q== X-Gm-Message-State: AOJu0YwCqRJ/a+P9hxBiZk6ZADubTPqOJ8y9qTJlSyF3uU9Yjto6NyFV 7xQWw5OLcaTMrqq7VC5FDBE1l+jNp5g= X-Received: by 2002:a17:90a:7e96:b0:28b:c10e:2f1e with SMTP id j22-20020a17090a7e9600b0028bc10e2f1emr2562890pjl.23.1703688585192; Wed, 27 Dec 2023 06:49:45 -0800 (PST) Received: from localhost ([198.11.178.15]) by smtp.gmail.com with ESMTPSA id h12-20020a17090aea8c00b0028c89298d36sm2178718pjz.27.2023.12.27.06.49.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2023 06:49:44 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Naohiro.Aota@wdc.com, Lai Jiangshan , Lai Jiangshan Subject: [PATCH 1/7] workqueue: Reuse the default PWQ as much as possible Date: Wed, 27 Dec 2023 22:51:37 +0800 Message-Id: <20231227145143.2399-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20231227145143.2399-1-jiangshanlai@gmail.com> References: <20231227145143.2399-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786446994207464666 X-GMAIL-MSGID: 1786446994207464666 From: Lai Jiangshan If the PWQ to be allocated has the same __pod_cpumask as the default one, just reuse the default one. No functionality changes intend. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 2989b57e154a..e734625fc8ce 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4270,7 +4270,7 @@ static void wq_calc_pod_cpumask(struct workqueue_attrs *attrs, int cpu, if (cpu_going_down >= 0) cpumask_clear_cpu(cpu_going_down, attrs->__pod_cpumask); - if (cpumask_empty(attrs->__pod_cpumask)) { + if (attrs->ordered || cpumask_empty(attrs->__pod_cpumask)) { cpumask_copy(attrs->__pod_cpumask, attrs->cpumask); return; } @@ -4360,15 +4360,15 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, goto out_free; for_each_possible_cpu(cpu) { - if (new_attrs->ordered) { + wq_calc_pod_cpumask(new_attrs, cpu, -1); + if (cpumask_equal(new_attrs->cpumask, new_attrs->__pod_cpumask)) { ctx->dfl_pwq->refcnt++; ctx->pwq_tbl[cpu] = ctx->dfl_pwq; - } else { - wq_calc_pod_cpumask(new_attrs, cpu, -1); - ctx->pwq_tbl[cpu] = alloc_unbound_pwq(wq, new_attrs); - if (!ctx->pwq_tbl[cpu]) - goto out_free; + continue; } + ctx->pwq_tbl[cpu] = alloc_unbound_pwq(wq, new_attrs); + if (!ctx->pwq_tbl[cpu]) + goto out_free; } /* save the user configured attrs and sanitize it. */ @@ -4530,6 +4530,8 @@ static void wq_update_pod(struct workqueue_struct *wq, int cpu, lockdep_is_held(&wq_pool_mutex)); if (wqattrs_equal(target_attrs, pwq->pool->attrs)) return; + if (cpumask_equal(target_attrs->cpumask, target_attrs->__pod_cpumask)) + goto use_dfl_pwq; /* create a new pwq */ pwq = alloc_unbound_pwq(wq, target_attrs); From patchwork Wed Dec 27 14:51:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 183485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1475268dyb; Wed, 27 Dec 2023 06:50:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8g9WAbuBZY0W/VQmqmqhkF/8mj+Ta6GILlPpiZ4WXxYwGYHxwjLdl1TZ5ifRR0PDcLGpb X-Received: by 2002:a50:c08a:0:b0:554:d691:d8a9 with SMTP id k10-20020a50c08a000000b00554d691d8a9mr2128882edf.143.1703688640385; Wed, 27 Dec 2023 06:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703688640; cv=none; d=google.com; s=arc-20160816; b=RmqoQzNTfCHlzJ2YyLSc18cHxs5VThQKAcb7vvN+NVV1yikfbgQvGpDNIOk4HAxPQt 0NIyw0mxOgJ55qvNv99ToZJqUGuGxqveP9aR1AoyU+jTJULoWbvLolp//GD0ut/FzaS1 nTeexY3OwvOprmWo82dXEq59LQ5/tJD9FVJFkMlHAOB7xHpcaPhe0PAMIBhnON6XNZ8z wMaslfRn72QLxBrLuREQS+BNH4dVYQxS11pGzWic207xlvFEMv9KUOoIgu8n04qpGu8k KT4jlU1bakiPMkcBWBRjlAsXpdnnucr0gZ4Ogr/o1KvAWvFjdtTcp7bur0M6Snkw47jX PivQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=OEkOlw6eKaiG2LU3fXepVKKsRgGZTje8n42JsBJJYDI=; fh=nCHpoOmZzPFKkYnjB6DcQplzE6zNssY94haDgAefa7c=; b=E7L2z9zksOWUFW+wt+8wZwBwFKDun5vOvnhhbTJIXqrOyZQYlM3c4p3ne+wrkvxCZ6 J89uzkZCNJ/trMrpWe695/FRVilXqcb2M5LaII2RZZ0CRO+SLpaD4a0bPotHbdi5X1Q+ IUZcHPzu2AJ6SaxXn9BJ/GQnd1Y3XGcF+hvec1LLBfCDIXMkc7pTaeZfs4azFlYdeN6d SYuoSrHdnRjWc6HCZfzr2Av/+2jdWv9JUckCxzKZnGfEzyg/8mI2YT1C0964GcZhziZV Bo5XESCqP/Ez32rSTqWiiNTxSm1H6mPTY+bRfKMHAkyVOxy/jrtZgsyrPVtZ+E2QMYPr wQGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WF771chD; spf=pass (google.com: domain of linux-kernel+bounces-12063-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12063-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y12-20020a056402270c00b0055312f1f9a2si6584796edd.436.2023.12.27.06.50.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 06:50:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12063-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WF771chD; spf=pass (google.com: domain of linux-kernel+bounces-12063-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12063-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 043F31F22281 for ; Wed, 27 Dec 2023 14:50:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D30546529; Wed, 27 Dec 2023 14:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WF771chD" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 C91DB4643A for ; Wed, 27 Dec 2023 14:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d427518d52so23302385ad.0 for ; Wed, 27 Dec 2023 06:49:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703688594; x=1704293394; 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=OEkOlw6eKaiG2LU3fXepVKKsRgGZTje8n42JsBJJYDI=; b=WF771chDp+6AOt7o9/GeMsCo77s+GKRaYP6fpNgXyn/03IgZzPaYYN9lsxdpDsxoZE yTT7YaYZbGfHbyEwQTxdH8DIFQHwEXMR5AH+CPfTpxH/Dri/fUaBYZ6kbOziGgVkhWZP tGYe1rIdhdpLJRdHDXGjJpigK1GttrVFWcdoBy9aNnRFMjoUTA64ff54AiAkQeHVl/57 HRPcy1Xg2fSGBGOpODQ3trJ7ZH1IwPOlZ8mUuc+v5MmSJmvYYMcqLu904VMdSNBOsh5U BymMMvZPPTNGC9tQkWB6ZwWk8T/ErPf5gH6SAz9FWY9C3eMp2Xbv2lnVqLqKcH8coIrF UBkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703688594; x=1704293394; 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=OEkOlw6eKaiG2LU3fXepVKKsRgGZTje8n42JsBJJYDI=; b=H54VYtQ+Utq7RaSPFVae2pIRW4r9qOIDqsBZC9U7ZGbDuuPuumxe8AM5y0g6cdVVDm 6lU80f3ocxU93J/DVqcS6gW4zCYcZLCKIDz1CUsK7/xbtaxIB7nkLsOWfWjy/ae8y5Ar L4S60xn7MLiszrpcn7exZJP28Sx2P1xfXoOfIgVLGHIvG22MRM7a1vw9vsKQH6lKTHXQ MAC7oeRc19y+Z2qxwcz9GNdoGHbOppuhuL+x71HLesXyZDteafrY7qA2LkFqcRH8oqjP W/jCaPVbCxDqPBHOHCJRuRxzE0iGztH/ootfD4ZbU5ml+SyJd8vL5t3mH2L5N3d/tqHe 5+LA== X-Gm-Message-State: AOJu0Yyw9wute9xtu5AOAwfhOOtDjJFWEyuHl+3WBY/nOJP2qiZlNoq5 nsMFghOfnqHG1HqQHMJcoxBBrN6N+5g= X-Received: by 2002:a17:902:6846:b0:1d4:81bc:a2c2 with SMTP id f6-20020a170902684600b001d481bca2c2mr1093014pln.2.1703688593655; Wed, 27 Dec 2023 06:49:53 -0800 (PST) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id ix9-20020a170902f80900b001cff026df52sm12148249plb.221.2023.12.27.06.49.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2023 06:49:53 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Naohiro.Aota@wdc.com, Lai Jiangshan , Lai Jiangshan Subject: [PATCH 3/7] workqueue: Add pwq_calculate_max_active() Date: Wed, 27 Dec 2023 22:51:39 +0800 Message-Id: <20231227145143.2399-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20231227145143.2399-1-jiangshanlai@gmail.com> References: <20231227145143.2399-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786447019703016958 X-GMAIL-MSGID: 1786447019703016958 From: Lai Jiangshan Abstract the code of calculating max_active from pwq_adjust_max_active() into pwq_calculate_max_active() to make the logic clearer. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 1f52685498f1..3347ba3a734f 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4136,6 +4136,25 @@ static void pwq_release_workfn(struct kthread_work *work) } } +/** + * pwq_calculate_max_active - Determine max_active to use + * @pwq: pool_workqueue of interest + * + * Determine the max_active @pwq should use. + */ +static int pwq_calculate_max_active(struct pool_workqueue *pwq) +{ + /* + * During [un]freezing, the caller is responsible for ensuring + * that pwq_adjust_max_active() is called at least once after + * @workqueue_freezing is updated and visible. + */ + if ((pwq->wq->flags & WQ_FREEZABLE) && workqueue_freezing) + return 0; + + return pwq->wq->saved_max_active; +} + /** * pwq_adjust_max_active - update a pwq's max_active to the current setting * @pwq: target pool_workqueue @@ -4147,35 +4166,26 @@ static void pwq_release_workfn(struct kthread_work *work) static void pwq_adjust_max_active(struct pool_workqueue *pwq) { struct workqueue_struct *wq = pwq->wq; - bool freezable = wq->flags & WQ_FREEZABLE; + int max_active = pwq_calculate_max_active(pwq); unsigned long flags; /* for @wq->saved_max_active */ lockdep_assert_held(&wq->mutex); - /* fast exit for non-freezable wqs */ - if (!freezable && pwq->max_active == wq->saved_max_active) + /* fast exit if unchanged */ + if (pwq->max_active == max_active) return; /* this function can be called during early boot w/ irq disabled */ raw_spin_lock_irqsave(&pwq->pool->lock, flags); - /* - * During [un]freezing, the caller is responsible for ensuring that - * this function is called at least once after @workqueue_freezing - * is updated and visible. - */ - if (!freezable || !workqueue_freezing) { - pwq->max_active = wq->saved_max_active; + pwq->max_active = max_active; - while (!list_empty(&pwq->inactive_works) && - pwq->nr_active < pwq->max_active) - pwq_activate_first_inactive(pwq); + while (!list_empty(&pwq->inactive_works) && + pwq->nr_active < pwq->max_active) + pwq_activate_first_inactive(pwq); - kick_pool(pwq->pool); - } else { - pwq->max_active = 0; - } + kick_pool(pwq->pool); raw_spin_unlock_irqrestore(&pwq->pool->lock, flags); } From patchwork Wed Dec 27 14:51:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 183486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1475354dyb; Wed, 27 Dec 2023 06:50:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IESLjArCGjFRuo23aXmkfo1ENlxxkTESBNjo+GmY2HdrSP1KGkJ9Adik0nWxboehF8ZXFIZ X-Received: by 2002:a0c:be8f:0:b0:680:3137:72a6 with SMTP id n15-20020a0cbe8f000000b00680313772a6mr2695108qvi.116.1703688652830; Wed, 27 Dec 2023 06:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703688652; cv=none; d=google.com; s=arc-20160816; b=nPZU0heCoyUomXKbklY69j5G/NaKxHg1pF6OBuAzc9246uAYI9VBTcHJT7D9f6Uxjp o3YenWeRWikSKDd4RYQlWMuV29IzBsHKU1bgN/6rJM58N0CykA3ks3TSlOh8dJxh0u7S U7OWZQgN7b6tMPIyELlue/y3Bn6ggOic6eij0sgEU+UNf52jGbUSiK06VpqAzetWGE/v 7dJdliPtxFq+fmM02hcnqx3SQpdpSM2MDFlxIbZmzX0vFD9JsApoBPRpyYDXORrZ15Z9 +kf5QbOZLLm31AvmqcoLoNYQHn88VZJLNpDDBLaB6O2tqzJDWowq/ErPGNo1+C2cqV6f lQ2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ykeys9/b81hQucL41oKnYrH4NAgYOfGtA2bT2pIxo5Q=; fh=nCHpoOmZzPFKkYnjB6DcQplzE6zNssY94haDgAefa7c=; b=KXKCtsz0nUJKUL2ZU38y2AnK9OI3b1CyLMf/lgg6biVM8UiHApc/USLxxn970xSaSa YS5Ap0EASofn00a5Z7qgqLLpyHj0eVECAXIzk3YFXcTcRNKmcqWBVwUFn4YxB4po3iM9 sn98eM8EaD3aIEIPxE1BTNpWTW6Uy4NCSpeYwDg37ALZHb5dhIWi907r6Lqpr6tNMhdr P1Gq2RVzfEEiZVmXecSGDNVkJjeie7SdR842hIPmlUmj4oXYnLo9pKQ9p6m23UAoFBrb yRl4zb+EMeLcvXGkZQvseMLksy81jPYFAR9Ne3rPIqaptPAuOuko3r9pfD7r203TI/bw P78w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="NN/5vIBk"; spf=pass (google.com: domain of linux-kernel+bounces-12064-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12064-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n10-20020a0ce48a000000b0067f2ef1a8a9si14748549qvl.296.2023.12.27.06.50.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 06:50:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12064-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="NN/5vIBk"; spf=pass (google.com: domain of linux-kernel+bounces-12064-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12064-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D3C91C20BC2 for ; Wed, 27 Dec 2023 14:50:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96D9246552; Wed, 27 Dec 2023 14:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NN/5vIBk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 BF70A4645C for ; Wed, 27 Dec 2023 14:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d3ea5cc137so41536835ad.0 for ; Wed, 27 Dec 2023 06:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703688598; x=1704293398; 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=Ykeys9/b81hQucL41oKnYrH4NAgYOfGtA2bT2pIxo5Q=; b=NN/5vIBkuMEgYFRUg56ViHsz6i0CXAPj1jkWMWTSuL+MVuBz6am6ZAV3e7oJvLaErg i2ewoS4ZxSnC+Y0Wu3u1SSLWJVOokwbXmpWwjEjaP5Jo+Ktx4X9NYOcINEf4XRF69Vtk W1Z2c0acQF3t0I+/oF39onoQCFIxp3DSCuyVk/pppKBQi/v3pyxMD5FNmmhMPe6U+2wY xMAjioZHWbXo7QYk8y+ru/xjshGkCFLhdrAFlrtMxUDMpyBdo/cV6bz5n3PW5Bwng86A 4ZxoCAsNKf+Wrm18b/cELUJCvw/KsPhEGbe0iIIOdjmNOICuQ0j+o9K/tmWNhicocZpW 23kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703688598; x=1704293398; 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=Ykeys9/b81hQucL41oKnYrH4NAgYOfGtA2bT2pIxo5Q=; b=LjBA3gYQfVdhc+IZjMsDlNIPLSW6mmAGAEiXiTPUgGrmOeDmW4yUY3062nyhV6bgYk d2kvjcggSewtlYXFIPrbNWDSRGPwBDXQ/FjwuKXXFag8E5pdFqNqsKQlGj4c+QX5Q3vB tiRVUcY0PfqYTBopNMp50Sk4JEd7B3/fDMOJUf+pKNf791ybk8ZDSKAyCFkjBR+7glf+ ZZEjHOJMl+/y8VjTo6JZgSWQ79subfMDDsHJ197UoN8y+Rec/OB21NgI3/vOQTjAclDW KW0b1Cc5tY2ag3gRvvw3113AWR6+TIpTvn9LiBO/p6JnQ+gIIHdj5iNTN+D1nNuIjXrR Un1Q== X-Gm-Message-State: AOJu0YxRxQk0w9i9aDSBVg5W+st+yLBACHjavbBEXyjAgitgeYu/Y70c 0MD3u1oBuYHlYZbaxZ++V8ldL++DJqQ= X-Received: by 2002:a17:902:ec92:b0:1d0:6ffe:9f5 with SMTP id x18-20020a170902ec9200b001d06ffe09f5mr8166768plg.83.1703688597875; Wed, 27 Dec 2023 06:49:57 -0800 (PST) Received: from localhost ([47.89.225.180]) by smtp.gmail.com with ESMTPSA id x22-20020a170902821600b001cfc1b931a9sm11995380pln.249.2023.12.27.06.49.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2023 06:49:57 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Naohiro.Aota@wdc.com, Lai Jiangshan , Lai Jiangshan Subject: [PATCH 4/7] workqueue: Wrap common code into wq_adjust_pwqs_max_active() Date: Wed, 27 Dec 2023 22:51:40 +0800 Message-Id: <20231227145143.2399-5-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20231227145143.2399-1-jiangshanlai@gmail.com> References: <20231227145143.2399-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786447033217802182 X-GMAIL-MSGID: 1786447033217802182 From: Lai Jiangshan There are 3 places using the same code, so wrap them into a common helper. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 3347ba3a734f..e0101b2b5fa3 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4190,6 +4190,16 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) raw_spin_unlock_irqrestore(&pwq->pool->lock, flags); } +static void wq_adjust_pwqs_max_active(struct workqueue_struct *wq) +{ + struct pool_workqueue *pwq; + + mutex_lock(&wq->mutex); + for_each_pwq(pwq, wq) + pwq_adjust_max_active(pwq); + mutex_unlock(&wq->mutex); +} + /* initialize newly allocated @pwq which is associated with @wq and @pool */ static void init_pwq(struct pool_workqueue *pwq, struct workqueue_struct *wq, struct worker_pool *pool) @@ -4700,7 +4710,6 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, { va_list args; struct workqueue_struct *wq; - struct pool_workqueue *pwq; /* * Unbound && max_active == 1 used to imply ordered, which is no longer @@ -4761,14 +4770,8 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, * list. */ mutex_lock(&wq_pool_mutex); - - mutex_lock(&wq->mutex); - for_each_pwq(pwq, wq) - pwq_adjust_max_active(pwq); - mutex_unlock(&wq->mutex); - + wq_adjust_pwqs_max_active(wq); list_add_tail_rcu(&wq->list, &workqueues); - mutex_unlock(&wq_pool_mutex); return wq; @@ -5698,19 +5701,14 @@ EXPORT_SYMBOL_GPL(work_on_cpu_safe_key); void freeze_workqueues_begin(void) { struct workqueue_struct *wq; - struct pool_workqueue *pwq; mutex_lock(&wq_pool_mutex); WARN_ON_ONCE(workqueue_freezing); workqueue_freezing = true; - list_for_each_entry(wq, &workqueues, list) { - mutex_lock(&wq->mutex); - for_each_pwq(pwq, wq) - pwq_adjust_max_active(pwq); - mutex_unlock(&wq->mutex); - } + list_for_each_entry(wq, &workqueues, list) + wq_adjust_pwqs_max_active(wq); mutex_unlock(&wq_pool_mutex); } @@ -5773,7 +5771,6 @@ bool freeze_workqueues_busy(void) void thaw_workqueues(void) { struct workqueue_struct *wq; - struct pool_workqueue *pwq; mutex_lock(&wq_pool_mutex); @@ -5783,12 +5780,8 @@ void thaw_workqueues(void) workqueue_freezing = false; /* restore max_active and repopulate worklist */ - list_for_each_entry(wq, &workqueues, list) { - mutex_lock(&wq->mutex); - for_each_pwq(pwq, wq) - pwq_adjust_max_active(pwq); - mutex_unlock(&wq->mutex); - } + list_for_each_entry(wq, &workqueues, list) + wq_adjust_pwqs_max_active(wq); out_unlock: mutex_unlock(&wq_pool_mutex); From patchwork Wed Dec 27 14:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 183487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1475480dyb; Wed, 27 Dec 2023 06:51:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXxGvMy0cZ79keELFDnKm1ki3o4FABzjIbV1iCkzG4v3SxWZXhdK5J2bxFygBNTyY21TCm X-Received: by 2002:a17:903:2283:b0:1d4:5268:27d9 with SMTP id b3-20020a170903228300b001d4526827d9mr5948401plh.55.1703688670695; Wed, 27 Dec 2023 06:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703688670; cv=none; d=google.com; s=arc-20160816; b=l9BUE+B7KtL4iJ/EW5NnIObQuC+uIea3SfximbdIxgaDjWuYyZGqDnoCm8Ats+g5RJ MTFFHZkhPsMXLNVD27lgF5zn51TzDD7AsSg10Z1B+UbzqnTcfjzGjTubBFCRs8Oelelf ZS4wXTM/uIVOjcvoBgpvViWUFgBLaPhDOkWFxPKcyQSWV92heRiCVOB6CEzBPGBaqca4 c1E4jqBrQWSl/YIuxjZEpndFnmI/KFfxGc2ememCVmcQDRhYMxHy5KxQaQfa8q05kPji QW40NC8H5YBOcpWlRz/18eMxnhuQw0umyxJXt0JFBu2ZZNUT7LalUbhRdLIVHGtRQo96 N3+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5JgQdBp97fYnSauGF41qAWZ2C5akEqSt+yyiFx6LPIY=; fh=nCHpoOmZzPFKkYnjB6DcQplzE6zNssY94haDgAefa7c=; b=Oth52zFS30IAK0dQalnYMOPD42AvwM9XUsvR6s3j6rvcgl1OpBXUZ/xBGOr6b4zzgq +AKCjxLGH2EQebv5sDX1HWTdKTZWD6TCqmnrphUV4/nWmhpib7EhOKh2BLHzesFmdOjw cJvNguv+vaGz43hnYJl79jgd8qqRsil5ywTxVu1j/Bfe97544ypdTkUIt8eUObcSz/8p GPTl0sHhGNBZ7HhDy2uukU0Sn8Icc4ioTQKD9z7im7/nfJxPeG1deRStD71qGLBRoxj0 LNlAATMuhf9yaNgow25/5wiSuXgQXDVw2XsuhobDy1/jbqpgxBTTdVqhBk3A+846/DSn gNXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cHaVO3hL; spf=pass (google.com: domain of linux-kernel+bounces-12065-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12065-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d20-20020a170902aa9400b001c9c967e77esi1232894plr.207.2023.12.27.06.51.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 06:51:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12065-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cHaVO3hL; spf=pass (google.com: domain of linux-kernel+bounces-12065-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12065-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AEB2FB20AAC for ; Wed, 27 Dec 2023 14:51:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1FB347775; Wed, 27 Dec 2023 14:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cHaVO3hL" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 349484655F for ; Wed, 27 Dec 2023 14:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d422c9f894so30418925ad.3 for ; Wed, 27 Dec 2023 06:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703688602; x=1704293402; 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=5JgQdBp97fYnSauGF41qAWZ2C5akEqSt+yyiFx6LPIY=; b=cHaVO3hLRUlKmmjxZcKzlxdAb0fd8WomUt9kUGiEdQIZOtWsAPr9xWW10JZgjThK+V X7NCgikZviCJPitmvWoG50SBwP6T8jX5rjLcJnpfZ9Azp7+GxEtPIfOSh+Qy+NNjNc8L YHmw/YpjtTlMR8MjV2wK9BgoTBAQxhjX8lMTBFj61u8Ckwxrh0IAmO/1C6+VXDKJ1Rv6 G/n3432z13SjnYRUz4qL7lRlpTFLx91LGJdZ/JSZK0fygafyapradebo2wSpaJxpVo7S uSLaIa8HVaoj7fB7CFHJyAN66w4jyVlfaHu1Hfs2QFCEGQJOnmD2myQ4PczsIsYDuU9F qFhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703688602; x=1704293402; 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=5JgQdBp97fYnSauGF41qAWZ2C5akEqSt+yyiFx6LPIY=; b=RaHSQ+tu5wR3+aKzJgnLMjL54iPxfbHRE2SB1aZ+GM9xEFM7JuAS5iBIHUn1rUelj8 HAZY62LwU8yhuCWIxW4lReuwGdJr0WTxaUS0pYq2MG6/+45Hur+u5BF+0irjd2+fMENS QUmbzHokcHH2eFaKRtZoF7MyHuZUDZlofvyuqhq9zXGvmSroH/lWwLVat++MFKJBdtSc s6rbOW+1IUMQefcweE951TjbkJs2/65KGgWlhx6vfbYAhjdXYIzaGktP8wsVvYn/GU+L ea373FqrxicUrwI8ZFpi9VcieL+wwNjFYT4bUbpNL/JczTQco1dkWSjgMfdsgJJRXlQR hTfw== X-Gm-Message-State: AOJu0YxUFkXBOxsUwaIho7hC/q4W5MGuuRkgSxMpRlHghiAlE6mM2zBo Odma2oVXzkHRIfFvb+L66TNo5XbPv+s= X-Received: by 2002:a17:902:bf42:b0:1d3:bedd:ad with SMTP id u2-20020a170902bf4200b001d3bedd00admr9265671pls.35.1703688602065; Wed, 27 Dec 2023 06:50:02 -0800 (PST) Received: from localhost ([198.11.176.14]) by smtp.gmail.com with ESMTPSA id r22-20020a170902be1600b001d3aa7604c5sm9806269pls.0.2023.12.27.06.50.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2023 06:50:01 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Naohiro.Aota@wdc.com, Lai Jiangshan , Lai Jiangshan Subject: [PATCH 5/7] workqueue: Addjust pwq's max_active when CPU online/offine Date: Wed, 27 Dec 2023 22:51:41 +0800 Message-Id: <20231227145143.2399-6-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20231227145143.2399-1-jiangshanlai@gmail.com> References: <20231227145143.2399-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786447051079368178 X-GMAIL-MSGID: 1786447051079368178 From: Lai Jiangshan pwq->max_active is going to be set based on the CPU online distribution which might be changed when CPU online/offine. Call into wq_adjust_pwqs_max_active() to update them when needed. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index e0101b2b5fa3..d1c671597289 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5590,10 +5590,15 @@ int workqueue_online_cpu(unsigned int cpu) mutex_unlock(&wq_pool_attach_mutex); } - /* update pod affinity of unbound workqueues */ + /* + * Update pod affinity of unbound workqueues, and update max_active + * for PWQs of all pods due to CPU online distribution changed. + */ list_for_each_entry(wq, &workqueues, list) { - if (wq->unbound_attrs) + if (wq->unbound_attrs) { wq_update_pod(wq, cpu, true); + wq_adjust_pwqs_max_active(wq); + } } mutex_unlock(&wq_pool_mutex); @@ -5610,11 +5615,16 @@ int workqueue_offline_cpu(unsigned int cpu) unbind_workers(cpu); - /* update pod affinity of unbound workqueues */ + /* + * Update pod affinity of unbound workqueues, and update max_active + * for PWQs of all pods due to CPU online distribution changed. + */ mutex_lock(&wq_pool_mutex); list_for_each_entry(wq, &workqueues, list) { - if (wq->unbound_attrs) + if (wq->unbound_attrs) { wq_update_pod(wq, cpu, false); + wq_adjust_pwqs_max_active(wq); + } } mutex_unlock(&wq_pool_mutex); From patchwork Wed Dec 27 14:51:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 183488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1475685dyb; Wed, 27 Dec 2023 06:51:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGt41StvU7e3WXdPYgUobZGxltOKxWMbYl0P6AQMxDZFIPH/yK/EX/zcZYJr13i2N0pV9fb X-Received: by 2002:a05:6a00:2316:b0:6d9:70fc:e3f with SMTP id h22-20020a056a00231600b006d970fc0e3fmr10344099pfh.24.1703688695847; Wed, 27 Dec 2023 06:51:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703688695; cv=none; d=google.com; s=arc-20160816; b=L1A84yPyG6AqDAInYcpSVqRsSP7inRugDuauDemD5NtShvEZ0iwSTebrP3wG7T2Ubv GCqcVpoa7Jlx6gxGqVvHvrAPbbHQ1oLcGR0RZjSfLivUpqbfNz/GDGTM/uMPxE10adhi HV91dDt+CeHy+AZSwVwawLE309sl7L87Aoxv5BEd/sFXgINiJYCAJMZ2Apivo7sIyQs3 Go5gdXJs4r7ciF3R190UA52tR/nJcUoma65bw5vpntEwb7aQ12julkjCM8h3NtLIwcjv cfmX7F/4Nz4gDDLsQHXuR7ObP7BWKW7iaHGFz3rh3J9UOOnJrkoIPE3yi+oaCKtMK3s2 u0Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dBhAD2KkbriEp2qNC+ghO6AuutHK13Eu3XnJAL8S1+o=; fh=nCHpoOmZzPFKkYnjB6DcQplzE6zNssY94haDgAefa7c=; b=vpWFZxZKbr+LQtUV7Ab+W6JS+xRti+2y0e4B6mzeo8hWqC6CZix/G7uG11LU0uklkX Ep1QZqNAby2hJeuhelRFVErfN68firMJXoW4FbI5rF4S+pNqJid7ondruqI+CWrQeP4e EXjx6Y7+bzXSb6bZCH2QVZVE/Ur1bHKFJkCUr4Kd/mvXHv1ZFu6sYh9NgeZFnLAzN8qN 43F1MIIHgiXfAoOWmis1c3Af+YmZzmUWTWISKFhGEIVfHplwhTcBrPjz3UAYrktsjpNB 0CQ1cXdm1y0NWsui4p6RumobeTG039jAU/Nfe2rwqxiqXmHJQFzK8/KaufFeAvU8oYKf yghg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ajXoVreg; spf=pass (google.com: domain of linux-kernel+bounces-12067-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12067-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id cd10-20020a056a00420a00b006d9bf3574fbsi4288248pfb.35.2023.12.27.06.51.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 06:51:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12067-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ajXoVreg; spf=pass (google.com: domain of linux-kernel+bounces-12067-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12067-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A7DDAB209FD for ; Wed, 27 Dec 2023 14:51:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C7D9A47F6B; Wed, 27 Dec 2023 14:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ajXoVreg" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 E997847F4D for ; Wed, 27 Dec 2023 14:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5cd5cdba609so3954685a12.0 for ; Wed, 27 Dec 2023 06:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703688612; x=1704293412; 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=dBhAD2KkbriEp2qNC+ghO6AuutHK13Eu3XnJAL8S1+o=; b=ajXoVregn/SHzWsoS+oENP/XcxH1cNJ/lhGGiGn+u8OoZ6nZhZdeu0Y+3ZsbwkCtAa FfsQHWn1kNFAWkcaKbR2AUYoiz+eG0bvc/X5VRz2iIAe/H4ksDuK8S3HGca5+mzKC6SQ lck+4mY2rwWqx4i4JckP4cC48rTklsRxyMp+5HToR0zOuUrQndWcRQw56RSxRkPdjo3q STaqbgPbxNcsj9flTvZg/QWhfV4pta7C8m+vMjXJybcHwr/JDnjpjeKR293koDQ9J6nb XlEAFmIxfwk4bse4Ktv8psX6HsmDdyhtF02sG9Tq0xT/uozeeoGRVehR7FRqtLouiVnZ xy1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703688612; x=1704293412; 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=dBhAD2KkbriEp2qNC+ghO6AuutHK13Eu3XnJAL8S1+o=; b=Q8Y+cmxAmCWtW/AteV0y/tBCmL9ajbPBnaKF9IQBTFX8on8sx+ZXXB6woQYyO7UWF2 1f3IyAshWhrIrezuF4o7sAG9axyUz6fMuvSLTLa4N6itZ1ZjqVOE0X2PHBMCUjtcLgqx Z4hoYUQXufEpyfiMjH4PK7bWdYJiN+mm213ekVh2ebWJivKyPV+180xV6eMCT+ie1KS1 ryp7GHq51EUj1WtOnp8x7HpdVhiSj1SZ5QrIgvgF+Ybd889ObfzCnY7msvs0xG3fV50E NRymNhx4euPINAhhYlHF2kOX5p0B/50CSGFe30XikQmLGZy4og4gWw3mQsm4TL4tXRBB Nrcw== X-Gm-Message-State: AOJu0YzcO+jCuEt3tO3mT4bCRBustoUdyb/npowYxLgGbpwJAkgWmD5e Vn/JuhLeF0nB1DBEm++Ijo4tD1x3CV0= X-Received: by 2002:a05:6a21:99a9:b0:196:16b0:b7b3 with SMTP id ve41-20020a056a2199a900b0019616b0b7b3mr1480281pzb.78.1703688612010; Wed, 27 Dec 2023 06:50:12 -0800 (PST) Received: from localhost ([198.11.176.14]) by smtp.gmail.com with ESMTPSA id f6-20020a056a001ac600b006d9a48882f7sm7651268pfv.118.2023.12.27.06.50.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2023 06:50:11 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Naohiro.Aota@wdc.com, Lai Jiangshan , Lai Jiangshan Subject: [PATCH 7/7] workqueue: Rename wq->saved_max_active to wq->max_active Date: Wed, 27 Dec 2023 22:51:43 +0800 Message-Id: <20231227145143.2399-8-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20231227145143.2399-1-jiangshanlai@gmail.com> References: <20231227145143.2399-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786447077988954193 X-GMAIL-MSGID: 1786447077988954193 From: Lai Jiangshan The name max_active is clearer. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 382c53f89cb4..0458545642f7 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -298,7 +298,7 @@ struct workqueue_struct { struct worker *rescuer; /* MD: rescue worker */ int nr_drainers; /* WQ: drain in progress */ - int saved_max_active; /* WQ: saved max_active */ + int max_active; /* WQ: percpu or total max_active */ int min_active; /* WQ: pwq min_active */ struct workqueue_attrs *unbound_attrs; /* PW: only for unbound wqs */ @@ -3376,7 +3376,7 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr, * forward progress. */ if (!from_cancel && - (pwq->wq->saved_max_active == 1 || pwq->wq->rescuer)) { + (pwq->wq->max_active == 1 || pwq->wq->rescuer)) { lock_map_acquire(&pwq->wq->lockdep_map); lock_map_release(&pwq->wq->lockdep_map); } @@ -4159,17 +4159,17 @@ static int pwq_calculate_max_active(struct pool_workqueue *pwq) return 0; if (!(pwq->wq->flags & WQ_UNBOUND)) - return pwq->wq->saved_max_active; + return pwq->wq->max_active; pwq_nr_online_cpus = cpumask_weight_and(pwq->pool->attrs->__pod_cpumask, cpu_online_mask); - max_active = DIV_ROUND_UP(pwq->wq->saved_max_active * pwq_nr_online_cpus, num_online_cpus()); + max_active = DIV_ROUND_UP(pwq->wq->max_active * pwq_nr_online_cpus, num_online_cpus()); /* * To guarantee forward progress regardless of online CPU distribution, * the concurrency limit on every pwq is guaranteed to be equal to or * greater than wq->min_active. */ - return clamp(max_active, pwq->wq->min_active, pwq->wq->saved_max_active); + return clamp(max_active, pwq->wq->min_active, pwq->wq->max_active); } /** @@ -4177,7 +4177,7 @@ static int pwq_calculate_max_active(struct pool_workqueue *pwq) * @pwq: target pool_workqueue * * If @pwq isn't freezing, set @pwq->max_active to the associated - * workqueue's saved_max_active and activate inactive work items + * workqueue's max_active and activate inactive work items * accordingly. If @pwq is freezing, clear @pwq->max_active to zero. */ static void pwq_adjust_max_active(struct pool_workqueue *pwq) @@ -4186,7 +4186,7 @@ static void pwq_adjust_max_active(struct pool_workqueue *pwq) int max_active = pwq_calculate_max_active(pwq); unsigned long flags; - /* for @wq->saved_max_active */ + /* for @wq->max_active */ lockdep_assert_held(&wq->mutex); /* fast exit if unchanged */ @@ -4761,7 +4761,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, /* init wq */ wq->flags = flags; - wq->saved_max_active = max_active; + wq->max_active = max_active; wq->min_active = min(max_active, WQ_DFL_MIN_ACTIVE); mutex_init(&wq->mutex); atomic_set(&wq->nr_pwqs_to_flush, 0); @@ -4935,7 +4935,7 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active) mutex_lock(&wq->mutex); wq->flags &= ~__WQ_ORDERED; - wq->saved_max_active = max_active; + wq->max_active = max_active; wq->min_active = min(wq->min_active, max_active); for_each_pwq(pwq, wq) @@ -5990,7 +5990,7 @@ static ssize_t max_active_show(struct device *dev, { struct workqueue_struct *wq = dev_to_wq(dev); - return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active); + return scnprintf(buf, PAGE_SIZE, "%d\n", wq->max_active); } static ssize_t max_active_store(struct device *dev,