Skip to content

Commit

Permalink
[btf] Flush kernel spec (BTF) after loading programs
Browse files Browse the repository at this point in the history
Do not cache BTF. Reload it when needed.

Signed-off-by: Anastasios Papagiannis <[email protected]>
  • Loading branch information
tpapagian committed Sep 20, 2024
1 parent 8ccba6c commit 247482f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/bpf/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ func HasMissedStatsKprobeMulti() bool {
}

func LogFeatures() string {
// once we have detected all features, flush the BTF spec
// we cache all values so calling again a Has* function will
// not load the BTF again
defer ebtf.FlushKernelSpec()
return fmt.Sprintf("override_return: %t, buildid: %t, kprobe_multi: %t, uprobe_multi %t, fmodret: %t, fmodret_syscall: %t, signal: %t, large: %t, link_pin: %t, lsm: %t, missed_stats_kprobe_multi: %t, missed_stats_kprobe: %t",
HasOverrideHelper(), HasBuildId(), HasKprobeMulti(), HasUprobeMulti(),
HasModifyReturn(), HasModifyReturnSyscall(), HasSignalHelper(), HasProgramLargeSize(),
Expand Down
7 changes: 7 additions & 0 deletions pkg/sensors/program/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@ func doLoadProgram(
return nil, fmt.Errorf("opening collection '%s' failed: %w", load.Name, err)
}
defer coll.Close()
// cleanup the BTF once we have loaded the program
defer btf.FlushKernelSpec()

err = installTailCalls(bpfDir, spec, coll, load)
if err != nil {
Expand Down Expand Up @@ -911,6 +913,11 @@ func doLoadProgram(

load.Prog = prog

// in KernelTypes, we use a non-standard BTF which is possibly annotated with symbols
// from kernel modules. At this point wewe don't need that anymore, so we can release
// the memory from it.
load.KernelTypes = nil

// Copy the loaded collection before it's destroyed
if KeepCollection {
return copyLoadedCollection(coll)
Expand Down

0 comments on commit 247482f

Please sign in to comment.