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

Function cbm_mem_rss

src/foundation/mem.c:437–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435}
436
437size_t cbm_mem_rss(void) {
438#if defined(__linux__)
439 /* Linux: mimalloc's _mi_prim_process_info() (vendored/mimalloc/src/prim/
440 * unix/prim.c) never sets pinfo->current_rss on Linux — it only sets
441 * peak_rss (from getrusage's ru_maxrss). current_rss therefore keeps
442 * mi_process_info()'s default of pinfo.current_commit: mimalloc's OWN
443 * committed-page counter, which this project deliberately tunes low via
444 * mi_option_arena_eager_commit=0 + purge_decommits=1 + purge_delay=0
445 * (cbm_mem_init) to reduce upfront memory. So on Linux "current_rss" is a
446 * low-biased mimalloc-internal metric, not true RSS: under concurrent
447 * large-file parsing it can read a few MB while real RSS is multiple GB,
448 * silently blinding cbm_mem_over_budget()'s backpressure to real memory
449 * pressure (small-but-nonzero, so the `current_rss > 0` guard below never
450 * catches it). os_rss() reads /proc/self/statm — authoritative OS RSS,
451 * unaffected by mimalloc's accounting — so it is the PRIMARY source on
452 * Linux, not a last-resort fallback. macOS/Windows are unaffected:
453 * mimalloc sets current_rss correctly there via task_info /
454 * GetProcessMemoryInfo. */
455 size_t proc_rss = os_rss();
456 if (proc_rss > 0) {
457 return proc_rss;
458 }
459 /* Extremely unlikely (/proc unavailable) — fall through to mimalloc. */
460#endif
461 size_t current_rss = 0;
462 size_t peak_rss = 0;
463 mi_process_info(NULL, NULL, NULL, &current_rss, &peak_rss, NULL, NULL, NULL);
464 if (current_rss > 0) {
465 return current_rss;
466 }
467 /* Fallback for ASan builds (MI_OVERRIDE=0) and any platform where
468 * mimalloc's current_rss is unavailable/zero. */
469 return os_rss();
470}
471
472size_t cbm_mem_peak_rss(void) {
473 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