From nobody Sat Jun 13 23:11:07 2026 Received: from outbound.baidu.com (mx13.baidu.com [220.181.3.100]) by smtp.subspace.kernel.org (Postfix) with SMTP id E9CC7386440 for ; Tue, 5 May 2026 09:04:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.181.3.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777971900; cv=none; b=HcNGAu/Rvte2ViZQ9dStjoVYKeY3t1W3bF6E+qclLczy4csl+pKlnjsWWRh75vYnVEUVP8qggnfBcLkEaMMvoLUOhwPDrD7Ax0MTxc4hf7lEevCAaNprHdMUAtILYw/Q0yfALPdW2c+r7d2k2hxJuXRq9Gy9lCv1YU0Ey/Hv55o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777971900; c=relaxed/simple; bh=XnzK+TaNX0ej6LPPslhAx8flbN5SXH0+8DimU/uB0qk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZPr+0zLfhiffXONO6esgLiY9njIOB2FSYT+Xy4YqZjqiAHcdPVKGuQKXOro9eJ/gBGFiqzYTr/05bJEElsYjYbg+Y/Nk7dVpUQWh+CkGLs30i81/fTr2OecI7VT99gVXHpEbBFoJhko5I4OwBPKsn0Xc395IOvpd2FA3/VKnOS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b=je/LTrR5; arc=none smtp.client-ip=220.181.3.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b="je/LTrR5" X-MD-Sfrom: lirongqing@baidu.com X-MD-SrcIP: 172.31.50.47 From: lirongqing To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , CC: Li RongQing Subject: [PATCH] sched/swait: Reduce lock contention in swake_up_all Date: Tue, 5 May 2026 05:04:31 -0400 Message-ID: <20260505090431.2423-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: bjkjy-exc5.internal.baidu.com (172.31.50.49) To bjkjy-exc3.internal.baidu.com (172.31.50.47) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baidu.com; s=selector1; t=1777971884; bh=1HqN0s59YlzeJNYjx5x+xijEc3ZhWBy7aq+ZWfwchw4=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=je/LTrR5nZoZYW8C4tMg/fh0+8R/adfmJEio02yx5/6GAtXjSokk8M7NiV19LZurN uuuhVF6qjC6izt51pPsEzVTiin/y323blhi8fkNn8b8H3Td2FSpHfYB6QRJD07gUEz mt1JPeoDgm/IYIJtyGJnk8QZGX6F+Wgapi59JIw7HmHiztj2KDK/G8aWEOL0MhX7+H +g5AdE8qaER7oXEmw426/b3AfgqvdYaZmcTrMy4JRIZnonVyUFyC27F1iAtjbNORNs TtZohyGvU+Dncb/eMTzn0hKbgdde1WtaW1ZBz7Qh/loktipWgn3hX9jjEHsyuhi7BT DYo+u+uiST0TA== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing The entire task list have been moved a local list under the lock, it is unnecessary to hold the lock to wake tasks, This reduces lock operations from O(n) to O(1). Move list_del_init before wake_up_state to prevent potential use-after-free if the woken task exits immediately and releases its memory. Signed-off-by: Li RongQing --- kernel/sched/swait.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/kernel/sched/swait.c b/kernel/sched/swait.c index 0fef649..ee4e658 100644 --- a/kernel/sched/swait.c +++ b/kernel/sched/swait.c @@ -66,19 +66,13 @@ void swake_up_all(struct swait_queue_head *q) =20 raw_spin_lock_irq(&q->lock); list_splice_init(&q->task_list, &tmp); + raw_spin_unlock_irq(&q->lock); while (!list_empty(&tmp)) { curr =3D list_first_entry(&tmp, typeof(*curr), task_list); =20 - wake_up_state(curr->task, TASK_NORMAL); list_del_init(&curr->task_list); - - if (list_empty(&tmp)) - break; - - raw_spin_unlock_irq(&q->lock); - raw_spin_lock_irq(&q->lock); + wake_up_state(curr->task, TASK_NORMAL); } - raw_spin_unlock_irq(&q->lock); } EXPORT_SYMBOL(swake_up_all); =20 --=20 2.9.4