Skip to content
All writing Part 06 of 11 · From 19 Goroutines to Exit 137
Engineering · 2 min read

OOM Diagnostic Decision Tree: Drill Down from pprof

Start with the cheapest tool. A decision tree from pprof to runtime to cgroup that drills down to why your Go service is eating memory.

Start with the cheapest tool. Only drill to runtime → cgroup when pprof (Go’s built-in heap profiler, go tool pprof) can’t explain it.

The Decision Tree

pprof inuse_space large? YES function-level culprit found NO heap_alloc large? YES sampling missed; check alloc_space NO runtime gaps: inuse−alloc large? → fragmentation (scattered live objects pin spans) idle−released large? → scavenger lag both small? → compare RSS vs cgroup: ├─ similar → in-process leak └─ cgroup>>RSS → kernel memory (unclosed sockets, file cache)

Three Layers

  1. App layer (pprof): inuse_space identifies live heap hogs by function. If small, alloc_space catches high-churn functions (rapid alloc → GC → alloc that inuse misses at sample time).
  2. Runtime layer (Go metrics): heap_inuse − heap_alloc = fragmentation. heap_idle − heap_released = pages the allocator holds but hasn’t returned to the kernel (memory three-layer model, allocator internals).
  3. Kernel layer (cgroup): container_memory_usage_bytes − container_memory_rss = kernel-charged memory. A large gap means unclosed sockets, heavy file I/O, or kernel buffer bloat.

Role in This OOM

The culprit here wasn’t the Go heap. It was the browser sidecar’s memory. This decision tree helps rule out “Go’s own problems” and confirm the issue is outside the process (shared resource blast radius).

The order of diagnostic tools is the order of their cost: pprof (free) → runtime (low) → cgroup (needs Prometheus).

References:

Related: see memory three-layer model, allocator internals, and shared resource blast radius, or go back to the series overview.

Tags #go #concurrency #reliability
// connect

Be brave | Be wise | Be grateful

21 BreakinCode

// elsewhere
LinkedInMedium (lang: en)Life RecordYoutube
wh:~$William Hung· © 2026 Taipei · GMT+8 · Available for collaboration