buildkitd retains ~16M live objects (~1.3 GB heap) after builds; only a restart releases it (v0.33.0, OCI worker)
Summary
On a dedicated build node, buildkitd retains memory after every successful build. RSS grows by roughly 115–146 MB per build and never comes back down: after ~11 builds the daemon holds 1.68 GB RSS / 1.27 GB HeapAlloc, while a freshly started daemon holds 62–73 MB. Only a daemon restart releases it, and the retained memory is live data — forcing runtime.GC() before profiling changes the heap by ~0.1%.
Environment
buildkitd github.com/moby/buildkit v0.33.0(commitdddd5621af), started as adocker-containerbuildx builder (buildx_buildkit_*), OCI worker with[worker.oci] enabled = trueandmax-parallelism = 1.- Host: 4 vCPU VM, 16 GiB RAM. The buildkitd container is capped at
memory=8 GiB,memory-swap=12 GiB. - Workload: one Node.js monorepo image per push (
pnpm install+ a Next.js production build + two application bundles), ~8–16 minutes per build, build cache kept at ~20 GiB, never more than one build at a time. - No other
buildkitdruns on this host. All numbers below are sampled while no build is running.
Measurements
Three independent sources, sampled every 10 s: Go runtime metrics from --debugaddr (go_memstats_heap_alloc_bytes, heap_inuse_bytes, heap_idle_bytes, heap_released_bytes, goroutines), VmRSS/VmHWM from /proc/<buildkitd pid>/status, and the container cgroup's memory.current / memory.stat / memory.events.
| point | RSS | HeapAlloc |
HeapObjects |
|---|---|---|---|
| right after daemon start | 62–73 MB | ~15 MB | – |
| after 11 successful builds (~24 h) | 1681 MB | 1269 MB | 16,471,085 |
≈ +146 MB RSS per build (≈ +115–139 MB in live-heap terms in earlier windows). The object count grows the same way: 7,077,752 → 16,471,085 over the same period.
What we ruled out
1. Cache size. We cleared the whole build cache (25.47 GB → 0). Live heap went 587 → 579 MB and live objects 7,077,752 → 7,066,571. The retained memory is not cache records.
2. Uncollected garbage. We triggered runtime.GC() via GET /debug/pprof/heap?debug=1&gc=1 (the measurement suggested in #6310) and compared the runtime ledger immediately before and after:
| metric | before | after forced GC |
|---|---|---|
HeapAlloc |
1269 MB | 1268 MB |
HeapObjects |
16,471,085 | 16,459,011 (−0.07%) |
HeapReleased |
1143 MB | 1143 MB |
NumGC / NumForcedGC |
891 / 0 | 892 / 1 |
VmRSS |
1681 MB | 1683 MB |
So the daemon is holding live objects rather than idle garbage, and a periodic GC cycle does not release them — GC had already run 891 times automatically, and one more forced cycle changed nothing.
3. Version. The behaviour is the same on v0.27.0 and v0.33.0. We upgraded to v0.33.0 hoping the v0.31.0 fix for the default GC policy would help (the filter in that rule never matched); it did not.
Heap profile (inuse_space, after a forced GC)
GET /debug/pprof/heap?gc=1, profile rate 131072 (we run with GODEBUG=memprofilerate=65536). Largest sampled in-use allocations by leaf frame:
1.0 MB go.etcd.io/bbolt/internal/freelist.(*shared).Free
0.7 MB github.com/hashicorp/go-immutable-radix/v2.(*Txn[...]).insert
0.4 MB github.com/hashicorp/go-immutable-radix/v2.(*Txn[...]).writeNode
0.4 MB bytes.Replace
0.2 MB github.com/moby/buildkit/cache/contenthash.(*cacheContext).scanPath.func2
0.1 MB github.com/moby/buildkit/cache/contenthash.(*cacheContext).checksumMetadata database sizes inside the daemon state directory at the same moment:
678 MB runc-overlayfs/metadata_v2.db
16 MB runc-overlayfs/containerdmeta.db
4 MB history.db
2 MB cache.dbCaveat: at a 128 KB sampling rate the profile only sees a small fraction of the live objects. MemStats reports 16.46M live objects averaging ~77 bytes, mostly below the sampling threshold, so the profile above does not explain the total on its own.
Questions
- Is retention of this magnitude known/expected? Which component is expected to hold ~16M small live objects — snapshotter metadata, the cache record index, or the content-hash cache?
- Is there a supported way to release it without restarting the daemon (a knob, a trim endpoint, a metadata DB compaction option)? We could not find one.
- Would a heap profile with
memprofilerate=1be useful? We can collect one on a disposable host if that is the fastest path — not on this node, since it is the only builder for our environments and a full build must stay inside an 8 GiB cap. - Is a daemon-level memory bound on the roadmap? We found no equivalent of
GOMEMLIMITor of a bounded metadata cache.
Related
- #4448 — open since 2023-11
- #6310 — closed as inconclusive; the reporter's workaround was configuring a GC cleanup cycle plus restarting the workers
- #3655, #2883, #1726 — closed
Notes
The node is shared with a test environment, so we keep the daemon capped at 8 GiB and restart it in idle windows; that is the only mitigation we have found. Attached measurements are from that host over 2026-09-17 … 2026-09-21.
Source: moby/buildkit