fix(diagnostics): report OS-truth RSS, not mimalloc's Linux commit counter

Both Linux soak-quick legs in the dry run failed with:

  FAIL: RSS 17592186044293MB > 200MB ceiling

17592186044293 MB is 2^44-123 -- a NEGATIVE ~123MB wrapped through size_t. The
diagnostics snapshot reported mi_process_info()'s current_rss verbatim, and on
Linux mimalloc never sets that field: it keeps mimalloc's internal
committed-page counter, which this project deliberately tunes low
(purge_decommits=1, purge_delay=0) and which can transiently go negative under
purge. macOS and Windows are untouched -- mimalloc reports real RSS there --
which is exactly the observed split: both Linux legs red, both macOS legs green.

mem.c already learned this lesson in full (its comment block documents the same
trap for cbm_mem_over_budget): cbm_mem_rss() is /proc-statm-primary on Linux and
mimalloc-correct elsewhere, and cbm_mem_peak_rss() reconciles peak >= current.
The diagnostics writer now uses both instead of the raw mi fields, so the soak
leak gates measure actual process RSS on every platform.

Verified: diagnostics suite passes; compiles and formats clean.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This commit is contained in:
Martin Vogel
2026-08-10 11:18:38 +02:00
parent ad010b1656
commit c0e64ef3cd
+10 -3
View File
@@ -528,9 +528,16 @@ static void write_diagnostics(void) {
size_t page_faults = 0;
mi_process_info(&elapsed_ms, &user_ms, &sys_ms, &current_rss, &peak_rss, &current_commit,
&peak_commit, &page_faults);
if (current_rss == 0) {
current_rss = cbm_mem_rss();
}
/* Do NOT report mi_process_info's rss fields: on Linux mimalloc never sets
* current_rss, so the field keeps mimalloc's internal committed-page
* counter — deliberately tuned low here (purge_decommits=1, purge_delay=0)
* and able to go transiently NEGATIVE under purge, which wraps through
* size_t and printed rss_bytes of ~2^64 (soak read it as a 17-exabyte
* "leak"). cbm_mem_rss()/cbm_mem_peak_rss() already encode the whole
* lesson: /proc statm is authoritative on Linux, mimalloc is correct on
* macOS/Windows, and peak is reconciled to never undercut current. */
current_rss = cbm_mem_rss();
peak_rss = cbm_mem_peak_rss();
int fds = count_open_fds();
time_t now = time(NULL);