[GH-ISSUE #4104] [Engine] --ple-io ram faults the 26.8 GiB PLE table in with a per-page userspace toucher: 310 s (~90 MB/s) where one MADV_POPULATE_READ runs at the drive's 979 MB/s #1795

Closed
opened 2026-11-04 01:54:08 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @chenyb999-zhcn on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4104

Area

[Engine]

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

A cold --serve start with --ple-io ram spends 310.3 s faulting the 26.8 GiB PLE n-gram table into the page cache before it mlocks it (215 s when a previous run left some of it cached) — ~90 MB/s — while the drive underneath it (NVMe) reads the same file range sequentially at 881 MB/s: the raw media time is ~31 s. The startup script drops caches first, so every start pays this cold.

The fault-in in PleTable::open (src/kernels/ngram.cpp, POSIX branch of the --ple-io ram setup) does three things:

  1. madvise(MADV_WILLNEED) over the whole 26.8 GiB range — the kernel readahead window is capped far below that, so the advise mostly asks for nothing;
  2. a 16-thread pool touches the mapping page by page at a 4096-byte stride from userspace — ~7 million page faults, each a synchronous trap into the kernel that faults one 4 KiB page at a time. This is the 310 s; it is a software cost, not a disk cost, and it neither overlaps reads nor uses the readahead the advise asked for;
  3. one whole-range mlock() afterwards, which walks the same page tables a second time.

Measured on this machine with a standalone ctypes probe against the real shard (engine stopped, drop_caches before each cold pass), on the 26.8 GiB table:

method cold cache-warm
current: WILLNEED + 16-thread per-page touch ~310 s (~90 MB/s) 16.7 s
one whole-range madvise(MADV_POPULATE_READ) (Linux 5.14+) 28.1 s (979 MB/s — the drive itself) 0.7 s
MADV_POPULATE_READ split over 16 threads by 64 MiB pieces 225.6 s (122 MB/s) —
mlock() alone after the pages are faulted 0.5–0.8 s 0.5 s

Two findings worth stating before any fix: the kernel-side batched populate exists (since 5.14) and runs at full device speed with one thread, because the single advise keeps the reads sequential; chunking the same advise across threads collapses it to random read-ahead (225.6 s), so the parallel shape only ever pays when the bytes are already in RAM. mlock itself is never the problem (≤0.8 s) and does not need parallelising.

Expected behaviour: --ple-io ram faults the table in at the speed of the device it is reading from, instead of at userspace-page-fault speed.

I have this patched (single whole-range MADV_POPULATE_READ, falling back to the current WILLNEED + touch pool where the advise answers ENOSYS/EINVAL, plus a split timing line): the startup line goes from

strata generate: PLE table locked in RAM (--ple-io ram) in 310.3 s

to

strata: PLE table 26.8 GiB: populated in 33.1 s, mlock in 0.5 s      (cold)
strata generate: PLE table locked in RAM (--ple-io ram) in 1.5 s     (cache-warm restart)

The PR is ready to open from chenyb999-zhcn:engine-ple-populate once this is filed — say the word if a different shape is wanted.

Side note while in there: the comments in tools/iq_pack.py and generate.cpp say the PLE table lives in shard 1; on this pack it is in shard 2 (file offset 682,453,280).

Smallest steps or command that reproduce it

  1. Linux ≥ 5.14, a pack with the n-gram table, enough RAM to cover it.
  2. sync && echo 3 > /proc/sys/vm/drop_caches
  3. strata generate --serve ... --ple-io ram and read the PLE table locked in RAM in X s line. Compare with dd if=<shard gguf> bs=1M skip=<PLE offset MiB> count=27000 iflag=direct | pv >/dev/null on the same file.

Reproduction status

Reproduced locally

Strata version

Strata 0.2.5 · engine 0.1.49.1 (patch validated on engine 0.1.50)

Graphics card, memory and system

2x Tesla V100-PCIE 32 GB · 96 GB RAM · Ubuntu 26.04.1 LTS (kernel 7.0.0-38-generic) · ZhiTai Ti600 1 TB NVMe

Model, size and settings

Qwen3.8-Flash-Next UD-Q4_K_XL · 131K context · --ple-io ram --layer-split auto · pictures on

Logs

strata generate: PLE table locked in RAM (--ple-io ram) in 310.3 s   (before, cold)
strata generate: PLE table locked in RAM (--ple-io ram) in 215.0 s   (before, warm)
strata: PLE table 26.8 GiB: populated in 33.1 s, mlock in 0.5 s      (after, cold)
strata: PLE table 26.8 GiB: populated in 0.8 s, mlock in 0.8 s       (after, warm)
Originally created by @chenyb999-zhcn on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4104 ### Area [Engine] ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### What happened A cold `--serve` start with `--ple-io ram` spends 310.3 s faulting the 26.8 GiB PLE n-gram table into the page cache before it mlocks it (215 s when a previous run left some of it cached) — ~90 MB/s — while the drive underneath it (NVMe) reads the same file range sequentially at 881 MB/s: the raw media time is ~31 s. The startup script drops caches first, so every start pays this cold. The fault-in in `PleTable::open` (src/kernels/ngram.cpp, POSIX branch of the `--ple-io ram` setup) does three things: 1. `madvise(MADV_WILLNEED)` over the whole 26.8 GiB range — the kernel readahead window is capped far below that, so the advise mostly asks for nothing; 2. a 16-thread pool touches the mapping **page by page at a 4096-byte stride from userspace** — ~7 million page faults, each a synchronous trap into the kernel that faults one 4 KiB page at a time. This is the 310 s; it is a software cost, not a disk cost, and it neither overlaps reads nor uses the readahead the advise asked for; 3. one whole-range `mlock()` afterwards, which walks the same page tables a second time. Measured on this machine with a standalone ctypes probe against the real shard (engine stopped, `drop_caches` before each cold pass), on the 26.8 GiB table: | method | cold | cache-warm | | --- | --- | --- | | current: WILLNEED + 16-thread per-page touch | ~310 s (~90 MB/s) | 16.7 s | | one whole-range `madvise(MADV_POPULATE_READ)` (Linux 5.14+) | **28.1 s (979 MB/s — the drive itself)** | **0.7 s** | | `MADV_POPULATE_READ` split over 16 threads by 64 MiB pieces | 225.6 s (122 MB/s) | — | | `mlock()` alone after the pages are faulted | 0.5–0.8 s | 0.5 s | Two findings worth stating before any fix: the kernel-side batched populate exists (since 5.14) and runs at full device speed with **one** thread, because the single advise keeps the reads sequential; chunking the same advise across threads collapses it to random read-ahead (225.6 s), so the parallel shape only ever pays when the bytes are already in RAM. `mlock` itself is never the problem (≤0.8 s) and does not need parallelising. Expected behaviour: `--ple-io ram` faults the table in at the speed of the device it is reading from, instead of at userspace-page-fault speed. I have this patched (single whole-range `MADV_POPULATE_READ`, falling back to the current WILLNEED + touch pool where the advise answers ENOSYS/EINVAL, plus a split timing line): the startup line goes from strata generate: PLE table locked in RAM (--ple-io ram) in 310.3 s to strata: PLE table 26.8 GiB: populated in 33.1 s, mlock in 0.5 s (cold) strata generate: PLE table locked in RAM (--ple-io ram) in 1.5 s (cache-warm restart) The PR is ready to open from `chenyb999-zhcn:engine-ple-populate` once this is filed — say the word if a different shape is wanted. Side note while in there: the comments in `tools/iq_pack.py` and `generate.cpp` say the PLE table lives in shard 1; on this pack it is in shard 2 (file offset 682,453,280). ### Smallest steps or command that reproduce it 1. Linux ≥ 5.14, a pack with the n-gram table, enough RAM to cover it. 2. `sync && echo 3 > /proc/sys/vm/drop_caches` 3. `strata generate --serve ... --ple-io ram` and read the `PLE table locked in RAM in X s` line. Compare with `dd if=<shard gguf> bs=1M skip=<PLE offset MiB> count=27000 iflag=direct | pv >/dev/null` on the same file. ### Reproduction status Reproduced locally ### Strata version Strata 0.2.5 · engine 0.1.49.1 (patch validated on engine 0.1.50) ### Graphics card, memory and system 2x Tesla V100-PCIE 32 GB · 96 GB RAM · Ubuntu 26.04.1 LTS (kernel 7.0.0-38-generic) · ZhiTai Ti600 1 TB NVMe ### Model, size and settings Qwen3.8-Flash-Next UD-Q4_K_XL · 131K context · `--ple-io ram` `--layer-split auto` · pictures on ### Logs strata generate: PLE table locked in RAM (--ple-io ram) in 310.3 s (before, cold) strata generate: PLE table locked in RAM (--ple-io ram) in 215.0 s (before, warm) strata: PLE table 26.8 GiB: populated in 33.1 s, mlock in 0.5 s (after, cold) strata: PLE table 26.8 GiB: populated in 0.8 s, mlock in 0.8 s (after, warm)
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Thanks for taking the time to report this.

Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6660006277 --> @Niko1221 commented on GitHub (Nov 5, 2026): Thanks for taking the time to report this. Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
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#1795
No description provided.