From 1e436ba668f5988ca8fbeb68734800b9dcf33dbc Mon Sep 17 00:00:00 2001 From: Carlos Amedee Date: Wed, 30 Apr 2025 15:17:45 -0400 Subject: runtime: only poll network from one P at a time in findRunnable This change reintroduces CL 564197. It was reverted due to a failing benchmark. That failure has been resolved. For #65064 Change-Id: Ic88841d2bc24c2717ad324873f0f52699f21dc66 Reviewed-on: https://go-review.googlesource.com/c/go/+/669235 LUCI-TryBot-Result: Go LUCI Reviewed-by: Mauri de Souza Meneguzzo Reviewed-by: Michael Knyszek Reviewed-by: Michael Pratt --- src/runtime/proc.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/runtime/proc.go') diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 9753ba5378..1ca800c5fd 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -3396,8 +3396,12 @@ top: // blocked thread (e.g. it has already returned from netpoll, but does // not set lastpoll yet), this thread will do blocking netpoll below // anyway. - if netpollinited() && netpollAnyWaiters() && sched.lastpoll.Load() != 0 { - if list, delta := netpoll(0); !list.empty() { // non-blocking + // We only poll from one thread at a time to avoid kernel contention + // on machines with many cores. + if netpollinited() && netpollAnyWaiters() && sched.lastpoll.Load() != 0 && sched.pollingNet.Swap(1) == 0 { + list, delta := netpoll(0) + sched.pollingNet.Store(0) + if !list.empty() { // non-blocking gp := list.pop() injectglist(&list) netpollAdjustWaiters(delta) -- cgit v1.3-6-g1900