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 18C773EB0ED for ; Fri, 26 Jun 2026 09:58:16 +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=1782467897; cv=none; b=UhMAExKibxAhuwbRn04eicki8HKfcTu/f/rKyRBwRObo2tKO58177yVgfONmqmUX433vVKWU/raJ0vJUAzEW8rUYuz1Rxn49JK3hv6gPk0tAdUV7Mt7XYPOYebRnQ99x5kpAgdH6J2tn3DhvgBpGvgSAw5ZM1rX57yWzK2gEkXI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782467897; c=relaxed/simple; bh=9SM7BMtE6cV/+0WirydoEGbYzWWPhfBzJArRzGcg938=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PZKcTzA87p0yXT76AcLjyYI8sXlzTIop8NGHiHnY3Jko4imF8IO2c60pnujCnpM3rMyePrJijpmkuWaFJdw7RxnxBznOpSHoozMo2mfhbsNMHp5wPjUGIz6+i9Hsvbk/WNNvkoAKHVhIiPcvchqvEQcTRyzhC9rLksIzPuow9mw= 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=O+Q3Ltm5; 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="O+Q3Ltm5" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=EKQw+3JUYxhDEeXNheHNpTCpJ+pSfNS+aXYxEds3PIU=; b=O+Q3Ltm5w7InsMU/Y81z56Y8ef VckckKzgmU4RfiiXh4KMskmokNt/bTKY4tdV+enFL2iKPoNBqe6TfuNkPPdXLKt6sl0JopHpI+JKn BR6WKoDN8kuPIGmt41kHP62NaWjkpscrZLDJ20/ngOrSOQUiMfTVZJtGKYPR0SShif905Ba8T9Av6 /TWPtjt0deEtmwY99J7x0HvyLLyibMaby4t5vzsLowlJxO2VA5JqOFTY8e6sZZ5VJ8fxCGo3v/t2B VD8HpFSonK3tkLZRfhbcya4YmmaKQ9EBAjgGJln5KUT7s2jLoVxMJdloRwx5Ik1W4NBBxKowQiSwn pVzD+5Iw==; 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 1wd3K6-003t4Q-2t; Fri, 26 Jun 2026 09:58:11 +0000 From: Breno Leitao Date: Fri, 26 Jun 2026 02:57:54 -0700 Subject: [PATCH v5 2/3] workqueue: defer the worker wakeup outside pool->lock in __queue_work() 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: 7bit Message-Id: <20260626-fastwake-v5-2-9ae2f1867234@debian.org> References: <20260626-fastwake-v5-0-9ae2f1867234@debian.org> In-Reply-To: <20260626-fastwake-v5-0-9ae2f1867234@debian.org> To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, marco.crivellari@suse.com, frederic@kernel.org, bigeasy@linutronix.de, Hillf Danton , Breno Leitao , kernel-team@meta.com, kmagar@redhat.com, psuriset@redhat.com, david.dai@linux.dev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1577; i=leitao@debian.org; h=from:subject:message-id; bh=9SM7BMtE6cV/+0WirydoEGbYzWWPhfBzJArRzGcg938=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqPk0m4S30HWtl4T74tPstEDV1ahZQQvtdw7ZN3 8awH3BwY/OJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaj5NJgAKCRA1o5Of/Hh3 bUr+D/46vnX5m1iElgOUv0GCv7fF4uhKvzJFkS4njBqBfk/cm7wYpTDqFlSYm0DLLozSlFtVkP1 JTPt9LPREGZsebU2gAGmi1mJj4m05XdC9Zb9EWMPq8AluiBe/H5lehthHm7M0SY4C6VRdIPJsDa fEpDhg3v9CVvbQp7UQFoFkwgQcjYUtMXsA+BqhrKELV0MM/Jjdg0LWkcyLRy8MekH7Em8UNrrsk vccsKTOB6pXZUtSbc/vudg12nLPRg/3kfazW/+Xy2fv+v4w4J3G5E2vBAzoHW7xegOL0Y5LqiWG 1luKCBfqu/za13e07k70DcX7dVJcVYOXxrFcbNThuYSe8tyWxvALYeB7yOX167Ur1pBIpvzunqu WQ2nR0MOZFc3C8nNsZTXm7xHkGHUw07RtPZvC+JqSZf3S5K99IDE229HYbtyNzj3D0rwxEpg84c nmyZxubiey6TeQLigpHSInhU8z5H1WrnjNKrYoqQrwDzUEqrfjJo3KnR8Mb6Fl67IsUEDAW4eCr k/5p9JY3E/kCHROAczpj2fF3LjeNijfS2VxmK4JiiaJ//qES1PNyQ25xGjl+hwVzi3o9sZeKs3g o312ZflkCGH81uDZClNULILhL+IJqQjWw8suTpVSPQw6zQeEg6eNfIIHlcEtZbCA2Uh+xGpb85N rKK0XkezXsJNnoA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao __queue_work() is the enqueue hot path: it inserts the work item and calls kick_pool() while holding pool->lock. kick_pool() ends in a wakeup, which takes the target task's rq->lock, so rq->lock nests under pool->lock on every enqueue that wakes a worker on a contended unbound pool. Use kick_pool_pick() to select and claim the worker under pool->lock and issue the wakeup with wake_up_process() right after dropping the lock. Signed-off-by: Breno Leitao --- kernel/workqueue.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index e855d15c1fb7b..594592768ef10 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2302,6 +2302,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq, { struct pool_workqueue *pwq; struct worker_pool *last_pool, *pool; + struct task_struct *wake_task = NULL; unsigned int work_flags; unsigned int req_cpu = cpu; @@ -2424,7 +2425,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq, trace_workqueue_activate_work(work); insert_work(pwq, work, &pool->worklist, work_flags); - kick_pool(pool); + kick_pool_pick(pool, &wake_task); } else { work_flags |= WORK_STRUCT_INACTIVE; insert_work(pwq, work, &pwq->inactive_works, work_flags); @@ -2432,6 +2433,8 @@ static void __queue_work(int cpu, struct workqueue_struct *wq, out: raw_spin_unlock(&pool->lock); + if (wake_task) + wake_up_process(wake_task); rcu_read_unlock(); } -- 2.53.0-Meta