warmThreads brings the worker's thread set to steady state BEFORE it reads the readiness probe, i.e. before the supervisor measures the baseline the memory cap is relative to (supervisor.go armCap). Every P runs an allocating goroutine at once, so the runtime starts an M for each, and a GC starts it
()
| 80 | // otherwise come out of that job's budget: on a cgo build each reserves an |
| 81 | // 8 MiB stack, and CI measured the growth this closes. |
| 82 | func warmThreads() { |
| 83 | n := runtime.GOMAXPROCS(0) |
| 84 | var wg sync.WaitGroup |
| 85 | start := make(chan struct{}) |
| 86 | for range n { |
| 87 | wg.Add(1) |
| 88 | go func() { |
| 89 | defer wg.Done() |
| 90 | <-start |
| 91 | var keep [][]byte |
| 92 | for range 32 { |
| 93 | keep = append(keep, make([]byte, 64<<10)) |
| 94 | } |
| 95 | runtime.KeepAlive(keep) |
| 96 | }() |
| 97 | } |
| 98 | close(start) |
| 99 | wg.Wait() |
| 100 | runtime.GC() |
| 101 | } |
| 102 | |
| 103 | // serveWorker is RunWorker's loop over an already-loaded Runner. Split out so |
| 104 | // the tests of the loop share one loaded bundle instead of paying the load |