file tier: opt-in Linux I/O path (STRATA_IO_PREFETCH=1) and counters that separate drive reads from page-cache hits

The mapped file tier reads experts through page faults. With STRATA_IO_PREFETCH=1 (Linux, experts.bin or the GGUF
in place) a blob whose pages are not cached is read with one pread of the whole blob into a staging buffer, the
predicted experts of the next layer(s) are read ahead on I/O threads (STRATA_IO_PF_THREADS, STRATA_IO_PREFETCH_DEPTH,
STRATA_IO_PF_AHEAD=0 for demand reads only), and a cached blob is still handed out as the mapping. Same bytes, so the
same output; off by default.

Counters: each request now logs the OS's own view of the file tier (/proc/self/io read_bytes and major faults) beside
the engine's expert reads, and with STRATA_IO_STATS=1 or io prefetch a mincore split of cached and uncached bytes,
read-ahead used / unused / skipped, and the decode's wait in the fetches (--stats prints the same).

blob_stable(): a pointer that is not recycled, for the copies that run asynchronously (adaptive swaps, the GPU cache
fills, the prompt stager).
This commit is contained in:
Niko1221 committed 2026-10-07 02:21:11 +02:00
1 parent e2de691c7c
commit 9745567e5f
7 files changed
+566 -25

No files matched your search

+27
View File
@@ -9,7 +9,9 @@
#include <cstring>
#else
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
@@ -168,4 +170,29 @@ void advise_willneed(int fd, uint64_t offset, uint64_t bytes) {
}
#endif
ProcIo proc_io_sample() {
ProcIo r;
#if defined(__linux__)
if (std::FILE* f = std::fopen("/proc/self/io", "r")) {
char key[64];
unsigned long long v;
while (std::fscanf(f, "%63[^:]: %llu\n", key, &v) == 2)
if (std::strcmp(key, "read_bytes") == 0) { r.read_bytes = v; r.valid = true; }
std::fclose(f);
}
if (std::FILE* f = std::fopen("/proc/self/stat", "r")) {
char buf[1024];
const size_t n = std::fread(buf, 1, sizeof buf - 1, f);
buf[n] = 0;
std::fclose(f);
if (const char* p = std::strrchr(buf, ')')) { // fields after the command: state ppid ... minflt cminflt majflt
unsigned long long minflt = 0, cminflt = 0, majflt = 0;
if (std::sscanf(p + 2, "%*c %*d %*d %*d %*d %*d %*u %llu %llu %llu", &minflt, &cminflt, &majflt) == 3)
r.major_faults = majflt;
}
}
#endif
return r;
}
} // namespace strata::platform