resource: fix parallel-run flake in the memory ledger test - #204
Merged
Conversation
reconcile_raises_a_laundered_ledger_to_the_measured_footprint asserted exact figures against this process's own statm while sibling tests move it: measured_footprint_tracks_anonymous_not_file_mappings maps a gigabyte of anonymous memory, exactly the headroom the ledger test budgeted for sibling noise, so a parallel run could land the mapping between the two reconciles and the floor legitimately raised the inflated ledger. Fork a child parked in pause() and measure that instead: its footprint is frozen at fork, so the headroom assumption goes away and the restored ledger can be checked against a separately taken reading. Signed-off-by: Cong Wang <cwang@multikernel.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
reconcile_raises_a_laundered_ledger_to_the_measured_footprint asserts exact figures against the test process's own statm while sibling tests move it. Its sibling measured_footprint_tracks_anonymous_not_file_mappings maps a gigabyte of anonymous memory, which is exactly the headroom the ledger test budgeted for sibling noise, so under a parallel run (the default cargo test; CI's --test-threads=1 hides it) the mapping can land between the ledger test's two reconciles. The measure then tops the inflated ledger and the floor legitimately raises it, failing the assert by the sibling's gigabyte plus a few pages of noise.
Fix: fork a child parked in pause() and point reconcile_floor at that pid instead of the shared process. The child's address space is frozen at fork, so its measure cannot move, the headroom assumption disappears, and the restored ledger is again checked against a separately taken reading (an exact-equality assertion the racy self-measure version had to give up). A Drop impl SIGKILLs and reaps the child so nothing leaks on assert failure. The mapping test keeps measuring itself, since it must own the address space it maps into; its existing wide margins were always sufficient once the ledger test stopped depending on them.
The flake was observed on a full parallel suite run (overshoot of exactly 1 GiB + 3 pages, matching the sibling's mapping); it is timing-dependent and not reproducible on demand, but the fix removes the interleaving by construction. The three memory_range_tests pass locally.