feat(memtrack): support disabling allocator tracking - #469
Conversation
Greptile SummaryAdds configurable allocator tracking alongside expanded RSS accounting.
Confidence Score: 5/5The PR appears safe to merge because no blocking failures remain within the follow-up review scope. No blocking failures remain. Important Files Changed
|
Merging this PR will not alter performance
|
d983261 to
131f8a3
Compare
GuillaumeLagrange
left a comment
There was a problem hiding this comment.
I'm not sure what's really the usecase of this? olgtm but I'm not sure we've discussed
f1dbc8a to
efc66c8
Compare
7e96222 to
bdd0455
Compare
bdd0455 to
e158870
Compare
Set AllowShortFunctionsOnASingleLine: None in .clang-format and apply it, reformatting the allocator uprobe macros accordingly.
A forked child's inherited RSS is invisible to rss_stat: the fork-time counter copies fire outside the child's context, and anon COW faults are counter-neutral, so a child that only touches inherited memory never reports anything on its own. A fork event carrying the parent pid lets consumers seed the child from the parent's last absolutes; exec and exit mark where the address space is replaced or torn down.
Sample the kernel's per-mm resident counter through the kmem:rss_stat tracepoint, emitting absolute byte values per mm member. Adds the EVENT_TYPE_RSS contract, MemtrackEventKind::Rss, the parser arm, and a writer bench case. An rss_stat update from reclaim or another process's madvise fires in the actor's context; track (mm_id, member) -> owning pid so those updates reach the owner. External events may only lower a counter, so stale reads and mm_id collisions cannot invent peaks.
Attach fentry hooks on the folio-rmap add/remove functions, emitting signed page-count deltas per MM_* bucket so anon, file, and shmem RSS can be reconstructed over time. Gated behind CODSPEED_MEMTRACK_TRACK_RMAP; the programs stay autoload-off by default so the skeleton loads on any kernel, with the PUD pair (only present since v6.15) gated separately from the core set so rmap still works on older kernels. Adds the EVENT_TYPE_RMAP contract, MemtrackEventKind::Rmap, parser arm, and bench case. Recover the owning pid for rmap events run by another task (reclaim, process_madvise, khugepaged, KSM) from the mm_struct pointer, and maintain the ownership maps across exec and thread-group exit. The same ownership binding also validates external (curr==0) rss_stat updates, so a stale mm can no longer attribute a counter to the wrong pid.
Add the rss_tests integration suite: per-workload RSS/rmap reconstruction snapshots against /proc ground truth, fork-seeded child RSS, exec/exit resets, foreign-actor rmap attribution (reclaim, external madvise), and mm-ownership across CLONE_VM and exec. Extend tests/shared.rs with the tracker/fixture helpers these tests need and move compile_c_source into it for reuse. The suite needs two surfaces the production paths don't: a tracker mode that skips the allocator probes and exec-mapping watcher, and readers for the mm-ownership maps.
Add an aarch64 lane to the bpf-tests matrix and run the rss integration tests alongside the existing test binaries.
Add a --track-allocators flag (default on, env CODSPEED_TRACK_ALLOCATORS) to the memtrack track subcommand. When disabled, memtrack skips the allocator uprobe machinery (exec watcher + attach worker) and only emits coarse mmap/munmap/brk events, reducing overhead on allocation-heavy programs. The mmap/munmap/brk syscall tracepoints are now always attached in every memory run. The runner does not add a CLI flag for this: it relies on the CODSPEED_TRACK_ALLOCATORS environment variable being inherited by the memtrack subprocess, keeping the runner decoupled from the installed memtrack version. Standalone memtrack can still use the CLI flag.
e158870 to
bbff5ff
Compare
What
memtrack track --track-allocators(default on, envCODSPEED_TRACK_ALLOCATORS). When disabled, memtrack skips the allocator uprobe machinery and only emits coarsemmap/munmap/brkevents.Why
Allocation-heavy programs (e.g. a Rust build) generate an overwhelming number of
malloc/freeevents, and the per-allocation uprobes slow the target significantly. This trades allocation granularity for lower overhead while still collecting RSS-relevant memory events.How
mmap/munmap/brksyscall tracepoints are now always attached in a memory run.