Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp437970rdb; Wed, 20 Dec 2023 01:20:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpgEjJ/fpDxbtpF4uy1P9CsvrxfXJKhCjdEyIfCTWO8pyKTrbzipIfBEbwEpC2Ieg1pfRS X-Received: by 2002:a05:6214:1305:b0:67a:9649:4229 with SMTP id pn5-20020a056214130500b0067a96494229mr25224549qvb.65.1703064039206; Wed, 20 Dec 2023 01:20:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703064039; cv=none; d=google.com; s=arc-20160816; b=wen1k12wkrCPGRlfcGn4EYPNTXaaNBcmQS/yWbcBqvarBtxIOMx7+UY4pJXc21o6g0 7H6qJs7RxIutOsbPKZTawbUHMpiCz2lg3lktElaNCptYPBXXtuF4YvV4UBcfA34Xavhm qV3wGxZr5SJOQaHTaVaE+hScOkQtOhtZKhonF8u3Lycte5a08lRzsaQc1zHxxbw+S2kP IDJ7OCntZX/ukP5VT4/Xjgayqi9JdfHTg47tExzu1MdHxWYCjXx5opCplJwzBg3xoqFO WdHFEJ8LebJTTOJ9UjHRmDwYu7Q8e+F6szixznEK7WcSy4aQyQbzaSrMZg/dEhm36+SR DoaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=dSahWqN/XPOUg/6X2/I93IlKLYoJC4R549QbBR0j2hg=; fh=x4smHwPOFOw21iBdSC3OpOhG6G0fYH4M8HPWFGpCrr4=; b=RyFJzTDf9zG+vQoXBSVYjmYEIordEl0N9Ne4E34m7/rs/AuoG/CC+nygsXq7Z6+LEG wUgoYD84Yswmh9IFPNmPxJd3qQ5pT9zvHSbaLDHU/0CgtRrTC/O9EF67Gk/5YyYf9j2Z ubsBYoc4Ds+j2LGZgPVbcrkkyugqjS5g2kqiBEhTCZ8msFKGzCIeMEB06ZI1iseQItHF KiUuHyZu9VEacTHBTvvokzfSZ4rwZ+/S6x9DkDJ86Z7xMlxxynQXekrJQw3aIUuAfSz2 xu7FBPbEv99RvQkTgfasAK62tI50VS6nKFVRLi3ALYedrVczgX+wWRGdsmH0xnBQJ8se KB8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PYZs0GOy; spf=pass (google.com: domain of linux-kernel+bounces-6633-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r12-20020a0ccc0c000000b0067f076c65cfsi11328172qvk.58.2023.12.20.01.20.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 01:20:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6633-linux.lists.archive=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=PYZs0GOy; spf=pass (google.com: domain of linux-kernel+bounces-6633-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6633-linux.lists.archive=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 DA8E61C24063 for ; Wed, 20 Dec 2023 09:20:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D20F1DA5E; Wed, 20 Dec 2023 09:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PYZs0GOy" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 1E9151DA27 for ; Wed, 20 Dec 2023 09:20:30 +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-f180.google.com with SMTP id 41be03b00d2f7-5c690c3d113so4168093a12.1 for ; Wed, 20 Dec 2023 01:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703064030; x=1703668830; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dSahWqN/XPOUg/6X2/I93IlKLYoJC4R549QbBR0j2hg=; b=PYZs0GOyW5xpvMBErtRlGAX9+WNeMfPD3pv2XFPVGvcXDVSUbkLzHOsyQuRcuEogTg CdiS79jEVONDz2FkSYgdTj+oaH6Aa3Tc9hrdnUWc+6v+T7wY/Y+Kmkpcf3SRUFTSsRDM KI01+7uScjsKTwv67S03x5qraeBW+YY9pBZj0U7cWUwRKv9lotWSCNJapyOaABBflh/N /EvsWcHccxoBYlsbKFBpPULmTnJsRYHIGM3k4QPQ+1D9p33s9SPJp4ZcHV91y1f+kdAn FwxZQy1zTXewyX9BPCLUcfj/EdF0zsrVPB1UkmvQvVtY7MV5tZOXuglDvcf1XXPFHY1G xsNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703064030; x=1703668830; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dSahWqN/XPOUg/6X2/I93IlKLYoJC4R549QbBR0j2hg=; b=BKEn+FO/2dRPNphSvn2U6Lp/36lHL+rHGVhiEPeCy+6c+BmU3yDDjCLpXDvvG6id90 GjdfOycYTx7SuQ+5WzEh5ZwOEITSyQmZp6J7x0a/PGbQo04iV5OuII/Hv81Zhz2VmH/z udVLUXdRNOKl3jU9ArvVaZhdJIBqI3sFEZaM2xDRIQQ9pXTPq+pVPoE4B/L8NW25RR+7 VrWVcs/OsDD2TyCtyM23NGpnogZbxPAOfSZr7XQ605zvMkGEYqARHW5B6A5R9Nhkd59F eHoasapleVfrNKg2QFibqaEJkIZGdJJjJKkbSojaTKLWQvEKHZCMpVrUPdxZVY5lnTt3 SDnA== X-Gm-Message-State: AOJu0Yw9wKTTL1FVEhBztR32PyLPkegIEwPLZ4yr5fpBCoGqFRigvNBl b9ySq8d9JZ568iRS7i7lZL/ZMghcEtRXK7mKTrA= X-Received: by 2002:a05:6a20:7b21:b0:194:a26a:15a8 with SMTP id s33-20020a056a207b2100b00194a26a15a8mr1971508pzh.23.1703064030213; Wed, 20 Dec 2023 01:20:30 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231220072529.1036099-1-tj@kernel.org> In-Reply-To: <20231220072529.1036099-1-tj@kernel.org> From: Lai Jiangshan Date: Wed, 20 Dec 2023 17:20:18 +0800 Message-ID: Subject: Re: [PATCHSET wq/for-6.8] workqueue: Implement system-wide max_active for unbound workqueues To: Tejun Heo Cc: linux-kernel@vger.kernel.org, Naohiro.Aota@wdc.com, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 20, 2023 at 3:25=E2=80=AFPM Tejun Heo wrote: > > Hello, > > A pool_workqueue (pwq) represents the connection between a workqueue and = a > worker_pool. One of the roles that a pwq plays is enforcement of the > max_active concurrency limit. Before 636b927eba5b ("workqueue: Make unbou= nd > workqueues to use per-cpu pool_workqueues"), there was one pwq per each C= PU > for per-cpu workqueues and per each NUMA node for unbound workqueues, whi= ch > was a natural result of per-cpu workqueues being served by per-cpu pools = and > unbound by per-NUMA pools. > > In terms of max_active enforcement, this was, while not perfect, workable= . > For per-cpu workqueues, it was fine. For unbound, it wasn't great in that > NUMA machines would get max_active that's multiplied by the number of nod= es > but didn't cause huge problems because NUMA machines are relatively rare = and > the node count is usually pretty low. > Hello, Tejun The patchset seems complicated to me. For me, reverting a bit to the behav= ior of 636b927eba5b ("workqueue: Make unbound workqueues to use per-cpu pool_workqueues"), like the following code (untested, just for showing the idea), seems simpler. max_active will have the same behavior as before if the wq is configured with WQ_AFFN_NUMA. For WQ_AFFN_{CPU|SMT|CACHE}, the problem isn't fixed. Thanks Lai diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 2989b57e154a..d0f133f1441b 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4364,8 +4364,16 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, ctx->dfl_pwq->refcnt++; ctx->pwq_tbl[cpu] =3D ctx->dfl_pwq; } else { + int head_cpu; + wq_calc_pod_cpumask(new_attrs, cpu, -1); - ctx->pwq_tbl[cpu] =3D alloc_unbound_pwq(wq, new_att= rs); + head_cpu =3D cpumask_first(new_attrs->__pod_cpumask= ); + if (!ctx->pwq_tbl[head_cpu]) { + ctx->pwq_tbl[cpu] =3D alloc_unbound_pwq(wq, new_attrs); + } else { + ctx->pwq_tbl[head_cpu]->refcnt++; + ctx->pwq_tbl[cpu] =3D ctx->pwq_tbl[head_cpu= ]; + } if (!ctx->pwq_tbl[cpu]) goto out_free; }