[PR #202] [CLOSED] ple: --ple-io ram locks the n-gram table in RAM (no SSD read on the prompt/token path) #2508

Closed
opened 2026-11-04 02:00:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/202
Author: @q8atnight
Created: 9/30/2026
Status: ❌ Closed

Base: main ← Head: pr/ple-io-ram


📝 Commits (2)

  • 7f78060 ple: --ple-io ram locks the n-gram table in RAM (no SSD read on the prompt/token path)
  • 6499768 ple: --ple-io ram: refused on Windows (no mlock), 'locked' only when mlock succeeded else 'loaded (not locked)', neutral comments + --help (review)

📊 Changes

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

View changed files

📝 include/strata/kernels/ngram.hpp (+5 -0)
📝 src/kernels/ngram.cpp (+24 -0)
📝 src/program/generate.cpp (+17 -4)

📄 Description

Summary

A third --ple-io mode: ram = the mmap mapping with the whole table mlocked at open, so no SSD read ever
sits on the prompt or token path. madvise(MADV_WILLNEED) first, then mlock; a start log line reports the time
it took. One commit on top of 0.1.27 (a790805). direct stays the default and mmap is unchanged; the ngram
files are untouched upstream, so the change is the PleIoOptions::lock flag, its open() handling, and the
option plumbing.

Measured

On 2x RTX 3090, IQ3_S, 121 GB RAM: stock --ple-io direct reads the 28.8 GB table with O_DIRECT, and a cold 32K
prompt waited ~3 s on those reads. With ram the table is mapped and locked once at start, and no table read
touches the SSD again. In use on our box since 2026-09-28 with no issue.

Cost and failure mode

ram costs host RAM = the table size (28.8 GB here; our IQ3_S dual setup uses ~82 of 121 GB). If mlock is
refused — ulimit -l too low, Docker's default memlock is 64 KB — the engine does NOT fail: it prints
strata: PLE table mlock failed (...): touching its pages instead and touches every page, so the table still
enters the page cache but the kernel may evict it under memory pressure. For the lock itself to hold, start with
ulimit -l unlimited (Docker: --ulimit memlock=-1). The log line
strata generate: PLE table locked in RAM (--ple-io ram) in X s distinguishes the two outcomes.

Switch

--ple-io ram is opt-in; direct (and mmap) behave exactly as before.


🔄 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/202 **Author:** [@q8atnight](https://github.com/q8atnight) **Created:** 9/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/ple-io-ram` --- ### 📝 Commits (2) - [`7f78060`](https://github.com/Niko1221/Strata/commit/7f780604de7b3b824f3e26d3d4fcb5ba83bd01ee) ple: --ple-io ram locks the n-gram table in RAM (no SSD read on the prompt/token path) - [`6499768`](https://github.com/Niko1221/Strata/commit/64997681466f51da45d7d588c636008e7c7b8436) ple: --ple-io ram: refused on Windows (no mlock), 'locked' only when mlock succeeded else 'loaded (not locked)', neutral comments + --help (review) ### 📊 Changes **3 files changed** (+46 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/kernels/ngram.hpp` (+5 -0) 📝 `src/kernels/ngram.cpp` (+24 -0) 📝 `src/program/generate.cpp` (+17 -4) </details> ### 📄 Description ## Summary A third `--ple-io` mode: `ram` = the `mmap` mapping with the whole table `mlock`ed at open, so no SSD read ever sits on the prompt or token path. `madvise(MADV_WILLNEED)` first, then `mlock`; a start log line reports the time it took. One commit on top of 0.1.27 (a790805). `direct` stays the default and `mmap` is unchanged; the ngram files are untouched upstream, so the change is the `PleIoOptions::lock` flag, its `open()` handling, and the option plumbing. ## Measured On 2x RTX 3090, IQ3_S, 121 GB RAM: stock `--ple-io direct` reads the 28.8 GB table with O_DIRECT, and a cold 32K prompt waited ~3 s on those reads. With `ram` the table is mapped and locked once at start, and no table read touches the SSD again. In use on our box since 2026-09-28 with no issue. ## Cost and failure mode `ram` costs host RAM = the table size (28.8 GB here; our IQ3_S dual setup uses ~82 of 121 GB). If `mlock` is refused — `ulimit -l` too low, Docker's default memlock is 64 KB — the engine does NOT fail: it prints `strata: PLE table mlock failed (...): touching its pages instead` and touches every page, so the table still enters the page cache but the kernel may evict it under memory pressure. For the lock itself to hold, start with `ulimit -l unlimited` (Docker: `--ulimit memlock=-1`). The log line `strata generate: PLE table locked in RAM (--ple-io ram) in X s` distinguishes the two outcomes. ## Switch `--ple-io ram` is opt-in; `direct` (and `mmap`) behave exactly as before. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:00:49 +07:00
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#2508
No description provided.