Skip to content

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

Merged
not-matthias merged 2 commits into
mainfrom
cod-3417-depot-runner-migration-breaks-memtrack
Sep 4, 2026
Merged

feat(memtrack): fail early when the kernel has no BTF#524
not-matthias merged 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 (03a0288) with main (6ecb3c0)

Open in CodSpeed

@not-matthias
not-matthias force-pushed the cod-3417-depot-runner-migration-breaks-memtrack branch 3 times, most recently 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 the memory-tracking eBPF programs and improves diagnostics for unsupported or inaccessible runner environments.

  • Extracts kernel-release lookup for reuse in diagnostics.
  • Distinguishes a missing BTF file from other filesystem access errors.
  • Exposes the new kernel-BTF capability API from the memtrack crate.

Confidence Score: 5/5

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

Important Files Changed

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

Comment thread crates/memtrack/src/kernel.rs Outdated

@GuillaumeLagrange GuillaumeLagrange left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ogltm

Comment thread crates/memtrack/src/kernel.rs Outdated
@not-matthias
not-matthias force-pushed the cod-3417-depot-runner-migration-breaks-memtrack branch from c4ce665 to 98d09b9 Compare September 3, 2026 17:32
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 98d09b9 to 03a0288 Compare September 4, 2026 07:37
@not-matthias
not-matthias merged commit 03a0288 into main Sep 4, 2026
48 checks passed
@not-matthias
not-matthias deleted the cod-3417-depot-runner-migration-breaks-memtrack branch September 4, 2026 08:52
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.

2 participants