refactor(memtrack): split monolithic eBPF C and Rust into domain files#455
Conversation
Merging this PR will not alter performance
|
344d4f2 to
03ba372
Compare
Greptile SummaryPure structural reorganization of the eBPF memory tracker: the 392-line monolithic
Confidence Score: 5/5Safe to merge — all changes are file-level reorganization with no logic alterations; BPF map names, program logic, and Rust attach semantics are preserved exactly. Every BPF program, map definition, and Rust attach method is a verbatim extraction from the monolith. Include guards prevent duplicate map definitions across the new header chain. The skeleton rename (MainSkel) follows mechanically from the .bpf.c file rename. No files require special attention beyond the cosmetic redundant-includes note in main.bpf.c. Important Files Changed
|
03ba372 to
181f056
Compare
Split the single-file eBPF source (memtrack.bpf.c) and its Rust attach code (memtrack.rs) into small, single-responsibility files. C side: - main.bpf.c: includes + LICENSE only, no programs or maps - utils/map_helpers.h: BPF_HASH_MAP/BPF_ARRAY_MAP/BPF_RINGBUF macros - utils/tracking.h: tracked_pids/pids_ppid/tracking_enabled maps + is_tracked/is_enabled/track_child helpers + sched_fork program - utils/event_helpers.h: events ringbuf, dropped_events, SUBMIT_EVENT, submit_*_event, store_param/take_param - allocator.h: UPROBE_* macros + all allocator uprobes + mmap/munmap/brk tracepoints Encapsulation improvements: - track_child() helper extracted from sched_fork body - store_mmap_args() helper extracted from mmap enter handler - brk enter now uses store_param() instead of raw bpf_map_update_elem Rust side: - memtrack/mod.rs: skel include, MemtrackBpf struct, new(), Drop - memtrack/macros.rs: attach_uprobe_uretprobe!/attach_uprobe!/ attach_tracepoint! macros + ensure_symbol_exists - memtrack/maps.rs: add_tracked_pid, enable/disable_tracking, dropped_events_count - memtrack/allocator.rs: all attach_* probe methods + per-allocator attach methods - memtrack/tracking.rs: attach_sched_fork / attach_tracepoints Skeleton struct names change from MemtrackSkel to MainSkel (derived from main.bpf.c filename). Output file memtrack.skel.rs unchanged.
181f056 to
c17b77f
Compare
Summary
Splits the monolithic eBPF source (
memtrack.bpf.c, 392 lines) and its Rust attach code (memtrack.rs, 478 lines) into small, single-responsibility files. Pure reorganization — no behavior change.C side
Encapsulation improvements
track_child()helper —sched_forkbody now reads as intent only, rawbpf_map_update_elemcalls hiddenstore_mmap_args()helper — mmap enter handler no longer pokes maps directlystore_param()instead of rawbpf_map_update_elemRust side
#[macro_use] mod macros;ensures declarative macros are visible to sibling modules. Each submodule importsuse super::MemtrackBpf;for itsimplblock.Notes
main.bpf.c(notmain.c) becauselibbpf_cargo::SkeletonBuilderrequires the.bpf.csuffixMemtrackSkel/MemtrackSkelBuildertoMainSkel/MainSkelBuilder(derived from filename). Output filememtrack.skel.rsandinclude!path unchanged.tracked_pids,tracking_enabled,events,dropped_events) preserved — Rust side reads them by name from the skeleton.Verification
cargo check --features ebpf— skeleton generates + compiles ✓cargo build --features ebpf✓cargo test— 2 passed, 20 ignored (sudo/GITHUB_ACTIONS gate) ✓