Arena RAM fallback: budget form with an 8 GiB headroom, and the Windows copy trims the mapped pages

The fallback's RAM copy (previous commit) now uses the --resident-budget-gib form: the budget is what is available minus the headroom
(default 8 GiB, STRATA_RESIDENT_HEADROOM_GIB changes it), so the experts outside the copy are read unbuffered instead of through the mapped
view whose pages grow the working set until available RAM is near zero.  On Windows the complement copy releases the mapped pages to the
standby list every 4 layers (the VirtualUnlock call that already ran once after the copy): available RAM fell to 0.9 GiB for ~10 s during the copy
on a 64 GB PC with 44.6 GiB available.  No data changes.
Measured on the RTX 5070 PC (128K, 44.6 GiB available): lowest available RAM 4.05 GiB, 2,000-token answer 25.2 tok/s (9.4-10.1 without the fix).
This commit is contained in:
Niko1221 committed 2026-11-02 02:15:46 +01:00
1 parent 43543e9b07
commit 07fb0e7113
2 files changed
+14 -2

No files matched your search

+6 -2
View File
@@ -6825,7 +6825,7 @@ int main(int argc, char** argv) {
const bool ram_fallback_resident_off = [] { const char* v = std::getenv("STRATA_ARENA_FALLBACK_RESIDENT"); return v != nullptr && v[0] == '0'; }();
const uint64_t ram_fallback_headroom = [] {
const char* v = std::getenv("STRATA_RESIDENT_HEADROOM_GIB");
return (v != nullptr && std::atof(v) >= 0.0) ? (uint64_t) (std::atof(v) * 1073741824.0) : (4ull << 30);
return (v != nullptr && std::atof(v) >= 0.0) ? (uint64_t) (std::atof(v) * 1073741824.0) : (8ull << 30);
}();
for (bool again = true; again;) {
again = false;
@@ -6844,7 +6844,7 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: the experts cannot be read from the file either (%s): loading the expert arena "
"as before, short of RAM\n", err.c_str());
o.mmap_experts = false;
if (ram_fallback_resident) o.resident_cpu_experts = o.resident_pin = o.resident_soft = ram_fallback_resident = false;
if (ram_fallback_resident) { o.resident_cpu_experts = o.resident_pin = o.resident_soft = ram_fallback_resident = false; o.resident_budget = 0; }
ram_fallback_taken = false;
ram_fallback_failed = true;
again = true;
@@ -7066,6 +7066,10 @@ int main(int argc, char** argv) {
if (!o.expert_profile.empty() && !o.resident_cpu_experts && !ram_fallback_resident_off) {
o.resident_cpu_experts = o.resident_pin = o.resident_soft = true;
o.resident_headroom = ram_fallback_headroom;
// the budget form (as --resident-budget-gib): the hottest experts in what is available minus the headroom, and the rest
// read unbuffered, not through the mapped view (whose pages grow the working set until available RAM is near zero)
if (const auto hm = strata::core::sample_host_memory(); hm && hm->available > o.resident_headroom + (1ull << 30))
o.resident_budget = hm->available - o.resident_headroom;
ram_fallback_resident = true;
}
again = true;