test(memtrack): reproduce fork-inherited unmap removes-exceed-adds - #486
test(memtrack): reproduce fork-inherited unmap removes-exceed-adds#486not-matthias wants to merge 1 commit into
Conversation
Fork copies page tables through the folio_*_dup_* helpers, which the rmap program does not hook, so pages inherited at fork never produce adds under the child's pid. Unmapping or reclaiming them fires in-context removes with no matching adds, leaving a net-negative delta. That stream shape is the root cause behind the negative resident estimates the parser now floors at zero. The fixture mmaps and touches 32 MiB, forks a child that munmaps the inherited region and exits; the test asserts the child's anon rmap net delta is at least ~-24 MiB with no adds. Reproduces in CI without memory pressure and documents the event-stream contract that consumers must tolerate removes exceeding adds per pid.
| include_str!("../testdata/rss/rss_report.h"), | ||
| )?; | ||
| let binary = shared::compile_c_source(source, name, temp_dir.path())?; |
There was a problem hiding this comment.
RSS test infrastructure is absent
When Cargo compiles the new integration-test target, its compile-time fixture includes, shared::compile_c_source and shared::track_command_with_rmap calls, and RSS event variants are unavailable in the reviewed tree, causing cargo test to fail before the tests can run.
Knowledge Base Used: memtrack: eBPF-based memory allocation tracking
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/memtrack/tests/rss_tests.rs
Line: 184-186
Comment:
**RSS test infrastructure is absent**
When Cargo compiles the new integration-test target, its compile-time fixture includes, `shared::compile_c_source` and `shared::track_command_with_rmap` calls, and RSS event variants are unavailable in the reviewed tree, causing `cargo test` to fail before the tests can run.
**Knowledge Base Used:** [memtrack: eBPF-based memory allocation tracking](https://app.greptile.com/codspeed/-/custom-context/knowledge-base/codspeedhq/codspeed/-/docs/memtrack.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Greptile SummaryAdds a deterministic fork-inherited unmap reproduction and an RSS/rmap integration-test target.
Confidence Score: 2/5This PR is not safe to merge until the new RSS integration-test target's missing fixtures and supporting APIs are included or the target is reduced to available infrastructure. Cargo test discovers the new integration-test file and encounters compile-time includes, helper calls, and event variants that do not exist in the reviewed tree, preventing the test target from compiling. Files Needing Attention: crates/memtrack/tests/rss_tests.rs
|
| Filename | Overview |
|---|---|
| crates/memtrack/testdata/rss/fork_unmap_inherited.c | Adds the focused C fixture that faults a private anonymous mapping and unmaps its inherited copy in a child. |
| crates/memtrack/tests/rss_tests.rs | Adds the intended regression assertion alongside a larger test suite, but the new target cannot compile without missing fixtures, helpers, and event variants. |
Sequence Diagram
sequenceDiagram
participant Test as rss_tests
participant Parent as Fixture parent
participant Child as Forked child
participant Rmap as rmap event stream
Test->>Parent: mmap and touch 32 MiB
Parent->>Child: fork with inherited page tables
Note over Rmap,Child: No child add events for inherited pages
Child->>Rmap: munmap emits child remove events
Test->>Rmap: Sum child anonymous deltas
Rmap-->>Test: "Net delta <= -24 MiB"
Prompt To Fix All With AI
### Issue 1
crates/memtrack/tests/rss_tests.rs:184-186
**RSS test infrastructure is absent**
When Cargo compiles the new integration-test target, its compile-time fixture includes, `shared::compile_c_source` and `shared::track_command_with_rmap` calls, and RSS event variants are unavailable in the reviewed tree, causing `cargo test` to fail before the tests can run.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "test(memtrack): reproduce fork-inherited..." | Re-trigger Greptile
Merging this PR will not alter performance
|
The rmap resident estimate in the parser is a signed running sum per pid
starting at zero. Fork copies page tables through the
folio_*_dup_*helpers, which the rmap program does not hook, so pages inherited at
fork never produce adds under the child's pid. Unmapping or reclaiming
them fires in-context removes with no matching adds, leaving a
net-negative delta — the root cause behind the negative resident
estimates the parser now floors at zero.
This adds a deterministic, CI-safe repro (no memory pressure needed):
the fixture mmaps and touches 32 MiB, forks a child that munmaps the
inherited region and exits. The test asserts the child's anon rmap net
delta is at least ~-24 MiB with no adds, documenting the event-stream
contract that consumers must tolerate removes exceeding adds per pid.
Companion to the parser-side fix in CodSpeedHQ/platform#2729.