Tuning GOMEMLIMIT vs GOGC in Memory-Constrained Containers
Before Go 1.19 introduced GOMEMLIMIT, services running inside cgroup-limited containers frequently suffered sudden OOM kills whenever live heap doubled during a burst before GOGC=100 triggered a cycle.
Setting GOMEMLIMIT to roughly 80–85% of the container memory limit gives the garbage collector headroom for non-heap runtime structures, goroutine stacks, and OS page cache.
The runtime includes built-in CPU throttling so that if live heap genuinely approaches the limit, Go sacrifices allocation throughput gracefully rather than entering a 100% CPU GC death spiral.
GOMEMLIMIT=1700MiB
GOGC=100