Report process memory footprint (RSS) in TurboMalloc and trace samples (#99527)
Adopts #93362. Closes #93362. ### What? Adds the process memory footprint (RSS / "Memory" column on macOS) to TurboMalloc's trace samples, mirroring how OS memory pressure was wired up in #93333. ### Why? The trace viewer already plots `memory` (TurboMalloc's accounted bytes) and, since #93333, OS-level `memory_pressure`. Neither captures the actual resident size of the process. Tracking the OS-reported footprint alongside the allocator's view exposes overhead from things the allocator doesn't account for (e.g. mimalloc reserves, mmap'd files, executable pages, native dependencies) and makes leaks/regressions in real RSS visible in traces. ### How? - New `TurboMalloc::memory_footprint() -> Option<usize>` (bytes), implemented in `turbopack/crates/turbo-tasks-malloc/src/memory_footprint.rs` with one `mod platform` per OS: - **Linux**: parses the resident-pages field of `/proc/self/statm` and multiplies by `sysconf(_SC_PAGESIZE)`. - **macOS**: `task_info(mach_task_self(), TASK_VM_INFO, …).phys_footprint` — the same value Apple's Activity Monitor labels "Memory". Guards against older kernels that return a shorter struct by checking the returned `count` covers `phys_footprint`. - **Windows**: `GetProcessMemoryInfo(GetCurrentProcess(), …).WorkingSetSize`. New `windows-sys` features `Win32_System_ProcessStatus` and `Win32_System_Threading`. - Other targets (incl. wasm) return `None`. - `TraceRow::MemorySample` gains a `memory_footprint: u64` field. `RawTraceLayer::maybe_report_memory_sample` captures it via `TurboMalloc::memory_footprint().map(|v| v as u64).unwrap_or(0)` at the same sampling point as `memory` and `memory_pressure`. - Trace-server `Store::MemorySample` becomes `(Timestamp, u64, u8, u64)` carrying `(ts, memory, memory_pressure, memory_footprint)`. A new `memory_footprint_samples_for_range` mirrors `memory_samples_for_range` and `memory_pressure_samples_for_range`, sharing the existing `memory_samples_slice` helper so the three result vectors stay index-aligned and use the same `MAX_MEMORY_SAMPLES`-cap max-per-chunk downsampling. - `ServerToClientMessage::QueryResult` exposes a parallel `memory_footprint_samples: Vec<u64>` next to `memory_samples` and `memory_pressure_samples`. This is a wire-format break for the postcard-encoded raw trace (added a serde field to `TraceRow::MemorySample`); old trace files cannot be read by the new trace-server. This matches the precedent set by #93333. ### Testing - `cargo test -p turbo-tasks-malloc` — 10 pass, including a new `parses_typical_statm_content` / `returns_none_on_malformed_statm` parser pair and a runtime `memory_footprint_is_reported_on_supported_platforms` check that asserts `Some(_)` and a positive, plausibly bounded byte count on Linux/macOS/Windows. - `cargo build`, `cargo clippy --all-targets`, and `cargo fmt --check` clean for `turbo-tasks-malloc`, `turbopack-trace-utils`, and `turbopack-trace-server`. <!-- NEXT_JS_LLM_PR --> <!-- fleet fdf95ce6-ffc0-474d-8a27-daecba57a97d --> --------- Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
This diff is collapsed.
Please
register
or
sign in
to comment