feat(memtrack): fail early when the kernel has no BTF - #524
Conversation
Merging this PR will not alter performance
|
9ad7ffa to
7673460
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
7673460 to
94ace38
Compare
Greptile SummaryThe PR adds an early kernel-BTF availability check before loading memtrack’s eBPF programs and extracts kernel-release retrieval for a more actionable error message.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking diagnostic issue when kernel BTF is present but hidden or inaccessible through sysfs. The preflight correctly prevents an unsupported BPF load, but its boolean filesystem probe conflates genuine BTF absence with namespace, mount, and permission failures and consequently recommends the wrong remediation. Files Needing Attention: crates/memtrack/src/kernel.rs
|
| Filename | Overview |
|---|---|
| crates/memtrack/src/kernel.rs | Adds kernel release and BTF helpers; the availability probe produces misleading diagnostics when sysfs metadata cannot be accessed. |
| crates/memtrack/src/ebpf/memtrack/mod.rs | Adds the intended BTF preflight before either eBPF variant is loaded. |
| crates/memtrack/src/lib.rs | Publicly re-exports KernelBtf alongside KernelVersion, with no current compatibility issue identified. |
Prompt To Fix All With AI
### Issue 1
crates/memtrack/src/kernel.rs:69-70
**BTF probe hides access errors**
If the tracker runs where sysfs is absent, masked, or inaccessible, `Path::exists` returns false and the diagnostic states that the kernel was built without BTF. This sends users toward replacing or rebuilding the kernel instead of correcting sysfs visibility or access.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat(memtrack): fail early when the kern..." | Re-trigger Greptile
| pub fn is_available() -> bool { | ||
| std::path::Path::new(Self::PATH).exists() |
There was a problem hiding this comment.
If the tracker runs where sysfs is absent, masked, or inaccessible, Path::exists returns false and the diagnostic states that the kernel was built without BTF. This sends users toward replacing or rebuilding the kernel instead of correcting sysfs visibility or access.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/memtrack/src/kernel.rs
Line: 69-70
Comment:
**BTF probe hides access errors**
If the tracker runs where sysfs is absent, masked, or inaccessible, `Path::exists` returns false and the diagnostic states that the kernel was built without BTF. This sends users toward replacing or rebuilding the kernel instead of correcting sysfs visibility or access.
**Knowledge Base Used:**
- [Native profiling components](https://app.greptile.com/codspeed/-/custom-context/knowledge-base/codspeedhq/codspeed/-/docs/native-profiling-components.md)
- [eBPF memory tracker](https://app.greptile.com/codspeed/-/custom-context/knowledge-base/codspeedhq/codspeed/-/docs/ebpf-memory-tracker.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
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