[GH-ISSUE #1194] file_cache_keeps() picks unbuffered (O_DIRECT) expert reads on a 32 GB + 12 GB GPU box with --resident-budget-gib, halving decode; STRATA_UNBUFFERED_LOAD=0 restores it #494

Closed
opened 2026-11-04 01:43:30 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @willthehuman on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1194

Engine: 0.1.40 (locally built, Linux, arch=compute_89)
Config: Q2_0 (native experts v3 pack), --mmap-experts --resident-budget-gib 18 --kv-resident 32768 --conversation-cache-mib 3072 --conversation-cache-slots 4, context 131072, --ple-io default
Machine: i7-8700, 31 GB RAM, RTX 4070 SUPER 12 GB, NVMe (models read from an NTFS pack volume)

Symptom

Same benchmark before and after the update — greedy, "Count from 1 to 200, one number per line", max_tokens 260, fresh engine process each time:

  • 0.1.39: 67.4 / 58.2 / 69.6 / 59.7 / 68.3 t/s — NVMe reads 95–190 MB/s
  • 0.1.40: 29.4 / 31.2 / 32.7 / 33.0 / 31.9 t/s — NVMe reads 657–987 MB/s

What the engine says

The budget itself is granted, so this is not the clamp:

FileExpertSource: RAM budget 18.00 GiB: 13981 of the 25.86 GiB of experts the GPU cache does not hold, by profile rank; the rest are read from the files
FileExpertSource: mapped pinned cache complement ready: resident 18.00 GiB, pinned 18.00 GiB; page-locked and mapped
strata generate: the file tier reads unbuffered (re-checked with the RAM copy built (18.00 GiB): 6.4 GiB available, 0.0 GiB of it still to be taken by the RAM copy, 13.6 GiB of experts read from the files: the file cache cannot keep them)

Where the time goes

GET /metrics per 260-token request — the requested volume is the same on both versions, only the cache hits differ:

  • ram_blobs ~19 000–22 000, file_blobs ~7 500–8 300, file_mb ~10–11 GB (both versions)
  • with unbuffered reads the disk sees ~6.4 GB per request; with the file cache it saw ~1 GB (measured at the block layer, 0.1.39)

Workaround that restored full speed

STRATA_UNBUFFERED_LOAD=0 (systemd drop-in for our service):

strata generate: the file tier reads through the file cache (STRATA_UNBUFFERED_LOAD=0)

→ 65.4 / 55.1 / 63.5 t/s at 136–203 MB/s, i.e. 0.1.39-level speed with the 0.1.40 engine and all the new code.

Why the heuristic looks wrong for this case

file_cache_keeps(avail, arena_bytes, read_bytes) compares all file-read bytes (13.6 GiB) against available RAM (6.4 GiB) and concludes the cache is useless. But the file tier is a hot subset: the same experts repeat across tokens (~30 file blobs per token here, with an 82% VRAM hit-rate), and roughly 2–3 GB of page cache was enough to serve them — 0.1.39 had no O_DIRECT tier and was 2× faster on identical hardware, config and prompt.

Possible improvements, in the project's measured style:

  1. With --resident-budget-gib set, default the file tier to buffered (or re-evaluate after the first requests, from the observed hit pattern) — the budget already guarantees the "all experts in RAM" case is not being attempted.
  2. Mention the trade-off in DETAILS.md next to #286, and note STRATA_UNBUFFERED_LOAD=0 for the "resident budget + small page cache" case.
  3. Setup could pick it (--low-ram answers) for machines like this one (32 GB RAM, 12 GB GPU, mapped+resident).

The docs' own #773 note ("forcing unbuffered reads there re-read 163–629 GB from the drive and halved the speed") describes the same failure mode in the no-budget case; this is the with-budget analogue, and the numbers are close (halved speed, ~6× the drive traffic).

Originally created by @willthehuman on GitHub (Oct 6, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1194 **Engine:** 0.1.40 (locally built, Linux, `arch=compute_89`) **Config:** Q2_0 (`native experts v3` pack), `--mmap-experts --resident-budget-gib 18 --kv-resident 32768 --conversation-cache-mib 3072 --conversation-cache-slots 4`, context 131072, `--ple-io` default **Machine:** i7-8700, 31 GB RAM, RTX 4070 SUPER 12 GB, NVMe (models read from an NTFS pack volume) ## Symptom Same benchmark before and after the update — greedy, "Count from 1 to 200, one number per line", `max_tokens 260`, fresh engine process each time: - **0.1.39:** 67.4 / 58.2 / 69.6 / 59.7 / 68.3 t/s — NVMe reads **95–190 MB/s** - **0.1.40:** 29.4 / 31.2 / 32.7 / 33.0 / 31.9 t/s — NVMe reads **657–987 MB/s** ## What the engine says The budget itself is granted, so this is not the clamp: ``` FileExpertSource: RAM budget 18.00 GiB: 13981 of the 25.86 GiB of experts the GPU cache does not hold, by profile rank; the rest are read from the files FileExpertSource: mapped pinned cache complement ready: resident 18.00 GiB, pinned 18.00 GiB; page-locked and mapped strata generate: the file tier reads unbuffered (re-checked with the RAM copy built (18.00 GiB): 6.4 GiB available, 0.0 GiB of it still to be taken by the RAM copy, 13.6 GiB of experts read from the files: the file cache cannot keep them) ``` ## Where the time goes `GET /metrics` per 260-token request — the requested volume is the same on both versions, only the cache hits differ: - ram_blobs ~19 000–22 000, file_blobs ~7 500–8 300, **file_mb ~10–11 GB** (both versions) - with unbuffered reads the disk sees **~6.4 GB per request**; with the file cache it saw ~1 GB (measured at the block layer, 0.1.39) ## Workaround that restored full speed `STRATA_UNBUFFERED_LOAD=0` (systemd drop-in for our service): ``` strata generate: the file tier reads through the file cache (STRATA_UNBUFFERED_LOAD=0) ``` → 65.4 / 55.1 / 63.5 t/s at 136–203 MB/s, i.e. 0.1.39-level speed with the 0.1.40 engine and all the new code. ## Why the heuristic looks wrong for this case `file_cache_keeps(avail, arena_bytes, read_bytes)` compares **all** file-read bytes (13.6 GiB) against available RAM (6.4 GiB) and concludes the cache is useless. But the file tier is a **hot subset**: the same experts repeat across tokens (~30 file blobs per token here, with an 82% VRAM hit-rate), and roughly 2–3 GB of page cache was enough to serve them — 0.1.39 had no O_DIRECT tier and was 2× faster on identical hardware, config and prompt. Possible improvements, in the project's measured style: 1. With `--resident-budget-gib` set, default the file tier to buffered (or re-evaluate after the first requests, from the observed hit pattern) — the budget already guarantees the "all experts in RAM" case is not being attempted. 2. Mention the trade-off in DETAILS.md next to #286, and note `STRATA_UNBUFFERED_LOAD=0` for the "resident budget + small page cache" case. 3. Setup could pick it (`--low-ram` answers) for machines like this one (32 GB RAM, 12 GB GPU, mapped+resident). The docs' own #773 note ("forcing unbuffered reads there re-read 163–629 GB from the drive and halved the speed") describes the same failure mode in the no-budget case; this is the with-budget analogue, and the numbers are close (halved speed, ~6× the drive traffic).
Author
Owner

@willthehuman commented on GitHub (Oct 6, 2026):

Related history from the tracker (for triage): #577 (0.1.38, same failure class on a 96 GB PC, closed) and #773 / #362 (the unbuffered file tier itself). This is the 0.1.40 case with --resident-budget-gib set: the heuristic concludes the cache cannot keep the 13.6 GiB of file-read experts, but the hot subset fits and STRATA_UNBUFFERED_LOAD=0 restores 0.1.39-level speed on the same engine.

<!-- gh-comment-id:6019694993 --> @willthehuman commented on GitHub (Oct 6, 2026): Related history from the tracker (for triage): #577 (0.1.38, same failure class on a 96 GB PC, closed) and #773 / #362 (the unbuffered file tier itself). This is the 0.1.40 case **with** `--resident-budget-gib` set: the heuristic concludes the cache cannot keep the 13.6 GiB of file-read experts, but the hot subset fits and `STRATA_UNBUFFERED_LOAD=0` restores 0.1.39-level speed on the same engine.
Author
Owner

@Niko1221 commented on GitHub (Oct 7, 2026):

Fixed in 0.1.40.2. You were right: the file tier is a hot subset, and 0.1.40 asked the cache to hold all of the experts it reads. Now it reads unbuffered only when the cache cannot hold a twentieth of them (at least 1.5 GiB beside a 1 GiB reserve), and through the cache otherwise. On a Tesla P100 box under a 32 GB cgroup, budget 18 (the same ratio as your 31 GB case), 10 interleaved pairs: decode 12.6 -> 15.2 tok/s on the story prompt and 9.3 -> 13.3 on the code prompt, 10 of 10 pairs faster, with 3 to 7 times less drive traffic. The answers are the same text. On 0.1.40 / 0.1.40.1 your STRATA_UNBUFFERED_LOAD=0 is exactly this.

<!-- gh-comment-id:6038058101 --> @Niko1221 commented on GitHub (Oct 7, 2026): Fixed in 0.1.40.2. You were right: the file tier is a hot subset, and 0.1.40 asked the cache to hold all of the experts it reads. Now it reads unbuffered only when the cache cannot hold a twentieth of them (at least 1.5 GiB beside a 1 GiB reserve), and through the cache otherwise. On a Tesla P100 box under a 32 GB cgroup, budget 18 (the same ratio as your 31 GB case), 10 interleaved pairs: decode 12.6 -> 15.2 tok/s on the story prompt and 9.3 -> 13.3 on the code prompt, 10 of 10 pairs faster, with 3 to 7 times less drive traffic. The answers are the same text. On 0.1.40 / 0.1.40.1 your STRATA_UNBUFFERED_LOAD=0 is exactly this.
Author
Owner

@willthehuman commented on GitHub (Oct 7, 2026):

Confirmed fixed on the reporting box — 0.1.40.2, Linux, same config (Q2_0, budget 18). The engine now picks the cached path on its own (the STRATA_UNBUFFERED_LOAD=0 workaround is removed here): warmed decode back to 49–63 t/s and per-request drive reads down from ~6.4 GB to ~0.5 GB. Matches the direction of your P100 pairs. Thanks!

FYI from the same hardware, same file tier: with a DRAM-less NVMe (Fanxiang S501), the single-stream page-fault path was the ceiling under heavy load (~116 MB/s, decode dropping to ~6 t/s). STRATA_IO_PREFETCH=1 transformed it: cold reads ~890 MB/s and a 98K-token context reload from ~13 min down to ~3.5 min. Might be worth a docs note for DRAM-less drives.

<!-- gh-comment-id:6041125374 --> @willthehuman commented on GitHub (Oct 7, 2026): Confirmed fixed on the reporting box — 0.1.40.2, Linux, same config (Q2_0, budget 18). The engine now picks the cached path on its own (the `STRATA_UNBUFFERED_LOAD=0` workaround is removed here): warmed decode back to 49–63 t/s and per-request drive reads down from ~6.4 GB to ~0.5 GB. Matches the direction of your P100 pairs. Thanks! FYI from the same hardware, same file tier: with a DRAM-less NVMe (Fanxiang S501), the single-stream page-fault path was the ceiling under heavy load (~116 MB/s, decode dropping to ~6 t/s). `STRATA_IO_PREFETCH=1` transformed it: cold reads ~890 MB/s and a 98K-token context reload from ~13 min down to ~3.5 min. Might be worth a docs note for DRAM-less drives.
Author
Owner

@Niko1221 commented on GitHub (Oct 7, 2026):

Thanks for confirming it is fixed on your box. Closing.

<!-- gh-comment-id:6043794280 --> @Niko1221 commented on GitHub (Oct 7, 2026): Thanks for confirming it is fixed on your box. Closing.
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#494
No description provided.