BlogsCloudflareGo Runtime Stack Management

Go Runtime Stack Management

Go Runtime Stack Management

1
posts
2014

Cloudflare's engineering blog has explored the intricacies of Go's runtime, focusing on how it manages goroutine stacks. Initially, segmented stacks were used, allowing stacks to grow and shrink on demand. However, the 'hot split' problem, where shrinking stacks incurred significant overhead, led to a transition to stack copying. This new method doubles the stack size when growth is needed and copies the old segment, making shrinking a free operation. The implementation relies on garbage collection information to update pointers within the stack. This evolution aims to make goroutines more efficient and cost-effective for a wide range of tasks.

2014

How Stacks are Handled in Go

9/15/2014

This post details the evolution of Go's stack management from segmented stacks to stack copying. It explains the mechanics of segmented stacks, including stack splits and the 'lessstack' function, and highlights the 'hot split' problem. It then introduces stack copying, explaining how it addresses the shrinking overhead by doubling stack size and copying data, and discusses the reliance on garbage collection information for pointer updates. The post also touches upon the challenges of rewriting the Go runtime in Go to enable stack copying for all parts of the system and briefly discusses the limitations of virtual memory for stack allocation.