Skip to content

Free cached BTF and verifier log to reduce memory use#668

Merged
brb merged 1 commit into
mainfrom
gray/flushbtf
Apr 10, 2026
Merged

Free cached BTF and verifier log to reduce memory use#668
brb merged 1 commit into
mainfrom
gray/flushbtf

Conversation

@jschwinger233

Copy link
Copy Markdown
Member

pprof/heap shows:

(pprof) top
Showing nodes accounting for 12116.15kB, 100% of 12116.15kB total Showing top 10 nodes out of 32
      flat  flat%   sum%        cum   cum%
    5180kB 42.75% 42.75%     5180kB 42.75%  golang.org/x/sys/unix.ByteSliceToString
    3078kB 25.40% 68.16%     3078kB 25.40%  runtime.allocm
 1408.02kB 11.62% 79.78%  2321.85kB 19.16%  github.com/cilium/ebpf/btf.newDecoder
  913.83kB  7.54% 87.32%   913.83kB  7.54%  github.com/cilium/ebpf/btf.newFuzzyStringIndex
  512.22kB  4.23% 91.55%   512.22kB  4.23%  runtime.malg
  512.05kB  4.23% 95.77%   512.05kB  4.23%  github.com/cilium/ebpf/features.init
  512.03kB  4.23%   100%  5692.03kB 46.98%  github.com/cilium/ebpf.newProgramWithOptions
         0     0%   100%  5692.03kB 46.98%  github.com/cilium/ebpf.(*collectionLoader).loadProgram
         0     0%   100%  5692.03kB 46.98%  github.com/cilium/ebpf.NewCollectionWithOptions
         0     0%   100%  2321.85kB 19.16%  github.com/cilium/ebpf/btf.LoadKernelSpec

The String* and cilium/ebpf/* related heap objects are mainly for bpf verifier log and cached BTF, I believe we don't need them after loading and attaching.

This patch frees the references to verifier log and cached BTF, manages to cut 33% memory from 30M to 20M.

The new pprof/heap top has no big stale cilium/ebpf/* heap objects:

(pprof) top
Showing nodes accounting for 6667.79kB, 100% of 6667.79kB total Showing top 10 nodes out of 19
      flat  flat%   sum%        cum   cum%
 5643.01kB 84.63% 84.63%  5643.01kB 84.63%  runtime.allocm
  512.56kB  7.69% 92.32%   512.56kB  7.69%  github.com/cilium/ebpf/features.init
  512.22kB  7.68%   100%   512.22kB  7.68%  runtime.malg
         0     0%   100%   512.56kB  7.69%  runtime.doInit (inline)
         0     0%   100%   512.56kB  7.69%  runtime.doInit1
         0     0%   100%   512.56kB  7.69%  runtime.main
         0     0%   100%     2052kB 30.77%  runtime.mcall
         0     0%   100%     3591kB 53.86%  runtime.mstart
         0     0%   100%     3591kB 53.86%  runtime.mstart0
         0     0%   100%     3591kB 53.86%  runtime.mstart1

Signed-off: gray greyschwinger@gmail.com

pprof/heap shows:

(pprof) top
Showing nodes accounting for 12116.15kB, 100% of 12116.15kB total
Showing top 10 nodes out of 32
      flat  flat%   sum%        cum   cum%
    5180kB 42.75% 42.75%     5180kB 42.75%  golang.org/x/sys/unix.ByteSliceToString
    3078kB 25.40% 68.16%     3078kB 25.40%  runtime.allocm
 1408.02kB 11.62% 79.78%  2321.85kB 19.16%  github.com/cilium/ebpf/btf.newDecoder
  913.83kB  7.54% 87.32%   913.83kB  7.54%  github.com/cilium/ebpf/btf.newFuzzyStringIndex
  512.22kB  4.23% 91.55%   512.22kB  4.23%  runtime.malg
  512.05kB  4.23% 95.77%   512.05kB  4.23%  github.com/cilium/ebpf/features.init
  512.03kB  4.23%   100%  5692.03kB 46.98%  github.com/cilium/ebpf.newProgramWithOptions
         0     0%   100%  5692.03kB 46.98%  github.com/cilium/ebpf.(*collectionLoader).loadProgram
         0     0%   100%  5692.03kB 46.98%  github.com/cilium/ebpf.NewCollectionWithOptions
         0     0%   100%  2321.85kB 19.16%  github.com/cilium/ebpf/btf.LoadKernelSpec

The *String* and cilium/ebpf/* related heap objects are mainly for bpf
verifier log and cached BTF, I believe we don't need them after loading
and attaching.

This patch frees the references to verifier log and cached BTF, manages
to cut 33% memory from 30M to 20M.

The new pprof/heap top has no big stale cilium/ebpf/* heap objects:

(pprof) top
Showing nodes accounting for 6667.79kB, 100% of 6667.79kB total
Showing top 10 nodes out of 19
      flat  flat%   sum%        cum   cum%
 5643.01kB 84.63% 84.63%  5643.01kB 84.63%  runtime.allocm
  512.56kB  7.69% 92.32%   512.56kB  7.69%  github.com/cilium/ebpf/features.init
  512.22kB  7.68%   100%   512.22kB  7.68%  runtime.malg
         0     0%   100%   512.56kB  7.69%  runtime.doInit (inline)
         0     0%   100%   512.56kB  7.69%  runtime.doInit1
         0     0%   100%   512.56kB  7.69%  runtime.main
         0     0%   100%     2052kB 30.77%  runtime.mcall
         0     0%   100%     3591kB 53.86%  runtime.mstart
         0     0%   100%     3591kB 53.86%  runtime.mstart0
         0     0%   100%     3591kB 53.86%  runtime.mstart1

Signed-off: gray <greyschwinger@gmail.com>
@jschwinger233 jschwinger233 requested a review from a team as a code owner April 10, 2026 04:36
@jschwinger233 jschwinger233 requested review from smagnani96 and removed request for a team April 10, 2026 04:36

@brb brb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@brb brb merged commit 544f08e into main Apr 10, 2026
10 checks passed
@brb brb deleted the gray/flushbtf branch April 10, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants