Optional startup pass that touches tensor pages before timing generation. */
| 2329 | m->fd = -1; |
| 2330 | } |
| 2331 | |
| 2332 | static void model_prefetch_cpu_mapping(const ds4_model *m) { |
| 2333 | if (!m || !m->map || m->size == 0) return; |
| 2334 | |
| 2335 | /* |
| 2336 | * CPU generation touches expert weights according to router decisions, so a |
| 2337 | * long decode can fault in model pages that the prompt never touched. On |
| 2338 | * current Darwin kernels we have seen those late file-backed faults trigger |
| 2339 | * an OS-level VM panic in map-count accounting. This hint does not copy or |
| 2340 | * pin the GGUF; it just asks the kernel to start bringing the read-only |
| 2341 | * mapping into the page cache before token generation reaches it. |
| 2342 | */ |
| 2343 | #if defined(POSIX_MADV_WILLNEED) |
| 2344 | const int rc = posix_madvise((void *)m->map, (size_t)m->size, POSIX_MADV_WILLNEED); |
| 2345 | if (rc != 0) { |
| 2346 | ds4_log(stderr, |
| 2347 | DS4_LOG_WARNING, |
| 2348 | "ds4: warning: POSIX_MADV_WILLNEED failed for CPU model mapping: %s\n", |
| 2349 | strerror(rc)); |
| 2350 | } |
| 2351 | #else |
| 2352 | (void)m; |
| 2353 | #endif |
| 2354 | } |
| 2355 | |
| 2356 | /* Read the GGUF metadata table. Values stay in the mmap; we store offsets so |
| 2357 | * later validation can decode only the keys it needs. */ |
| 2358 | static void parse_metadata(ds4_model *m, ds4_cursor *c) { |
| 2359 | /* n_kv comes from the header. Every entry consumes at least one byte in the |
no test coverage detected