Skip to content

fix(mem): reconcile peak RSS with live current RSS (Linux statm vs ru_maxrss)#866

Merged
DeusData merged 1 commit into
mainfrom
fix/mem-peak-rss-invariant
Jul 5, 2026
Merged

fix(mem): reconcile peak RSS with live current RSS (Linux statm vs ru_maxrss)#866
DeusData merged 1 commit into
mainfrom
fix/mem-peak-rss-invariant

Conversation

@DeusData

@DeusData DeusData commented Jul 4, 2026

Copy link
Copy Markdown
Owner

The bug (the recurring "ARM stall")

The ubuntu-24.04-arm CI leg has been intermittently "failing" — but it was never a timeout or a hang. The suite runs to completion and exactly one test fails:

mem_peak_rss_gte_rss  FAIL  tests/test_mem.c: peak (1058471936) not >= rss (1058648064)

On Linux, cbm_mem_rss() reads the live /proc/self/statm value (page-granular — the RSS-undercount fallback), while cbm_mem_peak_rss() returns mimalloc's peak_rss = getrusage ru_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 definitional peak >= current invariant. It's flaky, pre-existing on main, 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_rss guard now faults in a 32 MB buffer before asserting, so the invariant is checked against a non-trivial live current read.

Verification

  • Local (macOS): clean compile under -Werror + ASan/UBSan; mem suite 41 passed / 0 failed (mem_peak_rss_gte_rss PASS).
  • CI here proves the fix on the Linux + ARM legs (the tier that actually exercised the bug).

Atomic; 2 files (+25/−1); merge-commit, not squash.

…_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>
@DeusData DeusData enabled auto-merge July 4, 2026 23:51
@DeusData DeusData merged commit 60e1769 into main Jul 5, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant