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

Function detect_system_linux

src/foundation/system_info.c:216–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216static cbm_system_info_t detect_system_linux(void) {
217 cbm_system_info_t info;
218 memset(&info, 0, sizeof(info));
219
220 /* Host fallbacks. */
221 long nprocs = sysconf(_SC_NPROCESSORS_ONLN);
222 int host_cpus = nprocs > 0 ? (int)nprocs : DEFAULT_CORES;
223
224 size_t host_ram = 0;
225 struct sysinfo si;
226 if (sysinfo(&si) == 0) {
227 host_ram = (size_t)si.totalram * (size_t)si.mem_unit;
228 }
229
230 /* Cgroup-aware overrides. min(cgroup, host) defends against
231 * mis-mounted cgroups that report values larger than the host. */
232 int cg_cpus = cbm_detect_cgroup_cpus("/sys/fs/cgroup");
233 info.total_cores = (cg_cpus > 0 && cg_cpus < host_cpus) ? cg_cpus : host_cpus;
234 info.perf_cores = info.total_cores; /* Linux doesn't distinguish P/E */
235
236 size_t cg_ram = cbm_detect_cgroup_mem("/sys/fs/cgroup");
237 info.total_ram = (cg_ram > 0 && (host_ram == 0 || cg_ram < host_ram)) ? cg_ram : host_ram;
238
239 return info;
240}
241
242#endif /* __APPLE__ / BSD / Linux */
243

Callers 1

detect_system_nowFunction · 0.85

Calls 3

sysinfoClass · 0.85
cbm_detect_cgroup_cpusFunction · 0.85
cbm_detect_cgroup_memFunction · 0.85

Tested by

no test coverage detected