I'm building FerriteRT, a Rust inference runtime for Mixture-of-Experts models. Its core trick is not holding all the experts in GPU memory: a fetch coordinator thread streams them from NVMe as the router asks for them. On my DGX Spark (GB10, unified memory) that works. The same code on my Windows gaming PC (RTX 3080 Ti, native Windows 11, a discrete GPU behind PCIe) failed its first checkpoint so badly it looked like a different program.
Over one long day my coding agents and I took it from failing to passing. Every step was measured. Almost none of the causes were in the residency design itself. They were Windows and WDDM behaviours. Some are well known in other corners (audio, gaming, filesystem drivers), others are documented only in pieces, and I hadn't seen them gathered for CUDA on Windows. Here they are, each with the number that showed it and the fix. The prior art I found afterwards is linked at the end.
The setup, in one paragraph
Each layer has a pinned-memory doorbell. The GPU writes the experts it needs into a pinned export, rings ready, and waits for done. On the host, the coordinator sees the ring, reads the missing experts from NVMe into a pinned pool, moves them into device slots, and sets done. Three metrics gate the checkpoint:
| Metric | What it measures | Threshold |
|---|---|---|
| R1 | expert read rate under a miss-only workload, as a fraction of what the SSD can do (S1) | ≥ 0.90 |
| R2 | pool-to-GPU transfer rate, as a fraction of pinned PCIe bandwidth (S2) | ≥ 0.85 |
| R3 | round trip of a demand whose experts are all resident, p99 | ≤ 100 µs |
On the Windows box the first checkpoint, best of its tuning runs, measured R1 0.79, R2 0.38 and R3 p99 5 253 µs. The DGX Spark missed only R3, at 118 µs.
Trap 1: a 50 µs park that sleeps 15 ms
The coordinator spun on the doorbells while a ring was expected, then backed off with std::thread::park_timeout(50 µs). On Linux that sleeps about 50 µs. On Windows it sleeps about 15.5 ms: the default timer resolution. A zero-miss demand that arrived while the coordinator was parked waited a whole scheduler tick, which is exactly what R3's p50 of 4.6 ms looked like.
The fix was not a shorter sleep. The thread that submits GPU work that will ring a doorbell now wakes the coordinator, which spins for 2 ms after a wake or a serve and only then parks with a 1 ms safety-net timeout. Nothing in the protocol relies on a timed sleep any more. This one is well known: Windows' wait functions are only as accurate as the system clock tick, and a Rust audio project hit the same park_timeout rounding and fixed it the same way.
| R3 p50 | R3 p99 | R2 | |
|---|---|---|---|
| RTX 3080 Ti, before | 4 613–4 640 µs | 5 261–5 296 µs | 0.28 |
| RTX 3080 Ti, after | 92–93 µs | 384–390 µs | 0.97 |
| DGX Spark, before | 67–68 µs | 117–118 µs | — |
| DGX Spark, after | 14.1–14.7 µs | 18.4–18.5 µs | — |
R2 went from 0.28 to 0.97 without touching the transfer code: the "slow transfer" had been the round trip behind a parked thread all along. The DGX Spark's whole checkpoint miss disappeared in the same change.
A smaller one: copies inside the compute stream
The staged demand used to copy the kernel's export (the missing experts and their count) device→host with two cuMemcpyAsync before ringing. Copy-engine work inside a compute stream is a cross-engine fence on WDDM, so the kernel now writes its outputs straight into pinned memory through device aliases and no copy runs on the ring path. It mattered less on Windows than I expected, and more on the DGX Spark:
| Staged, R3 | p50 before → after | p99 before → after |
|---|---|---|
| RTX 3080 Ti | 93.2 → 87.0–87.1 µs | 385–390 → 342–387 µs |
| DGX Spark | 28.7 → 16.4–16.6 µs | 28.9–29.0 → 17.4–22.1 µs |
The rest of the Windows round trip was somewhere else. Trap 4 found it.
Trap 2: one copy engine, one deadlock
R1 could not pass on a discrete GPU with the original design: all reads of a serve landed in pinned memory first, then a gather kernel copied them over PCIe after done. Reads and transfers never overlapped. So the coordinator became the mover: it starts copying each expert into its device slot the moment that expert's read lands.
The first version used cuMemcpyAsync on the coordinator's own stream, the obvious choice, at 26.6 GB/s. On the DGX Spark it was great: R1 0.88 → 0.98. On Windows the benchmark hung, every time.
What happened: the RTX 3080 Ti under WDDM exposes one copy engine. The compute stream had enqueued cuStreamWaitValue64(done), followed by a device-to-host copy (the benchmark's exactness check; a real decode step would have its own copies). That copy sat at the head of the single copy engine's queue, waiting for done. The coordinator's host-to-device copies queued behind it, so they never ran, so done was never written. A deadlock that only exists when copy engines are scarce. A throwaway reproduction confirmed it: with a copy after the wait, every DMA round stalled; with the move done by a kernel on the SMs instead, every variant drained.
So the mover gathers on the SMs: one small expert_slot_copy launch per expert, reading the pinned pool through its device alias. It costs a little against the DMA engine, and it can't deadlock. NVIDIA's own advice for single-copy-engine GPUs is the same ("write simple copy kernels"); what I couldn't find written down is the deadlock you get when the copy that would release a wait sits behind it in the one engine's queue.
A side discovery while debugging the hang: the benchmark's main held io::stderr().lock() for the whole run. When the coordinator thread hit a fatal error, its handler's eprintln! blocked forever on that lock, so the program hung silently instead of printing why. WinDbg stacks of the hung process showed the coordinator waiting on the stderr lock that main held.
| Staged backend, mover on the SMs | R1 | R2 | R3 p50 | R3 p99 |
|---|---|---|---|---|
| DGX Spark, before → after | 0.886–0.888 → 0.982–0.986 | 0.894–0.901 → 0.890–0.891 | 16.5–18.4 → 12.4–12.5 µs | 18.6–18.7 → 13.0–13.1 µs |
| RTX 3080 Ti, before → after | 0.415–0.417 → 0.474–0.478 | 0.976 → 0.947–0.949 | 87–94 → 80–85 µs | 352–384 → 383–387 µs |
R2 dips on Windows because pool hits are now moved by the SMs reading pinned memory over PCIe, while R2 still divides by a DMA bandwidth; it stays well above 0.85.
On Windows R1 barely moved, because something else was capping the read rate.
Trap 3: a file you wrote is slow to read, in any process
On Windows, the expert reads ran at 2.3–2.6 GB/s inside the benchmark, while the same SSD delivered 6.4 GB/s to a standalone reader. The reads are unbuffered (FILE_FLAG_NO_BUFFERING), so the page cache shouldn't matter. It did.
The benchmark writes its bundle first, through the normal cached file API. Windows then keeps a cached copy of that file after every handle has closed, and any unbuffered reader opened on it while that copy exists reads at ~2.5 GB/s for as long as the handle stays open:
| How the file was written | Unbuffered reader, GB/s |
|---|---|
| Unbuffered | 6.1–6.5 from the first read |
| Cached, no flush | 0.9 at first, then 2.5–2.8 |
Cached + sync_all (FlushFileBuffers) | 2.47–2.52 |
| Cached, reader opened 30 s later | 2.50–2.55 |
| Cached, read by a different process | 2.49–2.56 |
Flushing doesn't help, waiting doesn't help, and a separate process is affected the same way. So in production, ferrite convert followed by ferrite serve would pay it too.
After the fact I went looking, and the mechanism is known to filesystem-driver developers: it's cache coherency. When a file has a data section (the cache manager's mapping of it), the filesystem makes every noncached transfer coherent with the cache first. The FASTFAT sample source does a CcFlushCache over the range, under the file's lock taken exclusive, whenever DataSectionObject != NULL (OSR, 2010). The kernel exports CcCoherencyFlushAndPurgeCache for exactly this "read coherency flush". The data section belongs to the file, not to a handle or a process, so it outlives the writer's handle, and sync_all writes the dirty pages back without tearing it down. NTFS's source isn't public, but a per-read check under an exclusive lock would explain 32 parallel readers collapsing to 2.5 GB/s. What I found nowhere is the size of the effect on a modern NVMe drive, or how long it lasts.
The fix is on the writing side: the bundle writer stages each object in a 4 KiB-aligned 1 MiB buffer and writes data files unbuffered on Windows, so no data section is ever created. Linux keeps buffered writes; it shows no such gap.
| Read rate (R1 ratio) | cached writer | unbuffered writer |
|---|---|---|
| RTX 3080 Ti, staged | 2.27–2.29 GB/s (0.426–0.428) | 5.09 GB/s (0.795–0.817) |
| DGX Spark, coherent | 7.11 GB/s (1.002–1.004) | 7.08–7.10 GB/s (1.002–1.010) |
The DGX Spark row is the no-regression check: Linux keeps its buffered writes, now in 1 MiB blocks, and reads the same.
One honest negative from this hunt: I also tried BypassIO (FSCTL_MANAGE_BYPASS_IO), which Windows 11 grants on NVMe and which skips the filter stack for unbuffered reads. Once the writer was fixed, it read no faster (5.07–5.08 vs 5.08–5.11 GB/s). It was dropped. In hindsight its documentation describes the same rule from the other side: a cached or mapped handle on the file sends BypassIO back to the traditional path "until all data sections and cache maps are torn down".
With the mover and the writer together, the Windows box reached R1 0.97 and R2 0.95. One metric was left.
Traps 4 and 5: stream memops cost tens of microseconds, and CPU 0 is busy
R3 p99 was still ~380 µs against 100. Timestamps in the coordinator, a GPU event after the demand, and an Nsight Systems trace split one zero-miss round trip:
| Segment | p50 before | p99 before | p50 after | p99 after |
|---|---|---|---|---|
| demand → ensure kernel ends | ~10 µs | ~11 µs | 10.2 µs | 11.3 µs |
kernel ends → host sees ready (cuStreamWriteValue64) | 49 µs | 224 µs | ~0 (the kernel writes it) | ~0 |
coordinator stalled before seeing ready (on CPU 0) | 0.1 µs | 117 µs | gone (off CPU 0) | gone |
| coordinator serves | 1.0 µs | 2.1 µs | 0.7 µs | 1.3 µs |
host writes done → wait passes (cuStreamWaitValue64) | 31 µs | 102 µs | ~5 µs (polling kernel, estimated) | — |
Under WDDM, a stream memory operation costs tens of microseconds even when it has nothing to wait for: the wait took 22–27 µs when done was already set before the GPU reached it. On the DGX Spark the whole round trip, memops included, takes 12–13 µs. Another project measured the same order on an RTX 5090 under WDDM: a memop ring round trip of 28 µs at p50 and 340 µs at p99.
The fix keeps memops off the round trip. The kernel that computes the export now rings the doorbell itself: every thread __threadfence_system()s, then one thread writes done = 0, fences, and writes ready = 1. The wait is a one-thread kernel that polls done. Does a spinning kernel on a display GPU trip the 2-second timeout detection? We held one for 3 s on purpose: the GPU preempted it and the stream completed cleanly.
One open question I want to be upfront about. A vLLM fork tried the same kind of spinning wait across a ~1 ms NVMe read and saw WDDM delay the next CUDA graph launch by up to 8 ms, so they went back to the memop. My measurements here run demands one at a time, not replayed graphs. Before decode runs as graphs I'll measure graph launches after long miss serves, and if they stall, the spin becomes bounded, with the memop as fallback.
The trace showed one more thing. When the coordinator happened to spin on logical processor 0, it stalled 25–50 µs right as the ring arrived. CPU 0 was taking ~1 750 deferred procedure calls per second during a run, against 50–145 on other cores. In two short probe runs with the coordinator forced onto CPU 0, p99 went to 213 µs and 3 587 µs; keeping it off CPU 0 is now part of the coordinator's startup on Windows. Gamers and audio engineers know this one well: LatencyMon shows the NVIDIA driver's DPCs landing on CPU 0, and the standard advice is to move the interrupt or your thread off it.
Interleaved runs, one change at a time, 10 000 demands:
| RTX 3080 Ti, staged | R3 p50 | R3 p99 |
|---|---|---|
| memops | 93–99 µs | 214–269 µs |
| kernel rings and waits | 20.5–21.7 µs | 54–94 µs |
| and the coordinator off CPU 0 | 14.3–20.5 µs | 22.5–27.6 µs |
On the DGX Spark, where memops were never slow, the kernel version costs about 1.2 µs at p99 (13.1 → 14.3 µs). I kept one mechanism for both systems rather than a per-OS doorbell to save that.
Where it ended: Checkpoint A passed
After the last fix the pipeline ran Checkpoint A again from scratch, on the same code on both machines, 10 000 demands per run, both on-disk layouts. Every gated metric passed, the RTX 3080 Ti with default settings and no tuning runs.
| RTX 3080 Ti, staged, Windows | First attempt (best tuned) | Checkpoint A, planar | Checkpoint A, record |
|---|---|---|---|
| C1, wrong bytes (= 0) | 0 | 0 | 0 |
| R1 (≥ 0.90) | 0.79 | 0.992 (6.24 GB/s) | 0.988 (6.22 GB/s) |
| R2 (≥ 0.85) | 0.38 | 0.962 | 0.956 |
| R3 p50 | — | 13.3 µs | 14.3 µs |
| R3 p99 (≤ 100 µs) | 5 253 µs | 14.3 µs | 22.5 µs |
| DGX Spark, coherent, Linux | First attempt (best tuned) | Checkpoint A, planar | Checkpoint A, record |
|---|---|---|---|
| C1 (= 0) | 0 | 0 | 0 |
| R1 (≥ 0.90) | 1.000 | 0.991 (7.08 GB/s) | 0.965 (6.83 GB/s) |
| R3 p50 | — | 16.0 µs | 14.3 µs |
| R3 p99 (≤ 100 µs) | 118 µs | 20.2 µs | 19.0 µs |
R3 p99 on the Windows box went from 5.25 ms to 14.3 µs, a factor of about 370. It is now on par with the unified-memory machine it was failing next to (planar 14.3 vs 20.2 µs, record 22.5 vs 19.0 µs), and both are far inside the 100 µs budget.
What I'd tell someone doing CUDA on Windows
- Don't trust a short sleep. Assume
park_timeout,sleepor a condvar timeout below the timer resolution sleeps a whole tick, and design so that nothing waits on one. - Count your copy engines. If a stream can wait on the host while another stream needs the copy engine to unblock it, you have a deadlock waiting for a GPU with one engine. Move data with kernels on the side that must never block.
- Write your weight files unbuffered. If anything reads them unbuffered later, a cached write makes those reads slow, even across processes.
- Treat stream memops as expensive under WDDM. On a latency path, let the kernel write the flag and let a kernel do the waiting.
- Keep latency-critical spinning threads off CPU 0.
Prior art
Searching afterwards, here is what I found for each trap:
| Trap | Status | Sources |
|---|---|---|
park_timeout sleeps a clock tick | well known | Microsoft: wait functions and time-out intervals; transit-audio #62 |
| one copy engine, one deadlock | parts documented, the combination not found | NVIDIA forum: single async engine, use copy kernels; CUDA stream memory operations ("improper use … may deadlock") |
| cached write, slow unbuffered reads | documented for filesystem developers; magnitude and duration not found | OSR: FASTFAT's coherency flush; CcCoherencyFlushAndPurgeCache; BypassIO for filter drivers |
| WDDM memops cost tens of µs | measured by others, not in NVIDIA's docs | crow-nest #149 (RTX 5090, WDDM) |
| CPU 0 takes the GPU's DPCs | well known in gaming and audio | ntlite: nvlddmkm.sys DPC latency; Blue Cat Audio |
| a spinning kernel can delay graph launches (open question above) | reported | HyunCello/vllm #5 |
So the individual pieces mostly aren't new. What I hope is useful is having them in one place for CUDA on Windows, with numbers from one machine and the fix for each.
How this got done
I wrote no fix in this post myself. A set of coding agents did the work, with me steering: one per unit of work implemented, a separate one reviewed every diff against the repository's rules until nothing was left, and the orchestrating agent ran the benchmarks and committed. The project's rule is that every performance choice is backed by a result file comparing the alternatives one change apart, so every before/after number above comes from interleaved runs (before, after, before, after) on the real hardware, committed next to the decision it justifies; the diagnostic tables come from probes and traces made to find the cause. Ruling things out took as long as finding them: timer resolution, the spin window, thread preemption and the measurement itself were each checked against a trace before the real causes showed up, and I skipped a HAGS experiment once it was clear HAGS was already in the low-latency setting.
That discipline is the reason the post exists at all. Without measurements I'd have guessed at "Windows is slow" and stopped.