Skip to content

feat(memtrack): fail early when the kernel has no BTF - #524

Open
not-matthias wants to merge 2 commits into
mainfrom
cod-3417-depot-runner-migration-breaks-memtrack
Open

feat(memtrack): fail early when the kernel has no BTF#524
not-matthias wants to merge 2 commits into
mainfrom
cod-3417-depot-runner-migration-breaks-memtrack

Conversation

@not-matthias

@not-matthias not-matthias commented Aug 31, 2026

Copy link
Copy Markdown
Member

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_btf program against it as well. Without /sys/kernel/btf/vmlinux the 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:

pub struct KernelBtf;

impl KernelBtf {
    pub fn is_available() -> bool;
    pub fn ensure_available() -> Result<()>;
}

The error names the running kernel and the config option to look for:

Memory profiling is not supported on this runner: its kernel (7.2.0) was built
without BTF, so /sys/kernel/btf/vmlinux does not exist. Use a runner whose kernel
is built with CONFIG_DEBUG_INFO_BTF=y.

The first commit is a pure refactor extracting the /proc/sys/kernel/osrelease read out of KernelVersion::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-targets clean.
  • Detection exercised on a BTF-having host: is_available() returns true, ensure_available() returns Ok, and the failure message renders with the real kernel release.

Notes for review

is_available is not unit-testable as written because the path is a hardcoded const. If coverage is wanted, it can take the path as a parameter behind a private helper.

COD-3417

@codspeed-hq

codspeed-hq Bot commented Aug 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 17 untouched benchmarks


Comparing cod-3417-depot-runner-migration-breaks-memtrack (94ace38) with main (6ecb3c0)

Open in CodSpeed

@not-matthias
not-matthias force-pushed the cod-3417-depot-runner-migration-breaks-memtrack branch 2 times, most recently from 9ad7ffa to 7673460 Compare August 31, 2026 16:43
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
@not-matthias
not-matthias force-pushed the cod-3417-depot-runner-migration-breaks-memtrack branch from 7673460 to 94ace38 Compare August 31, 2026 16:47
@not-matthias
not-matthias marked this pull request as ready for review August 31, 2026 16:49
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

The 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.

  • Adds KernelBtf::is_available and KernelBtf::ensure_available.
  • Runs the preflight from both BPF variants before page-size and rmap detection.
  • Publicly re-exports the new kernel capability helper.

Confidence Score: 4/5

The 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

Important Files Changed

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.

Fix all with Greploop Fix All in Claude Code Fix All in Codex

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

Comment on lines +69 to +70
pub fn is_available() -> bool {
std::path::Path::new(Self::PATH).exists()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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:

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!

Fix in Claude Code Fix in Codex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant