[PR #4105] [Engine] --ple-io ram: read the PLE table into page-locked RAM with the unbuffered reader instead of faulting it in through the page cache #4901

Open
opened 2026-11-07 16:31:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4105
Author: @chenyb999-zhcn
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: engine-ple-populate


📝 Commits (1)

  • 8f81cee ple: --ple-io ram reads the table into page-locked RAM with the unbuffered reader instead of faulting it in through the page cache: one MADV_POPULATE_READ walks the 26.8 GiB table one 4 KiB fault at a time (120.1 s, 240 MB/s on the box of #4104, cold) and eight parallel populate chunks are worse, not better (266.2 s - the chunks' read-ahead competes for the same window), while this same drive does 940 MB/s for the engine's unbuffered expert-complement copy; so map an anonymous region, lock it first (no swap window while it is filled), read the table into it with 4 MiB O_DIRECT requests over eight workers (23.7 s, 1215 MB/s measured, mlock 5.8 s) and point the row readers at it - the row path is unchanged, and the page-cache populate stays as the fallback for kernels without MADV_POPULATE_READ or a refused lock; cache-warm startup is unchanged (0.3 s), and the table no longer occupies 26.8 GiB of page cache (#4104)

📊 Changes

1 file changed (+99 additions, -22 deletions)

View changed files

📝 src/kernels/ngram.cpp (+99 -22)

📄 Description

Closes #4104

Problem and result

--ple-io ram brings the 26.8 GiB PLE n-gram table into RAM at startup and locks it. The path it used was the page
cache: madvise(MADV_WILLNEED) plus a 16-thread page-by-page toucher (the original shape), then one
MADV_POPULATE_READ (this PR's first shape). On the box of #4104 (2x Tesla V100 32 GB, 96 GB RAM, ZhiTai Ti600
1 TB NVMe) a cold start paid for 26.8 GiB:

shape cold
WILLNEED + 16-thread per-page toucher (0.1.49.x) 310.3 s (~90 MB/s)
one MADV_POPULATE_READ 120.1 s (240 MB/s)
eight 512 MiB MADV_POPULATE_READ chunks 266.2 s (108 MB/s) - worse, the chunks' read-ahead competes
this PR: read into page-locked RAM, 4 MiB O_DIRECT over 8 workers 23.7 s (1215 MB/s), mlock 5.8 s

Every page-cache shape is fault driven: each page is its own 4 KiB fault and the read-ahead window is one 128 KiB
request, so more threads only make the windows compete. The engine's own unbuffered expert-complement copy on the
same machine and the same drive does 940 MB/s - that is the shape that reaches the device.

What changed

PleTable::open for --ple-io ram (POSIX):

  1. map an anonymous region and mlock it before filling it (no swap window while it is being written),
  2. read the table into it with platform::read_range_direct - 4 MiB O_DIRECT requests, eight workers, the table's
    file offset and length rounded to 512 bytes as O_DIRECT requires,
  3. point impl_->data at the region; the row readers, the gather path and the prompt path are untouched,
  4. release the region in close().

The page-cache populate stays as the fallback for kernels without MADV_POPULATE_READ or a refused lock, and the
WILLNEED + touch loop stays below that.

platform::read_range_direct is a small general helper (path, offset, length, destination, workers) that other
startup loaders use for the same reason.

Validation

Same box, same model, engine 0.1.50 + this commit, --ple-io ram, launch script with drop_caches:

strata: PLE table 26.8 GiB: read into page-locked RAM in 23.7 s (1215 MB/s), mlock in 5.8 s
strata generate: PLE table locked in RAM (--ple-io ram) in 29.5 s
  • cache-warm population: 0.3 s (0.8 s with the one-shot populate),
  • the log line names the shape, so a startup log shows which path ran,
  • the rest of the startup is covered by #4064; this PR is only the table.

Limits

  • The table no longer counts as page cache (it is anonymous locked memory now), so the page cache has 26.8 GiB more
    room for the model's shards. The process's RSS is unchanged.

  • mlock still needs ulimit -l unlimited (setup sets it). A refused lock falls back to the page-cache path and
    says so in the log.

  • Windows is untouched: it has no populate advice, and its existing VirtualLock path stays as it is.

  • On the reporting box a restart finds the table in the page cache (the mlock is released with the process); the
    follow-up series in #4064 adds a mincore probe (platform::resident_fraction) that then takes the populate
    path (0.3 s) instead of reading 26.8 GiB again. This PR is the cold path: 120.1 s -> 24.2 s.


🔄 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/4105 **Author:** [@chenyb999-zhcn](https://github.com/chenyb999-zhcn) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `engine-ple-populate` --- ### 📝 Commits (1) - [`8f81cee`](https://github.com/Niko1221/Strata/commit/8f81cee6453b734fd36446aa27fa910ccfb9ebae) ple: --ple-io ram reads the table into page-locked RAM with the unbuffered reader instead of faulting it in through the page cache: one MADV_POPULATE_READ walks the 26.8 GiB table one 4 KiB fault at a time (120.1 s, 240 MB/s on the box of #4104, cold) and eight parallel populate chunks are worse, not better (266.2 s - the chunks' read-ahead competes for the same window), while this same drive does 940 MB/s for the engine's unbuffered expert-complement copy; so map an anonymous region, lock it first (no swap window while it is filled), read the table into it with 4 MiB O_DIRECT requests over eight workers (23.7 s, 1215 MB/s measured, mlock 5.8 s) and point the row readers at it - the row path is unchanged, and the page-cache populate stays as the fallback for kernels without MADV_POPULATE_READ or a refused lock; cache-warm startup is unchanged (0.3 s), and the table no longer occupies 26.8 GiB of page cache (#4104) ### 📊 Changes **1 file changed** (+99 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/ngram.cpp` (+99 -22) </details> ### 📄 Description Closes #4104 ## Problem and result `--ple-io ram` brings the 26.8 GiB PLE n-gram table into RAM at startup and locks it. The path it used was the page cache: `madvise(MADV_WILLNEED)` plus a 16-thread page-by-page toucher (the original shape), then one `MADV_POPULATE_READ` (this PR's first shape). On the box of #4104 (2x Tesla V100 32 GB, 96 GB RAM, ZhiTai Ti600 1 TB NVMe) a cold start paid for 26.8 GiB: | shape | cold | |---|---| | WILLNEED + 16-thread per-page toucher (0.1.49.x) | 310.3 s (~90 MB/s) | | one `MADV_POPULATE_READ` | 120.1 s (240 MB/s) | | eight 512 MiB `MADV_POPULATE_READ` chunks | 266.2 s (108 MB/s) - worse, the chunks' read-ahead competes | | **this PR: read into page-locked RAM, 4 MiB O_DIRECT over 8 workers** | **23.7 s (1215 MB/s), mlock 5.8 s** | Every page-cache shape is fault driven: each page is its own 4 KiB fault and the read-ahead window is one 128 KiB request, so more threads only make the windows compete. The engine's own unbuffered expert-complement copy on the same machine and the same drive does 940 MB/s - that is the shape that reaches the device. ## What changed `PleTable::open` for `--ple-io ram` (POSIX): 1. map an anonymous region and `mlock` it *before* filling it (no swap window while it is being written), 2. read the table into it with `platform::read_range_direct` - 4 MiB O_DIRECT requests, eight workers, the table's file offset and length rounded to 512 bytes as O_DIRECT requires, 3. point `impl_->data` at the region; the row readers, the gather path and the prompt path are untouched, 4. release the region in `close()`. The page-cache populate stays as the fallback for kernels without `MADV_POPULATE_READ` or a refused lock, and the WILLNEED + touch loop stays below that. `platform::read_range_direct` is a small general helper (path, offset, length, destination, workers) that other startup loaders use for the same reason. ## Validation Same box, same model, engine 0.1.50 + this commit, `--ple-io ram`, launch script with `drop_caches`: ``` strata: PLE table 26.8 GiB: read into page-locked RAM in 23.7 s (1215 MB/s), mlock in 5.8 s strata generate: PLE table locked in RAM (--ple-io ram) in 29.5 s ``` - cache-warm population: 0.3 s (0.8 s with the one-shot populate), - the log line names the shape, so a startup log shows which path ran, - the rest of the startup is covered by #4064; this PR is only the table. ## Limits - The table no longer counts as page cache (it is anonymous locked memory now), so the page cache has 26.8 GiB more room for the model's shards. The process's RSS is unchanged. - `mlock` still needs `ulimit -l unlimited` (setup sets it). A refused lock falls back to the page-cache path and says so in the log. - Windows is untouched: it has no populate advice, and its existing VirtualLock path stays as it is. - On the reporting box a restart finds the table in the page cache (the mlock is released with the process); the follow-up series in #4064 adds a `mincore` probe (`platform::resident_fraction`) that then takes the populate path (0.3 s) instead of reading 26.8 GiB again. This PR is the cold path: 120.1 s -> 24.2 s. --- <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#4901
No description provided.