Skip to content

feat: speedup ebpf uprobe attaching#440

Open
not-matthias wants to merge 3 commits into
mainfrom
cod-3070-speedup-allocator-attaching-on-nixos
Open

feat: speedup ebpf uprobe attaching#440
not-matthias wants to merge 3 commits into
mainfrom
cod-3070-speedup-allocator-attaching-on-nixos

Conversation

@not-matthias

@not-matthias not-matthias commented Jul 7, 2026

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR speeds up memtrack allocator probe attachment. The main changes are:

  • Resolves allocator ELF symbol offsets once per library.
  • Attaches uprobes by resolved file offset instead of symbol name.
  • Resolves allocator offsets in parallel before serial probe attachment.
  • Adds a divan benchmark for serial and parallel offset resolution.

Confidence Score: 4/5

This is close, but the offset attach path should be fixed before merging.

  • A symbol that is present but not offset-resolvable can still be skipped without a fallback.
  • The tracker can then report incomplete allocation data for that allocator.

crates/memtrack/src/ebpf/memtrack.rs

Important Files Changed

Filename Overview
crates/memtrack/src/ebpf/memtrack.rs Changes allocator probe attachment to use precomputed ELF file offsets, but missing offset entries can still leave valid symbols uninstrumented.
crates/memtrack/src/ebpf/tracker.rs Delegates allocator attachment to the new batched MemtrackBpf path.
crates/memtrack/benches/attach.rs Adds benchmarks for serial and parallel allocator symbol-offset resolution.
crates/memtrack/Cargo.toml Adds rayon and divan support for the new attachment benchmark and parallel offset resolution.

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
crates/memtrack/src/ebpf/memtrack.rs:120-122
**Offset Misses Still Skip**

When `resolve_symbol_offsets` cannot produce a section-backed file offset for one allocator symbol, this branch returns before trying any symbol-name attach path. A discovered allocator can then have valid exported allocation entry points left uninstrumented with no retry and no visible error, so allocations through those symbols are silently missed. This path needs to fall back to libbpf's symbol attach behavior or make the missing required probe fail loudly instead of treating the allocator as attached.

Reviews (2): Last reviewed commit: "bench(memtrack): add offset resolution b..." | Re-trigger Greptile

Comment thread crates/memtrack/src/ebpf/memtrack.rs Outdated
Comment thread crates/memtrack/src/ebpf/memtrack.rs Outdated
Comment on lines +522 to +524
let offsets = names
.iter()
.filter_map(|name| symbol_offsets.get(name).copied())

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 Offset Filtering Drops Symbols

This collects only names that resolve_symbol_offsets can map to a section file offset. If one allocator symbol is a valid attach target but has no section-backed offset while another name in the same group does, the multi attach succeeds for the subset and the omitted symbol is never retried by the per-symbol fallback, so allocations through that symbol are silently missed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/memtrack/src/ebpf/memtrack.rs
Line: 522-524

Comment:
**Offset Filtering Drops Symbols**

This collects only names that `resolve_symbol_offsets` can map to a section file offset. If one allocator symbol is a valid attach target but has no section-backed offset while another name in the same group does, the multi attach succeeds for the subset and the omitted symbol is never retried by the per-symbol fallback, so allocations through that symbol are silently missed.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

Comment thread crates/memtrack/src/ebpf/memtrack.rs Outdated
{
Ok(output) => output,
Err(error) if error.kind() == ErrorKind::NotFound => {
eprintln!("skipping non-PIE symbol offset test: gcc is not installed");

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 Test Diagnostics Use Eprintln

The custom Rust rule forbids println! and eprintln! in favor of tracing macros. This new test skip diagnostic uses eprintln!, so the changed test code can fail a policy gate that enforces that rule.

Rule Used: Never use println!/eprintln! in Rust; use trac... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/memtrack/src/ebpf/memtrack.rs
Line: 873

Comment:
**Test Diagnostics Use Eprintln**

The custom Rust rule forbids `println!` and `eprintln!` in favor of tracing macros. This new test skip diagnostic uses `eprintln!`, so the changed test code can fail a policy gate that enforces that rule.

**Rule Used:** Never use `println!`/`eprintln!` in Rust; use trac... ([source](https://app.greptile.com/codspeed/-/custom-context?memory=f04f734b-e556-482b-98b9-64c7ce663663))

How can I resolve this? If you propose a fix, please make it concise.

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

@codspeed-hq

codspeed-hq Bot commented Jul 7, 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.

✅ 7 untouched benchmarks


Comparing cod-3070-speedup-allocator-attaching-on-nixos (3a322ae) with main (3278ec8)

Open in CodSpeed

…f func_name

Resolve every defined symbol's libbpf-compatible file offset once per
library (st_value - sh_addr + sh_offset) and attach uprobes by offset,
replacing the per-probe func_name lookup that reparsed the ELF each time.
Symbol resolution parses each allocator ELF independently, so fan it out
across cores with rayon before the serial attach step. Cuts offset
resolution for all discovered allocators from ~190ms to ~29ms locally.
Divan bench comparing serial vs parallel symbol offset resolution over
the discovered allocator libraries. Runs without sudo since it only
parses ELFs, no eBPF attach.
@not-matthias not-matthias force-pushed the cod-3070-speedup-allocator-attaching-on-nixos branch from 0e8688a to 3a322ae Compare July 7, 2026 17:07
Comment on lines +120 to +122
let Some(&offset) = offsets.get(symbol) else {
return;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Offset Misses Still Skip

When resolve_symbol_offsets cannot produce a section-backed file offset for one allocator symbol, this branch returns before trying any symbol-name attach path. A discovered allocator can then have valid exported allocation entry points left uninstrumented with no retry and no visible error, so allocations through those symbols are silently missed. This path needs to fall back to libbpf's symbol attach behavior or make the missing required probe fail loudly instead of treating the allocator as attached.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/memtrack/src/ebpf/memtrack.rs
Line: 120-122

Comment:
**Offset Misses Still Skip**

When `resolve_symbol_offsets` cannot produce a section-backed file offset for one allocator symbol, this branch returns before trying any symbol-name attach path. A discovered allocator can then have valid exported allocation entry points left uninstrumented with no retry and no visible error, so allocations through those symbols are silently missed. This path needs to fall back to libbpf's symbol attach behavior or make the missing required probe fail loudly instead of treating the allocator as attached.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

@not-matthias not-matthias marked this pull request as ready for review July 7, 2026 17:47
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