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 1 commit into
Conversation
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.
Merging this PR will not alter performance
|
344d4f2 to
03ba372
Compare
Greptile SummarySplits the monolithic
Confidence Score: 5/5Pure structural reorganization with no BPF program logic, map definitions, or Rust attach logic changes — safe to merge. Every probe, map, and event-submission code path is a faithful copy of the original monolith. The only functional change is sys_enter_brk now calling store_param instead of inlining three lines — the semantics are identical. cargo build and cargo check pass, the two runnable unit tests pass, and the integration tests are gated by privilege so their absence here is expected. No map names, SEC sections, or event struct layouts changed. No files require special attention. The redundant direct includes in main.bpf.c (headers already pulled in transitively via allocator.h) are harmless due to include guards and do not affect the compiled BPF object. Important Files Changed
|
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) ✓