title: Golang: why runtime.GOMAXPROCS is limited to 256?
body: <p>I was playing with golang 1.7.3 on MacBook and Ubuntu and found that runtime.GOMAXPROCS is limited to 256. Does anyone know where this limit comes from? Is this documented anywhere and why would there be a limit? Is this an implementation optimization?</p>
  
  <p>Only reference to 256 I could find is on this page that describes golang's runtime package: <a href="https://golang.org/pkg/runtime/" rel="nofollow noreferrer">https://golang.org/pkg/runtime/</a>. The runtime.MemStats struct has a couple of stat arrays of size 256:</p>
  
  <pre><code>type MemStats struct {
      ...
      PauseNs       [256]uint64 // circular buffer of recent GC pause durations, most recent at [(NumGC+255)%256]
      PauseEnd      [256]uint64 // circular buffer of recent GC pause end times
  </code></pre>
  
  <p>Here's example golang code I used:</p>
  
  <pre><code>func main() {
      runtime.GOMAXPROCS(1000)
  log.Printf("GOMAXPROCS %d\n", runtime.GOMAXPROCS(-1))
  </code></pre>
  
  <p>}</p>
  
  <p>Prints
      GOMAXPROCS 256</p>
  
  <p>P.S. 
  Also, can someone point me to documentation on how this GOMAXPROCS relate to OS thread count used by golang scheduler (if at all). Shall we observe go-compiled code running GOMAXPROCS OS threads?</p>
  
  <p><strong>EDIT:</strong> Thanks @twotwotwo for pointing out how GOMAXPROCS relate to OS threads. Still it's interesting that documentation does not mention this 256 limit (other that in the MemStats struct which may or may not be related).</p>
  
  <p>I wonder if anyone is aware of the true reason for this 256 number.</p>