From 31cf1c17792d4da9dae2504c703633a0db8072c7 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 7 Apr 2016 11:47:32 +1200 Subject: [PATCH] runtime: clamp OS-reported number of processors to _MaxGomaxprocs So that all Go processes do not die on startup on a system with >256 CPUs. I tested this by hacking osinit to set ncpu to 1000. Updates #15131 Change-Id: I52e061a0de97be41d684dd8b748fa9087d6f1aef Reviewed-on: https://go-review.googlesource.com/21599 Reviewed-by: Brad Fitzpatrick --- src/runtime/proc.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 5145c84aea8..1f55b0fa21a 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -449,6 +449,9 @@ func schedinit() { sched.lastpoll = uint64(nanotime()) procs := int(ncpu) + if procs > _MaxGomaxprocs { + procs = _MaxGomaxprocs + } if n := atoi(gogetenv("GOMAXPROCS")); n > 0 { if n > _MaxGomaxprocs { n = _MaxGomaxprocs