A 40ms Go garbage collector pause caused by swap
Running Go with swap enabled can cause severe stop-the-world garbage collector pauses when the Linux kernel pages out internal GC metadata.
read it It provides concrete BPF-backed measurements and runtime analysis showing how swap interacts destructively with Go's garbage collector metadata.
summary
The author investigated unexpected latency spikes in a Go service running under memory pressure with swap enabled. Using BPF tracing, they discovered that Go's garbage collector metadata—kept outside the heap and read during stop-the-world phases—was being evicted to swap. When the STW pause occurred, reading this metadata triggered major page faults, accounting for 39ms of a 40ms pause. This demonstrates that swap can transform standard memory pressure into global application stalls via runtime bookkeeping.
key points
- Go's GC metadata pages are reused rather than freed, making them prime targets for age-based kernel swap eviction under memory pressure.
- BPF tracing revealed that a 40ms stop-the-world pause was dominated by 228 major page faults taking nearly 39ms of disk wait time.
- Because these page faults happen during a stop-the-world pause, all goroutines freeze, stalling asynchronous I/O handling.
who should read it
Go backend engineers running production services under tight memory limits.
discussion positive
consensus
Commenters debate whether tracing garbage collectors are fundamentally incompatible with swap, with many arguing that swap should be disabled entirely for latency-sensitive Go applications.
pushback
A few push back, noting that disabling swap merely shifts memory pressure to code pages and advocating for mlock() instead.
Please read the article. The issue was caused by swapped out metadata being read in a critical section, not typical heap traversal shenanigans.
This is not exclusive to GC, any program that reads a rarely accessed piece of memory is vulnerable to this.
It clarifies that the issue of swapped-out memory read during critical sections can impact any program, not just garbage-collected languages.
Generated by an LLM from the article and thread. Check the sources before relying on it.