Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2683425rdb; Tue, 26 Dec 2023 01:13:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiz9kUI426sqrXOhcqLyoRRfAaPn1fY2xCOzr1Yq4OJxMKgWs1TMm4tyz7jrYt8wwS8pm+ X-Received: by 2002:a05:622a:138b:b0:423:b6a1:206e with SMTP id o11-20020a05622a138b00b00423b6a1206emr10247683qtk.5.1703581996495; Tue, 26 Dec 2023 01:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703581996; cv=none; d=google.com; s=arc-20160816; b=BI8Zyh6IkLJKTSWPE5ilQ39cnZ05k3C4+LZfeqY2RHiJOixwZFpdBZ1Y3UnRvJ/ipR MpbCOKFnyaTCjbLXtfZRNCmTGscBrsyUdkI+ubFPu3K5/BUxAwvbxMVs8ewEqkWdY4Gg CkffC8XG8hM5UIG0Qw1b0quelEqZHgU0Qt0ZVSQuHS7IxwWuJEyFNwY76OSiG56hWwyS nlFRTDxZoqjAfVwJVk0nRmSlRAS6D/bSk11ObH8+ECkubC7307PFUMO8dTOiKLRjqN3C 6QGAuGZGuTet0tcTH1bU6w1xkvOgN8fIsUdv9kuDIrz3lzrPuuPniZzntbduj6SP/Lrs FLkg== 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=oD5iK0F1iadCeZ+DhemgQrO1IM36iKgwfZ0udGFoLoc=; fh=x4smHwPOFOw21iBdSC3OpOhG6G0fYH4M8HPWFGpCrr4=; b=Gzr9uc9C9Qk5H1mqKh7U1DYtAAXjQ45pil1oTz/tREnYsfFlYSuSdayX9KLmHFJdYh 6qGIvXxZAZQGB2Ls56ufvvpNHUDMwyfQRdu8KUM7fM9+YWu+l0dsZpwvpDj4tJ1F80iI QJ0O3kkKvkORTZNRTbNzwXvdrbiiXBsgF8KbeqXQaZJ2eeJfKSqZq0DMuRKJ79/Cj8YV rtuR/arCwtWn/IQP/bWTxavGmZqNPNb+aB7AWyH+RzUHScwBjofejYO9QKXuk4c/pMnr m2Fam1xiJLRV4lDlniYvKHws+QnGVs6z368Bw8aJepiAPK64N8qfYQHUEgfVd1O7iCKy s2Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IeE+81tO; spf=pass (google.com: domain of linux-kernel+bounces-11433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11433-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v22-20020a05622a131600b0042543843087si12070672qtk.552.2023.12.26.01.13.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 01:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IeE+81tO; spf=pass (google.com: domain of linux-kernel+bounces-11433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11433-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 42D941C21DA8 for ; Tue, 26 Dec 2023 09:13:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F329D4CE18; Tue, 26 Dec 2023 09:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IeE+81tO" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 0DEEF4CE09 for ; Tue, 26 Dec 2023 09:13:07 +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-pj1-f44.google.com with SMTP id 98e67ed59e1d1-28b82dc11e6so1534703a91.1 for ; Tue, 26 Dec 2023 01:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703581987; x=1704186787; 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=oD5iK0F1iadCeZ+DhemgQrO1IM36iKgwfZ0udGFoLoc=; b=IeE+81tOJAXZQhTdPWzk++po3nJuGIam5/eeImhtyxclYsrs7NOj2tSm5vNOB6wh0b WV/BPPvboHICjgIDQ6D4r+ldET+9D6tBeim/ArX7GvKksHIxKjAGWB3YzlzmhzsOmz+y OsHA9NOCAXSp+zB/lYd4gP5yHVU9m1D9823Qj5kJ2NN4BYhmQUCkgplYYMAoixE2lk8M SPKEDGyQPrlptroaEMZPBobOlE5DyrxBmtBmgUW+lu7XMuKJ3FaUfF3LV4OpPmfLH2Wl H467u03H9M5KB0CshYu95mYYOn8xBu8q6pb/ciYXB2MSLqgj+YZdSVbX1o1uXMw1F9dL DQbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703581987; x=1704186787; 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=oD5iK0F1iadCeZ+DhemgQrO1IM36iKgwfZ0udGFoLoc=; b=bshO24K4mgqPy9qJsUVneUVza6nQUJRPCBbioHrKSwSYBkkMeAwfv5FHD2l9VVOd/I wyxKni9yWrJVWyvIS/bQ2Fipxod5AVIj3zlz5kal5cuoQ8drdthRmZWuKUGYoyM6VZ64 gGKlQFjeEB045poNibBGNQYYeUXdi5wF21aW/GJRhWbPmSmfZiz4WY5Pz4oanjFNDJrP AeqEq3za+E7ML5KsgBehkXkOC1bqRKHnBqbK+JSLMxAsLFXzphuQ/nKYqhYvlV44Hlfz EE08AOBIw0tRa9sUnssPwVE14VGecSSPw+GwO+X5zKF3oNaDH1/tzZa7FzaBcrvh0MgV /xgA== X-Gm-Message-State: AOJu0Yz2y1mPGB+6My9yB81UWl51tkxi9qf40iB+edo/LGywmVvelgSi WtuJ8AVG/bBcI/W4punhRZRzx80R3FINYVreAfuMIQtb X-Received: by 2002:a17:90b:2388:b0:28c:687c:299 with SMTP id mr8-20020a17090b238800b0028c687c0299mr257230pjb.71.1703581987271; Tue, 26 Dec 2023 01:13:07 -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> <20231220072529.1036099-5-tj@kernel.org> In-Reply-To: <20231220072529.1036099-5-tj@kernel.org> From: Lai Jiangshan Date: Tue, 26 Dec 2023 17:12:55 +0800 Message-ID: Subject: Re: [PATCH 04/10] workqueue: Move nr_active handling into helpers 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: > +static bool pwq_tryinc_nr_active(struct pool_workqueue *pwq) > { > - struct work_struct *work =3D list_first_entry(&pwq->inactive_work= s, > - struct work_struct, e= ntry); > + struct workqueue_struct *wq =3D pwq->wq; > + struct worker_pool *pool =3D pwq->pool; > + bool obtained; > > - pwq_activate_work(pwq, work); > + lockdep_assert_held(&pool->lock); > + > + obtained =3D pwq->nr_active < wq->max_active; It is better to use READ_ONCE(wq->max_active) here in case the compiler issues code to calculate "obtained" multi-time. Theoretically, READ_ONCE(wq->max_active) is recommended from the patch1 in pwq_dec_nr_in_flight() and __queue_work() since there is no wq->mutex for them. > + > + if (obtained) > + pwq->nr_active++; > + return obtained; > +} > +