feat(memtrack): fail early when the kernel has no BTF - #524
Conversation
Merging this PR will not alter performance
|
7673460 to
94ace38
Compare
Greptile SummaryThe PR adds an early kernel-BTF availability check before loading the memory-tracking eBPF programs and improves diagnostics for unsupported or inaccessible runner environments.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the active memory-tracker initialization path now preserves non-NotFound BTF access errors instead of misreporting them as missing kernel support.
|
| Filename | Overview |
|---|---|
| crates/memtrack/src/ebpf/memtrack/mod.rs | Adds the BTF preflight to the eBPF initialization path before program loading. |
| crates/memtrack/src/kernel.rs | Adds kernel-BTF detection with distinct diagnostics for missing files and other access failures, resolving the prior review issue. |
| crates/memtrack/src/lib.rs | Re-exports the new KernelBtf API alongside KernelVersion. |
Reviews (3): Last reviewed commit: "feat(memtrack): fail early when the kern..." | Re-trigger Greptile
c4ce665 to
98d09b9
Compare
libbpf resolves CO-RE relocations against the running kernel's own BTF, and the kernel resolves the attach target of every fentry/tp_btf program against it too, so a kernel without BTF cannot load the programs at all. libbpf reports this as a bare -ESRCH, which gives no hint about the cause. Check /sys/kernel/btf/vmlinux in MemtrackBpf::with_variant, where the load would otherwise fail, and report which kernel lacks it. COD-3417
98d09b9 to
03a0288
Compare
Problem
Memory mode fails on runners whose kernel is built without
CONFIG_DEBUG_INFO_BTF.libbpf resolves CO-RE relocations against the running kernel's own BTF, and the kernel resolves the attach target of every
fentry/tp_btfprogram against it as well. Without/sys/kernel/btf/vmlinuxthe programs cannot load at all — and libbpf surfaces this as a bare-ESRCH, which says nothing about the actual cause.Change
Preflight check in
MemtrackBpf::with_variant, where the load would otherwise fail:The error names the running kernel and the config option to look for:
The first commit is a pure refactor extracting the
/proc/sys/kernel/osreleaseread out ofKernelVersion::current, so the message can report the running release.Verification
cargo test --release -p memtrack— 19 passed, remainder are the pre-existing root/eBPF-gated ignored tests.cargo fmt --check,cargo clippy --all-targetsclean.is_available()returnstrue,ensure_available()returnsOk, and the failure message renders with the real kernel release.Notes for review
is_availableis not unit-testable as written because the path is a hardcodedconst. If coverage is wanted, it can take the path as a parameter behind a private helper.COD-3417