fix(mem): reconcile peak RSS with live current RSS (Linux statm vs ru_maxrss)#866
Merged
Conversation
…_maxrss) cbm_mem_peak_rss() returned mimalloc's peak_rss (from getrusage ru_maxrss, KB-granular) while on Linux cbm_mem_rss() reads the live /proc/self/statm value (page-granular, the RSS-undercount fallback). The two sources can disagree by a few pages, so a live current read could momentarily exceed the reported peak and break the definitional peak >= current invariant — flaking the mem_peak_rss_gte_rss test on the Linux/ARM CI leg (observed as peak 172KB under current). Reconcile the sources so the reported peak is at least the current RSS. Not observable on macOS, where both come from mimalloc. The mem_peak_rss_gte_rss guard now faults in a 32MB buffer before asserting so the invariant is checked against a non-trivial live current read. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
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.
The bug (the recurring "ARM stall")
The
ubuntu-24.04-armCI leg has been intermittently "failing" — but it was never a timeout or a hang. The suite runs to completion and exactly one test fails:On Linux,
cbm_mem_rss()reads the live/proc/self/statmvalue (page-granular — the RSS-undercount fallback), whilecbm_mem_peak_rss()returns mimalloc'speak_rss= getrusageru_maxrss(KB-granular, and it lags). Reading the two sources independently lets a fresh live current read momentarily exceed the reported peak by a few pages (here 172 KB = 43 pages), breaking the definitionalpeak >= currentinvariant. It's flaky, pre-existing onmain, and Linux-only (macOS reads both from mimalloc → consistent), so it can intermittently sink any Linux/ARM leg — including the release dry run.The fix
cbm_mem_peak_rss()now reconciles the two sources: the reported peak is at least the current RSS (peak is definitionally ≥ current). This is a correctness fix — our peak source was under-reporting relative to the live current source — not a test relaxation.Reproduction tier
Linux-only — not reproducible on macOS (both RSS values come from mimalloc there). The authoritative reproduction is the Linux/ARM CI leg, where the guard flaked red; with this fix it goes deterministically green. The
mem_peak_rss_gte_rssguard now faults in a 32 MB buffer before asserting, so the invariant is checked against a non-trivial live current read.Verification
-Werror+ ASan/UBSan; mem suite 41 passed / 0 failed (mem_peak_rss_gte_rss PASS).Atomic; 2 files (+25/−1); merge-commit, not squash.