Skip to content

Commit 64cd996

Browse files
committed
perf(memtrack): drain ringbuf bursts eagerly and reserve poller cores
Two consumer-side fixes for event drops under allocation bursts: - After each poll() the poller keeps calling consume_raw() until the ring buffer reads empty, draining bursts without paying an epoll wakeup round-trip per poll cycle. - The encode pipeline no longer claims every core: rayon workers on all cores starve the poll thread (and the tracked command), which is what let the ring buffer fill up. Reserve two cores. Refs COD-3071
1 parent 4da30e9 commit 64cd996

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

crates/memtrack/src/ebpf/poller.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ impl RingBufferPoller {
3939
move || {
4040
while !shutdown.load(Ordering::Relaxed) {
4141
let _ = ringbuf.poll(timeout);
42+
43+
// Records produced while poll() was draining are consumed
44+
// directly (no epoll_wait syscall) until the buffer reads
45+
// empty, so bursts are drained at full speed instead of
46+
// paying a wakeup round-trip per poll cycle.
47+
while ringbuf.consume().is_ok() {}
4248
}
4349

4450
// Events may still be sitting in the ring buffer after the last

crates/memtrack/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ fn track_command(
126126
let file_name = MemtrackArtifact::file_name(Some(root_pid));
127127
let out_file = std::fs::File::create(out_dir.join(file_name))?;
128128

129+
// Leave headroom for the ring buffer poll thread and the tracked
130+
// command: encode workers on every core starve the poller during
131+
// allocation bursts, which overflows the kernel ring buffer.
129132
let n_workers = thread::available_parallelism()
130-
.map(|n| n.get())
133+
.map(|n| n.get().saturating_sub(2).max(1))
131134
.unwrap_or(4);
132135

133136
let pipeline_thread = thread::spawn(move || encode_events(event_rx, out_file, n_workers));

0 commit comments

Comments
 (0)