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

Function cbm_mem_rss

src/foundation/mem.c:517–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517size_t cbm_mem_rss(void) {
518#if defined(__linux__)
519 /* Linux: mimalloc's _mi_prim_process_info() (vendored/mimalloc/src/prim/
520 * unix/prim.c) never sets pinfo->current_rss on Linux — it only sets
521 * peak_rss (from getrusage's ru_maxrss). current_rss therefore keeps
522 * mi_process_info()'s default of pinfo.current_commit: mimalloc's OWN
523 * committed-page counter, which this project deliberately tunes low via
524 * mi_option_arena_eager_commit=0 + purge_decommits=1 + purge_delay=0
525 * (cbm_mem_init) to reduce upfront memory. So on Linux "current_rss" is a
526 * low-biased mimalloc-internal metric, not true RSS: under concurrent
527 * large-file parsing it can read a few MB while real RSS is multiple GB,
528 * silently blinding cbm_mem_over_budget()'s backpressure to real memory
529 * pressure (small-but-nonzero, so the `current_rss > 0` guard below never
530 * catches it). os_rss() reads /proc/self/statm — authoritative OS RSS,
531 * unaffected by mimalloc's accounting — so it is the PRIMARY source on
532 * Linux, not a last-resort fallback. macOS/Windows are unaffected:
533 * mimalloc sets current_rss correctly there via task_info /
534 * GetProcessMemoryInfo. */
535 size_t proc_rss = os_rss();
536 if (proc_rss > 0) {
537 return proc_rss;
538 }
539 /* Extremely unlikely (/proc unavailable) — fall through to mimalloc. */
540#endif
541 size_t current_rss = 0;
542 size_t peak_rss = 0;
543 mi_process_info(NULL, NULL, NULL, &current_rss, &peak_rss, NULL, NULL, NULL);
544 if (current_rss > 0) {
545 return current_rss;
546 }
547 /* Fallback for ASan builds (MI_OVERRIDE=0) and any platform where
548 * mimalloc's current_rss is unavailable/zero. */
549 return os_rss();
550}
551
552size_t cbm_mem_peak_rss(void) {
553 size_t peak_rss = 0;

Callers 13

dump_lockedFunction · 0.85
cbm_mem_peak_rssFunction · 0.85
cbm_mem_chargedFunction · 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

Calls 1

os_rssFunction · 0.85

Tested by 1

incremental_setupFunction · 0.68