You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a very simple tracepoint eBPF program, which does not need BTF.
But I notice that while the program is running, the memory usage is far more large than I expected
Investigation
After running the memory profile, I found the program contains lots of fragmental allocations.
and it doesn't return memory to OS
Memory exactly used:
Memory allocation in full lifetime:
Here, the Btf::from_sys_fs() is even called twice.
EbpfLoader doesn't give any chance to prevent BTF loading, it load BTF at the struct initialization.
After I remove the Btf::from_sys_fs() in the EbpfLoader, the memory usage after calling Ebpf::load reduce to half.
Once I manually build Ebpf from EbpfLoader, the heap allocation is reduced to 150 KiB
More
Although not my use case, there is still a lot of room for optimization in BTF loading, such as arena (like bumpalo?) and using stack allocation instead of Vec abusing.
The text was updated successfully, but these errors were encountered:
Although not my use case, there is still a lot of room for optimization in BTF loading, such as arena (like bumpalo?) and using stack allocation instead of Vec abusing.
I think it's worth leaving this issue open just for ☝
dave-tucker
changed the title
EbpfLoader should not load BTF from sys by default
Reduce memory footprint when loading BTF
Feb 21, 2025
Origin
I'm writing a very simple tracepoint eBPF program, which does not need BTF.
But I notice that while the program is running, the memory usage is far more large than I expected
Investigation
After running the memory profile, I found the program contains lots of fragmental allocations.
and it doesn't return memory to OS
Memory exactly used:

Memory allocation in full lifetime:

Here, the

Btf::from_sys_fs()
is even called twice.EbpfLoader
doesn't give any chance to prevent BTF loading, it load BTF at the struct initialization.aya/aya/src/bpf.rs
Line 157 in ade2e2a
and
Ebpf::load
causes the BTF double loadingaya/aya/src/bpf.rs
Lines 879 to 883 in ade2e2a
Fixing
After I remove the
Btf::from_sys_fs()
in theEbpfLoader
, the memory usage after callingEbpf::load
reduce to half.Once I manually build
Ebpf
fromEbpfLoader
, the heap allocation is reduced to 150 KiBMore
Although not my use case, there is still a lot of room for optimization in BTF loading, such as arena (like bumpalo?) and using stack allocation instead of
Vec
abusing.The text was updated successfully, but these errors were encountered: