mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-11 09:25:35 +08:00
Inside a container, sysconf(_SC_NPROCESSORS_ONLN) and sysinfo() report the host's CPU count and RAM, not the cgroup's effective quota — so cbm_default_worker_count over-provisions workers and the mmap budget can exceed the cgroup memory cap, driving OOMKills (#363). detect_system_linux now reads the cgroup limits: - cbm_detect_cgroup_cpus: cgroup v2 cpu.max, then v1 cpu.cfs_quota_us / cpu.cfs_period_us → ceil(quota/period); -1 when unlimited. - cbm_detect_cgroup_mem: cgroup v2 memory.max, then v1 memory.limit_in_bytes; 0 when unlimited or the v1 near-ULLONG_MAX sentinel. - Effective value is min(cgroup, host), guarding against mis-mounted cgroups that report more than the host. Helpers read via a bounded read_small_file (fopen "re", capped fread) and are exposed through system_info_internal.h for unit tests that drive them against a fake cgroup tree. The test teardown uses opendir/unlink/ rmdir (no shell spawn). Distilled from #365 onto current main (unioned the test additions with the CBM_WORKERS tests from #364, and replaced the test-cleanup system("rm -rf") with a shell-free recursive remove). Closes #363 together with #364.