From c0e64ef3cd06145f19151da048574903677fd40b Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Mon, 10 Aug 2026 11:18:38 +0200 Subject: [PATCH] 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 --- src/foundation/diagnostics.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/foundation/diagnostics.c b/src/foundation/diagnostics.c index 3360ef1f9..5b2ee2cb8 100644 --- a/src/foundation/diagnostics.c +++ b/src/foundation/diagnostics.c @@ -528,9 +528,16 @@ static void write_diagnostics(void) { size_t page_faults = 0; mi_process_info(&elapsed_ms, &user_ms, &sys_ms, ¤t_rss, &peak_rss, ¤t_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);