MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_mem_rss

Function cbm_mem_rss

src/foundation/mem.c:408–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408size_t cbm_mem_rss(void) {
409#if defined(__linux__)
410 /* Linux: mimalloc's _mi_prim_process_info() (vendored/mimalloc/src/prim/
411 * unix/prim.c) never sets pinfo->current_rss on Linux — it only sets
412 * peak_rss (from getrusage's ru_maxrss). current_rss therefore keeps
413 * mi_process_info()'s default of pinfo.current_commit: mimalloc's OWN
414 * committed-page counter, which this project deliberately tunes low via
415 * mi_option_arena_eager_commit=0 + purge_decommits=1 + purge_delay=0
416 * (cbm_mem_init) to reduce upfront memory. So on Linux "current_rss" is a
417 * low-biased mimalloc-internal metric, not true RSS: under concurrent
418 * large-file parsing it can read a few MB while real RSS is multiple GB,
419 * silently blinding cbm_mem_over_budget()'s backpressure to real memory
420 * pressure (small-but-nonzero, so the `current_rss > 0` guard below never
421 * catches it). os_rss() reads /proc/self/statm — authoritative OS RSS,
422 * unaffected by mimalloc's accounting — so it is the PRIMARY source on
423 * Linux, not a last-resort fallback. macOS/Windows are unaffected:
424 * mimalloc sets current_rss correctly there via task_info /
425 * GetProcessMemoryInfo. */
426 size_t proc_rss = os_rss();
427 if (proc_rss > 0) {
428 return proc_rss;
429 }
430 /* Extremely unlikely (/proc unavailable) — fall through to mimalloc. */
431#endif
432 size_t current_rss = 0;
433 size_t peak_rss = 0;
434 mi_process_info(NULL, NULL, NULL, &current_rss, &peak_rss, NULL, NULL, NULL);
435 if (current_rss > 0) {
436 return current_rss;
437 }
438 /* Fallback for ASan builds (MI_OVERRIDE=0) and any platform where
439 * mimalloc's current_rss is unavailable/zero. */
440 return os_rss();
441}
442
443size_t cbm_mem_peak_rss(void) {
444 size_t peak_rss = 0;

Callers 11

cbm_mem_peak_rssFunction · 0.85
cbm_mem_over_budgetFunction · 0.85
mem_map_collect_implFunction · 0.85
cbm_mem_census_logFunction · 0.85
write_diagnosticsFunction · 0.85
log_extract_mem_statsFunction · 0.85
log_phase_memFunction · 0.85
run_parallel_pipelineFunction · 0.85
test_mem.cFile · 0.85
incremental_setupFunction · 0.85
rss_bytesFunction · 0.85

Calls 1

os_rssFunction · 0.85

Tested by 1

incremental_setupFunction · 0.68