| 253 | #else // generic unix |
| 254 | |
| 255 | static 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 | |
| 278 | void _mi_os_init(void) { |
| 279 | // get the page size |
no test coverage detected