MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / os_detect_overcommit

Function os_detect_overcommit

3rd/mimalloc-2.0.9/src/os.c:255–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253#else // generic unix
254
255static void os_detect_overcommit(void) {
256#if defined(__linux__)
257 int fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY);
258 if (fd < 0) return;
259 char buf[32];
260 ssize_t nread = read(fd, &buf, sizeof(buf));
261 close(fd);
262 // <https://www.kernel.org/doc/Documentation/vm/overcommit-accounting>
263 // 0: heuristic overcommit, 1: always overcommit, 2: never overcommit (ignore NORESERVE)
264 if (nread >= 1) {
265 os_overcommit = (buf[0] == '0' || buf[0] == '1');
266 }
267#elif defined(__FreeBSD__)
268 int val = 0;
269 size_t olen = sizeof(val);
270 if (sysctlbyname("vm.overcommit", &val, &olen, NULL, 0) == 0) {
271 os_overcommit = (val != 0);
272 }
273#else
274 // default: overcommit is true
275#endif
276}
277
278void _mi_os_init(void) {
279 // get the page size

Callers 1

_mi_os_initFunction · 0.85

Calls 3

readFunction · 0.85
openFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected