The runtime / debug.SetMaxStack function only detects what indicates that the program is infinitely recursive and terminates it. http://golang.org/pkg/runtime/debug/#SetMaxStack
By setting it absurdly low, it does nothing for the minimum stack size and limits the maximum size only if your program crashes, if the size of the used stack exceeds the limit.
Technically, a crash occurs only when the stack needs to grow, so your program will die when the stack needs more than 8 KB (or 4 KB before transition 1.2).
The reason your program uses a minimum of 4KB * nGoroutines is because the stacks are page aligned, so there cannot be more than one stack on a VM page. Therefore, your program will use at least nGoroutines worth pages, and operating systems usually only measure and allocate memory in increments of page size.
The only way to change the initial (minimum) stack size is to change and recompile run run (and possibly the compiler too).
Go 1.3 will include continuous stacks, which are generally faster than split stacks in Go 1.2 and earlier, which may also lead to smaller initial stacks in the future.
source share