From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EADC429CE1 for ; Mon, 1 Jun 2026 17:27:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780334823; cv=none; b=J4wwlGzF1yxkl+bzKZn8p8GBFcAGJq7KmppD4loMcJZ3q8Wh7wxj441ypsmM/mJ5iPBkaiJ90GovVgDqshxAjVoIhn6JoDMhoe3L+7Pgp3B9QI6z0KvHSSElFVMGFR3h+HII1o0kzd5oeVHn14iasFMveRSQOm6gMEYuC+8mz0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780334823; c=relaxed/simple; bh=Ms+LD1BVS8sg3rCXQZpPyJl2vQPa2mgY05h2G5zSA+k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WzLHD+tScwxa9+VILZpJphSvmvoHjvl3ESECxMyAQpCyJeOG9VgPjkl46cFfc70bHoZV702GoAAHgUEHSJsVSpzn4xIwdhg/SrvT8XraCMEe2z4Afe2bGqZDohG1F2uS/F5PzIFfpWKGdGu/X4JP9xE3QCrHfCuHzqCZvTaWzuM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=OYBHomiJ; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="OYBHomiJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BTMLYeLMD1ugP8AxmFz33UGUqGw8/TT7aCSaUps2jPA=; b=OYBHomiJhpnM/maqt8lxZMRZyV EJBK1JAljdGs4h/4ghKd30qSZVe8c0CCx2UqfpyVk7iudHFLFCsGqd5cxISNKViOlHPt+NkRm/tn0 ac80xXJYZ4pyUOoajGrLWP1B3YF/fpX/18/V0DrwiM71e4KH+J2gQJlSVmL+t04RCJYJHYEbDwsaB uYQgvpQFvmANvtB6dWtZZ9kGL+XBa0Vij9PV/Vd7PLGjIOZNR6FOZuoN1EcBb88aeNuIArTuecqW+ Gmt89La8F9lgYXfOe1Ru5jKJV5mkyiesowHWJaFN7HzEezrLcLsA+lsqL2rHYWBbEYxT+Zj79leXo U9xgRfhw==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wU6Pa-002Kti-2p; Mon, 01 Jun 2026 17:26:51 +0000 Date: Mon, 1 Jun 2026 10:26:45 -0700 From: Breno Leitao To: Sebastian Andrzej Siewior Cc: Hillf Danton , Tejun Heo , Lai Jiangshan , linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org Subject: Re: [PATCH 2/2] workqueue: defer wake_up_process() outside pool->lock on hot paths Message-ID: References: <20260526-fastwake-v1-0-e69ad86923e6@debian.org> <20260526212346.1100-1-hdanton@sina.com> <20260527153500.ERVl3my3@linutronix.de> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260527153500.ERVl3my3@linutronix.de> X-Debian-User: leitao On Wed, May 27, 2026 at 05:35:00PM +0200, Sebastian Andrzej Siewior wrote: > On 2026-05-27 07:51:17 [-0700], Breno Leitao wrote: > > @@ -3447,7 +3459,13 @@ static int worker_thread(void *__worker) > > return 0; > > } > > > > - worker_leave_idle(worker); > > + /* > > + * Kicked workers have already been removed from pool->idle_list > > + * by kick_pool(); only first-time wakeups (via create_worker()) > > + * still arrive with WORKER_IDLE set. > > + */ > > + if (worker->flags & WORKER_IDLE) > > + worker_leave_idle(worker); > > Couldn't create_worker() be aligned here not set the idle flag and wake > the thread a few lines later? Then we wouldn't have to conditionally > clear the idle flag here (which sort of NULL renders the flag check in > worker_leave_idle()). I tried exactly that and it regresses worker creation, so I'd rather keep create_worker() as-is and leave the check in woke_up: conditional. create_worker() deliberately returns with the new worker still on pool->idle_list (counted in pool->nr_idle), and maybe_create_worker() depends on that. After a successful create_worker() it re-checks: need_to_create_worker() = need_more_worker() && !may_start_working() and may_start_working() is just pool->nr_idle. That nr_idle is the signal "I already created a worker that will pick up the pending work, stop creating". If create_worker() leaves the worker !WORKER_IDLE before the wakeup (or never enters idle), it returns with nr_idle unchanged. A fresh worker starts WORKER_PREP, so it doesn't bump nr_running until it actually runs. So until the woken kthread schedules in, the manager keeps seeing: need_more_worker() == true (worklist non-empty, nr_running 0) may_start_working() == false (nr_idle 0) and loops/goto restart, creating extra workers until one of the woken ones runs. Under scheduler latency that's a burst of surplus kworkers (eventually culled). So I kept create_worker() untouched and only claim the worker (off idle_list) in kick_pool(), with the conditional worker_leave_idle() in woke_up: covering the create_worker() path. --breno