[PR #5531] engine: load the expert arena through the file cache again when the shortfall is only MemAvailable's cache discount (#5327) #5504

Open
opened 2026-11-08 04:52:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5531
Author: @pjgmobile
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: fix/1m-arena-linux-file-cache


📝 Commits (2)

  • 6864dce #5327: on Linux an expert-arena shortfall the file cache can serve loads through it again - the 0.1.55 warn-and-proceed (free pages + Cached+Buffers+SReclaimable-Shmem-Dirty cover the need: MemAvailable credits only half the cache), said loudly on stdout as well, because a service setup never sees stderr; the #4846 refusal stays for shortfalls it cannot serve (#4051's anonymous RAM), under a cgroup limit, and on Windows, and STRATA_ARENA_FILE_CACHE=0 turns the credit off; tests
  • 63cf748 #5327: correct the comments - MemAvailable does not credit "only about half" of the page cache (it counts nearly all of it, minus the low watermark); the false alarm this fixes is the reserved hugetlb pool, which MemAvailable does not count at all. The file-cache credit stays as a small secondary margin. Comments only, no code change.

📊 Changes

4 files changed (+140 additions, -3 deletions)

View changed files

📝 include/strata/core/ple_residency.hpp (+60 -0)
📝 src/core/expert_source.cpp (+42 -2)
📝 src/core/ple_residency_test.cpp (+31 -0)
📝 src/program/generate.cpp (+7 -1)

📄 Description

Fixes #5327.

What

At 0.1.56 the arena RAM guard (#4846, for #4051) started refusing every MemAvailable < need shortfall and taking the --mmap-experts fallback for the run. On Linux that misreads a safe shortfall as #4051's stall:

  • A reserved hugetlb pool (the main case). MemAvailable does not count free huge pages at all, and a launcher may reserve a pool for exactly this arena, which maps MAP_HUGETLB first. The reserve itself takes MemAvailable below the need while holding precisely the pages the load wants. That is the issue's box: 12.8 GiB available for a 31.64 GiB arena with the pool reserved, decode 47 tok/s on 0.1.56-0.1.58 against 116-122 tok/s on 0.1.54/0.1.55, which loaded anyway (expert arena read through the file cache).
  • A small secondary credit for free pages plus droppable file pages (clean cache the kernel evicts as the arena reads). This is within a small margin of MemAvailable's own figure, which already counts nearly all of the page cache (it keeps back only the zone low watermark and reserves), so it bridges only a small shortfall; on the issue's box it is the pool that makes the load fit.

(Correction: the first commit's message and an earlier version of this description said MemAvailable credits only about half of the page cache. That was wrong; the follow-up commit fixes the code comments.)

This restores the warn-and-proceed for exactly those cases. After the existing 20 s wait and the give-back, when the shortfall can be served without touching swap or any program's anonymous memory - MemFree plus Cached + Buffers + SReclaimable - Shmem - Dirty, plus the free hugetlb pages when they hold the whole arena (the MAP_HUGETLB try is all-or-nothing, so a smaller pool serves none of it and is not credited) - the arena loads as 0.1.55 did, and says so on stdout as well as stderr (a service setup never sees the engine's stderr; the line is printed pre-READY, so the app server's protocol reader ignores it, and a direct --serve deployment gets it in its service log). The #4846 refusal stays where #4051's stall risk is real: a shortfall those pages cannot cover (anonymous RAM, e.g. an engine still exiting), under a cgroup limit, and on Windows (the proceed path was never trusted there - its own old note said "buffered (not Windows)", and the mapped-view trim needs the headroom the refusal keeps). STRATA_ARENA_FILE_CACHE=0 turns the credit off and refuses as since 0.1.56; STRATA_ARENA_RAM_FALLBACK=0 still restores the whole old behaviour.

  • the predicate and the /proc/meminfo parsing live in ple_residency.hpp (arena_shortfall_served_by_file_cache, meminfo_free_and_droppable), used at the FallBack verdict in ArenaExpertSource::open; the proceed sets the usual ram_warning_ (the caller's pre-load WARNING) and adds the stdout line
  • the caller's not enough RAM for the expert arena ... reads the experts from the file fallback notice is printed on stdout too, so the slow mode is visible in a service log even where the refusal still applies
  • unit tests in ple_residency_test.cpp pin the two poles: the issue's box (load) and #4051's box (keep the fallback)

Receipts

Same box, same lane/model/args, one fresh boot per arm (kill + GPU-drain gate between boots; decode = client-side tokens in the first 30 s after first token; Qwen3.8-Flash-Next GSQ-RCO Q2_0, --max-context 1048576, --kv int8 --kv-resident 32768). Hardware class: RTX 3090 24 GB + RTX 3060 12 GB (sm_86), 62 GB RAM, Linux. The stock arm is the official 0.1.58 cuda13 component; the patched arm is this branch built locally (CUDA 13.1, sm_86, Release).

engine @ 1M context first-30 s class arena decision at boot
stock 0.1.58 47.2 tok/s SLOW not enough RAM for the expert arena (it needs 31.64 GiB and 12.83 GiB is available (18.82 GiB short, after waiting)): this run reads the experts from the file, like --mmap-experts - stderr only, nothing on stdout
0.1.58 + this PR 124.5 tok/s FAST WARNING: ... 46.50 GiB of free pages, droppable file cache and free huge pages can still hold it: loading through the file cache, as 0.1.55 did (#5327 ...) on stderr AND stdout, then expert arena read through the file cache (buffered (not Windows)), expert arena: cudaHostRegister PORTABLE ok; hugetlb 2 MB pages, loaded 31.64 GiB at 3.10 GiB/s
0.1.54 (control) 113.0 tok/s FAST the old warn-and-proceed (WARNING: ... the load may swap ... (#4051)), same proceed lines

At --max-context 262144 the patched engine measures 114.8 tok/s (FAST); that boot was short as well (23.1 GiB available) and proceeded through the file cache the same way, so the fix also covers the smaller-context boots the issue saw falling back on a cache-hot box. Full-run decode on the patched @1M arm was 123.1 tok/s (5817 tokens), matching the issue's 0.1.54/0.1.55 band (116.4-119.9) against its 0.1.56+ band (45.7-54.3).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5531 **Author:** [@pjgmobile](https://github.com/pjgmobile) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/1m-arena-linux-file-cache` --- ### 📝 Commits (2) - [`6864dce`](https://github.com/Niko1221/Strata/commit/6864dce2dcbe9976ae5cc080d7c7b9dfa4e0b87e) #5327: on Linux an expert-arena shortfall the file cache can serve loads through it again - the 0.1.55 warn-and-proceed (free pages + Cached+Buffers+SReclaimable-Shmem-Dirty cover the need: MemAvailable credits only half the cache), said loudly on stdout as well, because a service setup never sees stderr; the #4846 refusal stays for shortfalls it cannot serve (#4051's anonymous RAM), under a cgroup limit, and on Windows, and STRATA_ARENA_FILE_CACHE=0 turns the credit off; tests - [`63cf748`](https://github.com/Niko1221/Strata/commit/63cf7489329ac0b18ec779aeda4702c2f072560d) #5327: correct the comments - MemAvailable does not credit "only about half" of the page cache (it counts nearly all of it, minus the low watermark); the false alarm this fixes is the reserved hugetlb pool, which MemAvailable does not count at all. The file-cache credit stays as a small secondary margin. Comments only, no code change. ### 📊 Changes **4 files changed** (+140 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/ple_residency.hpp` (+60 -0) 📝 `src/core/expert_source.cpp` (+42 -2) 📝 `src/core/ple_residency_test.cpp` (+31 -0) 📝 `src/program/generate.cpp` (+7 -1) </details> ### 📄 Description Fixes #5327. ## What At 0.1.56 the arena RAM guard (#4846, for #4051) started refusing every `MemAvailable < need` shortfall and taking the `--mmap-experts` fallback for the run. On Linux that misreads a *safe* shortfall as #4051's stall: - **A reserved hugetlb pool** (the main case). MemAvailable does not count free huge pages at all, and a launcher may reserve a pool for exactly this arena, which maps `MAP_HUGETLB` first. The reserve itself takes MemAvailable below the need while holding precisely the pages the load wants. That is the issue's box: 12.8 GiB available for a 31.64 GiB arena with the pool reserved, decode 47 tok/s on 0.1.56-0.1.58 against 116-122 tok/s on 0.1.54/0.1.55, which loaded anyway (`expert arena read through the file cache`). - **A small secondary credit** for free pages plus droppable file pages (clean cache the kernel evicts as the arena reads). This is within a small margin of MemAvailable's own figure, which already counts nearly all of the page cache (it keeps back only the zone low watermark and reserves), so it bridges only a small shortfall; on the issue's box it is the pool that makes the load fit. *(Correction: the first commit's message and an earlier version of this description said MemAvailable credits only about half of the page cache. That was wrong; the follow-up commit fixes the code comments.)* This restores the warn-and-proceed for exactly those cases. After the existing 20 s wait and the give-back, when the shortfall can be served without touching swap or any program's anonymous memory - `MemFree` plus `Cached + Buffers + SReclaimable - Shmem - Dirty`, plus the free hugetlb pages when they hold the *whole* arena (the MAP_HUGETLB try is all-or-nothing, so a smaller pool serves none of it and is not credited) - the arena loads as 0.1.55 did, and says so **on stdout as well as stderr** (a service setup never sees the engine's stderr; the line is printed pre-READY, so the app server's protocol reader ignores it, and a direct `--serve` deployment gets it in its service log). The #4846 refusal stays where #4051's stall risk is real: a shortfall those pages cannot cover (anonymous RAM, e.g. an engine still exiting), under a cgroup limit, and on Windows (the proceed path was never trusted there - its own old note said "buffered (not Windows)", and the mapped-view trim needs the headroom the refusal keeps). `STRATA_ARENA_FILE_CACHE=0` turns the credit off and refuses as since 0.1.56; `STRATA_ARENA_RAM_FALLBACK=0` still restores the whole old behaviour. - the predicate and the /proc/meminfo parsing live in `ple_residency.hpp` (`arena_shortfall_served_by_file_cache`, `meminfo_free_and_droppable`), used at the `FallBack` verdict in `ArenaExpertSource::open`; the proceed sets the usual `ram_warning_` (the caller's pre-load WARNING) and adds the stdout line - the caller's `not enough RAM for the expert arena ... reads the experts from the file` fallback notice is printed on stdout too, so the slow mode is visible in a service log even where the refusal still applies - unit tests in `ple_residency_test.cpp` pin the two poles: the issue's box (load) and #4051's box (keep the fallback) ## Receipts Same box, same lane/model/args, one fresh boot per arm (kill + GPU-drain gate between boots; decode = client-side tokens in the first 30 s after first token; Qwen3.8-Flash-Next GSQ-RCO Q2_0, `--max-context 1048576`, `--kv int8 --kv-resident 32768`). Hardware class: RTX 3090 24 GB + RTX 3060 12 GB (sm_86), 62 GB RAM, Linux. The stock arm is the official 0.1.58 cuda13 component; the patched arm is this branch built locally (CUDA 13.1, sm_86, Release). | engine @ 1M context | first-30 s | class | arena decision at boot | |---|---|---|---| | stock 0.1.58 | **47.2 tok/s** | SLOW | `not enough RAM for the expert arena (it needs 31.64 GiB and 12.83 GiB is available (18.82 GiB short, after waiting)): this run reads the experts from the file, like --mmap-experts` - stderr only, nothing on stdout | | 0.1.58 + this PR | **124.5 tok/s** | FAST | `WARNING: ... 46.50 GiB of free pages, droppable file cache and free huge pages can still hold it: loading through the file cache, as 0.1.55 did (#5327 ...)` on stderr AND stdout, then `expert arena read through the file cache (buffered (not Windows))`, `expert arena: cudaHostRegister PORTABLE ok; hugetlb 2 MB pages`, `loaded 31.64 GiB at 3.10 GiB/s` | | 0.1.54 (control) | **113.0 tok/s** | FAST | the old warn-and-proceed (`WARNING: ... the load may swap ... (#4051)`), same proceed lines | At `--max-context 262144` the patched engine measures **114.8 tok/s** (FAST); that boot was short as well (23.1 GiB available) and proceeded through the file cache the same way, so the fix also covers the smaller-context boots the issue saw falling back on a cache-hot box. Full-run decode on the patched @1M arm was 123.1 tok/s (5817 tokens), matching the issue's 0.1.54/0.1.55 band (116.4-119.9) against its 0.1.56+ band (45.7-54.3). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5504
No description provided.