refactor(memtrack): split monolithic eBPF C and Rust into domain files#455
refactor(memtrack): split monolithic eBPF C and Rust into domain files#455not-matthias wants to merge 2 commits into
Conversation
Merging this PR will not alter performance
|
344d4f2 to
03ba372
Compare
Greptile SummaryThis PR splits the monolithic
Confidence Score: 5/5Pure reorganization — no logic changes, all BPF map names and program semantics are preserved. Every behavioral path (store_param for brk, store_mmap_args for mmap, track_child for fork) is functionally identical to the deleted monolith. The skeleton type rename from MemtrackSkel to MainSkel has no external consumers. The only finding is redundant explicit includes in main.bpf.c that are already pulled in transitively — header guards prevent any compile issue. No files require special attention; main.bpf.c has a minor redundant-include style nit. Important Files Changed
|
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.
03ba372 to
181f056
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) ✓