Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
file tier on Linux: unbuffered reads only when the cache cannot hold a twentieth of the experts it would read (at least 1.5 GiB); the rest read through it (#1194, #1116, #1085)
Niko1221805088d5b61a
diff --git a/include/strata/platform/memory.hpp b/include/strata/platform/memory.hppindex 0ebc84a57..2944ec96e 100644--- a/include/strata/platform/memory.hpp+++ b/include/strata/platform/memory.hpp@@ -37,10 +37,20 @@ uint64_t total_physical_memory();/// bytes of RAM available. The file tier passes only the expert bytes it really reads from the files (the experts/// outside its resident RAM copy) and the RAM that copy really holds - not every shard's bytes and the requested/// budget, which on a 96 GB PC (#577) made the file tier read unbuffered when the cache could keep its reads.+/// #1194: the file tier's reads are a skewed set (the GPU cache and the RAM copy took the hottest experts; the same+/// few of the rest come back token after token), so the cache does not have to hold all `read_bytes` to serve most of+/// them. With `hot_fraction` < 1 it is enough that the room holds that share of them, but never less than+/// `floor_bytes` (below it the cache holds nothing worth having) and never more than every read. The defaults ask for+/// every byte, as the Windows rule does. Measured on Linux (#1194, a Tesla P100 box under 20 to 32 GB cgroups): through+/// the cache beat the unbuffered reads at every room tried, down to 7% of the read bytes (decode +7% to +118%, a third to+/// a sixth of the drive traffic).inline bool file_cache_keeps(uint64_t avail, uint64_t arena_bytes, uint64_t read_bytes,- uint64_t margin = 4ull << 30) {+ uint64_t margin = 4ull << 30, double hot_fraction = 1.0, uint64_t floor_bytes = 0) {const uint64_t room = avail > arena_bytes + margin ? avail - arena_bytes - margin : 0;- return room >= read_bytes;+ uint64_t need = (uint64_t) ((double) read_bytes * hot_fraction);+ if (need < floor_bytes) need = floor_bytes;+ if (need > read_bytes) need = read_bytes;+ return room >= need;}/// Whether `advise_willneed` asks the OS for anything: not on Windows, nor with STRATA_READ_AHEAD=0.diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cppindex 7ce9b7910..75159eacd 100644--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@ -395,10 +395,14 @@ bool file_tier_unbuffered(const std::vector<std::string>& paths, uint64_t arena_why = "the available RAM is unknown";return false;}- const bool keepable = strata::platform::file_cache_keeps(avail, arena_bytes, read_bytes);+ // #1194: the experts read from the files are a skewed set: a cache holding a twentieth of them (at least 1.5 GiB)+ // serves most of the repeats, and beat the unbuffered reads at every room measured (it reads 2 to 7 times less from+ // the drive). `avail` already has what this process and the cgroup hold taken off, so 1 GiB is left for the rest.+ const bool keepable = strata::platform::file_cache_keeps(avail, arena_bytes, read_bytes, 1ull << 30, 0.05,+ 3ull << 29);char msg[256];std::snprintf(msg, sizeof msg, "%.1f GiB available, %.1f GiB of it still to be taken by the RAM copy, %.1f GiB "- "of experts read from the files: the file cache %s keep them",+ "of experts read from the files: the file cache %s keep the ones that come back",(double) avail / (1ull << 30), (double) arena_bytes / (1ull << 30), (double) read_bytes / (1ull << 30),keepable ? "can" : "cannot");why = msg;diff --git a/src/platform/memory_test.cpp b/src/platform/memory_test.cppindex 7346189d6..0f61c430d 100644--- a/src/platform/memory_test.cpp+++ b/src/platform/memory_test.cpp@@ -45,6 +45,30 @@ int file_cache_keeps_cases() {got == c.keeps ? "" : " <-- WRONG");fail |= got != c.keeps;}+ // #1194, the Linux file tier: a skewed read set, so a twentieth of it (at least 1.5 GiB) is room enough+ const Case linux_cases[] = {+ {"#1194: 31 GB + 12 GB GPU, budget 18 built (6.4 avail, 13.6 read)", 6.4, 0.0, 13.6, true},+ {"#1194: before the copy (avail 25, arena 18, read 13.6)", 25.0, 18.0, 13.6, true},+ {"32 GB cgroup, budget 18, copy built (12.1 avail, 22 read)", 12.1, 0.0, 22.0, true},+ {"32 GB cgroup, budget 24, copy built (3.8 avail, 16 read)", 3.8, 0.0, 16.0, true},+ {"20 GB cgroup, budget 12, copy built (4.7 avail, 28 read)", 4.7, 0.0, 28.0, true},+ {"12 GB cgroup, budget 6, copy built (3.5 avail, 34 read)", 3.5, 0.0, 34.0, true},+ {"no room beside the margin (1 avail, 47 read)", 1.0, 0.0, 47.0, false},+ {"room under the 1.5 GiB floor (2.4 avail, 47 read)", 2.4, 0.0, 47.0, false},+ {"room a twentieth of the reads (3.4 avail, 47 read)", 3.4, 0.0, 47.0, true},+ {"room just under that (3.3 avail, 47 read)", 3.3, 0.0, 47.0, false},+ {"a big read set needs its twentieth (4 avail, 200 read)", 4.0, 0.0, 200.0, false},+ {"a big read set with that room (12 avail, 200 read)", 12.0, 0.0, 200.0, true},+ {"read less than the floor (2.5 avail, 1 read)", 2.5, 0.0, 1.0, true},+ {"nothing available", 0.0, 0.0, 1.0, false},+ {"arena larger than the RAM", 10.0, 20.0, 5.0, false},+ };+ for (const Case& c : linux_cases) {+ const bool got = file_cache_keeps(gib(c.avail), gib(c.arena), gib(c.read), 1ull << 30, 0.05, 3ull << 29);+ std::printf("file_cache_keeps (Linux file tier) %-52s -> %s%s\n", c.what, got ? "buffered" : "unbuffered",+ got == c.keeps ? "" : " <-- WRONG");+ fail |= got != c.keeps;+ }return fail;}} // namespace