btf: move LoadKernelSpec into separate package #1015
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
vmlinux BTF turns out to be a big headache, because it is quite large at roughly 150k types. The API we currently have in place forces a copy of the whole vmlinux btf.Spec on every call to LoadKernelSpec. We copy to prevent distinct callers of LoadKernelSpec from modifying types that may be referenced by someone else. As a result, some things that require access to kernel BTF are really slow: attaching fentry/fexit hooks, kfuncs, etc.
We've optimized the copying a little bit, but we can't get around the fact that there are a lot of objects to be copied so it's unlikely to get much faster. An attempt to copy btf.Spec lazily was abandoned due to it's complexity.
Which leaves us with this approach: the library shares a single kernel Spec and must take care to avoid mutating or exposing types contained therein. Users of the library always get a fresh copy and must themselves take care to cache the spec if necessary.
Due to import cycles this means we can't expose the kernel spec from package btf anymore and instead need a separate package. This will cause compilation errors, but they should be simple to fix since the semantics don't change otherwise.