[PR #385] [CLOSED] Prompt path: a stager buffer's first job of a generation waits for the previous DMA from it (a narrow race with unpinned blobs) #2612

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/385
Author: @sergqwer
Created: 10/1/2026
Status: ❌ Closed

Base: main ← Head: pr/stager-dma


📝 Commits (1)

  • c55854c Prompt path: a stager buffer's first job of a generation waits for the previous DMA from it

📊 Changes

1 file changed (+5 additions, -3 deletions)

View changed files

📝 src/prefill/prefill.cpp (+5 -3)

📄 Description

Stager::work waits for a buffer's DMA only from a generation's kRing-th job on (j >= kRing). A generation's first kRing jobs memcpy into their pinned buffers straight away.

So the previous generation's last DMAs from those buffers are only known to be done where something else waits for them:

  • staged layers (chunks below stream_all_min): the routing sync (cudaStreamSynchronize(m.cs)) before the layer's start();
  • stream_all chunks: the sync at the end of a chunk, which runs only with an MTP drafter (on_chunk) or a layer split (on_stage_chunk).

That leaves a window in two cases:

  • a stream_all chunk that ends without that sync (no --mtp);
  • a ring entry the routing skipped. Its copy was issued, but nothing waits for it, so even a chunk-end sync of the compute stream does not cover it.

In that window, the next chunk's first jobs can overwrite a pinned buffer that a cudaMemcpyAsync on the copy stream is still reading. It only matters with unpinned blobs, which go through the stager: the RAM-budget tier, or a partially pinned arena.

The fix: the event is now waited for on every job. An event that was never recorded, or has already completed, returns at once. For j < kRing, no job of the current generation can have recorded the event, so the wait is exactly the previous generation's last DMA from that buffer.

We found it in an audit of our fork. We have not seen it corrupt a run: it needs that timing and the unpinned path.

Measured:

  • IQ2_XS with --mmap-experts --resident-budget-gib 16: 12,144 of the 48,668 streamed experts went through the stager.
  • The tokens on a 32K prompt are the same as on 0.1.31.
  • Prefill took 6,546 ms vs 6,491 ms (noise).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 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/385 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/stager-dma` --- ### 📝 Commits (1) - [`c55854c`](https://github.com/Niko1221/Strata/commit/c55854cf3f23fda6f74d2a4a190f8cdca1b17e23) Prompt path: a stager buffer's first job of a generation waits for the previous DMA from it ### 📊 Changes **1 file changed** (+5 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/prefill/prefill.cpp` (+5 -3) </details> ### 📄 Description `Stager::work` waits for a buffer's DMA only from a generation's `kRing`-th job on (`j >= kRing`). A generation's first `kRing` jobs `memcpy` into their pinned buffers straight away. So the previous generation's last DMAs from those buffers are only known to be done where something else waits for them: - **staged layers** (chunks below `stream_all_min`): the routing sync (`cudaStreamSynchronize(m.cs)`) before the layer's `start()`; - **`stream_all` chunks:** the sync at the end of a chunk, which runs only with an MTP drafter (`on_chunk`) or a layer split (`on_stage_chunk`). That leaves a window in two cases: - a `stream_all` chunk that ends without that sync (no `--mtp`); - a ring entry the routing skipped. Its copy was issued, but nothing waits for it, so even a chunk-end sync of the compute stream does not cover it. In that window, the next chunk's first jobs can overwrite a pinned buffer that a `cudaMemcpyAsync` on the copy stream is still reading. It only matters with unpinned blobs, which go through the stager: the RAM-budget tier, or a partially pinned arena. **The fix:** the event is now waited for on every job. An event that was never recorded, or has already completed, returns at once. For `j < kRing`, no job of the current generation can have recorded the event, so the wait is exactly the previous generation's last DMA from that buffer. We found it in an audit of our fork. We have not seen it corrupt a run: it needs that timing and the unpinned path. **Measured:** - IQ2_XS with `--mmap-experts --resident-budget-gib 16`: 12,144 of the 48,668 streamed experts went through the stager. - The tokens on a 32K prompt are the same as on 0.1.31. - Prefill took 6,546 ms vs 6,491 ms (noise). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:01:45 +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#2612
No description provided.