IT lexicon › Programming › Segmented stacks

Segmented stacks

Programming På svenska → Updated: 2026-11-06

Stacks that start small and grow in detached chunks, so a program can run hundreds of thousands of threads without reserving megabytes for each.

Every function gets an extra check in its prologue: is there room left in the current segment? If not, a helper called morestack allocates a fresh segment and carries on there. Ian Lance Taylor added support to GCC as -fsplit-stack in 2011, mainly for gccgo. Go used the technique for goroutines, and early Rust did the same.

Both gave up. The trouble was the "hot split": put a call inside a tight loop right at a segment boundary and a segment gets allocated and freed on every iteration, sending performance off a cliff in ways nobody could predict. Rust dropped segmented stacks in 2013. Go 1.3 switched in 2014 to contiguous stacks that are copied into a region twice the size when they run out — which only works because Go's garbage collector knows where every pointer into the stack lives.

← Back to the lexicon