[GH-ISSUE #3681] [Engine] SYCL --stream-experts: mirror PCIe bandwidth depends on host memory fragmentation at engine start (Arc Pro B70: 27 vs 42 tok/s, same boot, same link) #1524

Closed
opened 2026-11-04 01:51:57 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @phg1024 on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3681

Area

[Engine]

Desktop app, Terminal or source?

Source (a build)

What happened

On a single Arc Pro B70, the --stream-experts mirror's PCIe bandwidth depends on how fragmented host RAM is when the engine starts. Decode speed follows it. With the same binary, config, link and boot, decode ranges from 27 to 43 tok/s, depending only on host memory state at startup.

The mirror is about 27 GiB, and about 55% of experts on this pack are read from it over PCIe. It is pinned once at start (GgufExpertSource::mirror, sycl::malloc_host in 2 GiB chunks), so whatever pages the driver hands out then stay for the life of the process. The effects:

  • A service restart helps or hurts at random, and a host reboot "fixes" it.
  • Every A/B comparison between separate server starts is noisy. I saw 26.9 → 32.6 tok/s for the same config within one evening.
  • Gen4-vs-Gen5 comparisons are easy to misread. A run three minutes after boot looked like a "+40% from Gen5", but most of that gain was fresh memory.

Measurements. Same boot, same PCIe 4.0 x16 link with 0 AER errors throughout, same binary and config. Host memory before the "compacted" rows was reset with sync; echo 3 > /proc/sys/vm/drop_caches; echo 1 > /proc/sys/vm/compact_memory, then the engine was restarted.

host memory state at engine start pinned H→D (512 MiB memcpy, best of 10) GPU kernel zero-copy read of malloc_host memory decode 2K / 32K (tok/s)
right after boot 27.5 GB/s 24.0 GB/s 36.3 / 37.0
45 min of uptime, page cache full (MemFree ≈ 0, 5,341 compact_stalls since boot), 4 engine starts 11.0 and 17.6 GB/s (two runs, 1 min apart) 9.6 and 15.0 GB/s 30.1 / 30.7, then 26.9 / 27.6
same boot after drop_caches + compact_memory, engine restarted 27.5 GB/s 23.9 GB/s 42.4 / 42.7
  • Draft acceptance is the same across all rows: 295–296 of 457–459 at 2K, 291–293 of 432–433 at 32K.
  • The text output of runs across separate engine starts is byte-identical at temperature 0.
  • GPU clock is ~2.6 GHz with throttle/reasons = none.
  • GPU power falls from ~165–195 W to ~135 W in the slow state, so the GPU is waiting on the mirror.
  • On the same box at PCIe 5.0, an instance started three minutes after boot ran at 42–45 tok/s (2026-10-19). An instance started after two days of uptime ran at 25–27 tok/s (2026-10-21).

Suspected mechanism (not yet verified).

  • The IOMMU is in translated mode: all 22 groups are DMA-FQ, the Ubuntu default, with no iommu= on the command line.
  • On a fragmented host, the xe/TTM system-memory pages behind malloc_host are mostly order-0. The GPU's reads of the mirror then hit IOMMU translation (IOTLB misses) on scattered 4 KiB pages. With mostly high-order pages, the same reads run at full link speed.
  • #3201 (comment on the IOMMU check) already showed DMA-FQ costing pinned copy bandwidth on a Gen3 box (7.7–9.2 against 12.3 GB/s with iommu=pt). That covers the translation part. The dependence on fragmentation at start is the new part.
  • What would confirm or refute the mechanism: the same fragmented-vs-compacted A/B with iommu=pt. I have not run it yet and will add it here.

Why this is a Strata issue and not only host tuning.

  • The mirror() allocation is the one large pinned allocation whose page backing Strata does not control.
  • The CPU arena already tries MAP_HUGETLB, then MADV_HUGEPAGE (core/pinned.dp.cpp), but the mirror goes straight to sycl::malloc_host.
  • At minimum, the start log could report how the mirror is backed or warn when the host is fragmented, so users stop chasing PCIe settings.

Workaround that works today: run drop_caches + compact_memory as root right before the engine starts, for example in ExecStartPre. That gave 42.4 / 42.7 tok/s.

Smallest steps or command that reproduce it

  1. Boot, start the engine with --stream-experts on a pack where a large share of experts is mirrored, and run the same short benchmark (2K and 32K prompts, 512 tokens, temperature 0). Note the decode speed.
  2. Let the host fill its page cache: read the GGUFs or other large files, or run a few benchmark rounds, until MemFree is near 0 and /proc/buddyinfo shows few high-order blocks. Restart the engine and benchmark again. Decode drops.
  3. As root, run sync; echo 3 > /proc/sys/vm/drop_caches; echo 1 > /proc/sys/vm/compact_memory. Restart the engine and benchmark again. Decode recovers.

The microbenchmark below shows the same split without the engine: the zero-copy row is the access pattern the decode path uses on the mirror.

bw.cpp (SYCL, icpx -fsycl -O2 bw.cpp -o bw)
#include <sycl/sycl.hpp>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
int main(){
  sycl::queue q{sycl::gpu_selector_v};
  const size_t N = 512ull<<20; const int R = 10;
  char* d = sycl::malloc_device<char>(N, q);
  char* h = sycl::malloc_host<char>(N, q);
  memset(h, 1, N);
  auto bw=[&](const char* name, void* dst, const void* src){
    q.memcpy(dst, src, N).wait(); double best=0;
    for(int r=0;r<R;r++){ auto t0=std::chrono::steady_clock::now(); q.memcpy(dst,src,N).wait();
      double s=std::chrono::duration<double>(std::chrono::steady_clock::now()-t0).count(); best=std::max(best,N/s/1e9);}
    printf("%-24s best %.1f GB/s\n", name, best); };
  bw("pinned host->device", d, h);
  bw("pinned device->host", h, d);
  const unsigned* hs=(const unsigned*)h; unsigned* out=sycl::malloc_device<unsigned>(1,q); size_t n4=N/4;
  for(int r=0;r<3;r++){ auto t0=std::chrono::steady_clock::now();
    q.parallel_for(sycl::range<1>(n4/16), [=](sycl::id<1> i){ unsigned s=0; for(int k=0;k<16;k++) s+=hs[i*16+k]; if(s==12345) out[0]=s; }).wait();
    double s=std::chrono::duration<double>(std::chrono::steady_clock::now()-t0).count(); printf("kernel zero-copy read    %.1f GB/s\n", N/s/1e9);}
}

Reproduction status

Reproduced locally

Strata version

Engine 0.1.45.3 (commit e88ee39). The mirror code is unchanged on main @ 011c9e6 (v0.2.2).

Graphics card, memory and system

Intel Arc Pro B70 32 GB (BMG-G31) in the CPU x16 slot, ReBAR on. i7-12700K, 64 GB DDR4 (61 GiB visible), ASUS Z690. Ubuntu 26.04, kernel 7.0.0-38, xe, GuC 70.58, compute-runtime 26.31.39395.16, IGC 2.40.16, Level Zero loader 1.32.0, oneAPI 2026.1. IOMMU DMA-FQ, THP madvise.

Model, size and settings

Qwen3.8-Flash-Next IQ3_S native pack, text only. --stream-experts --expert-cache auto --vram-reserve-mib 2048 --kv int8 --kv-resident 32768 --max-context 262144 --spec 4 --spec-min-p 0.5 --mtp ... --prefill 8192, STRATA_VERIFY_DEVICE_PLAN=1 STRATA_VERIFY_NO_HOST=1. In the runs above, 13,446 of 25,746 experts were mirrored (25.71 GiB).

Logs

Both starts are in the same boot, with the same config and binary. The mirror has the same size both times; only the host memory state differs.

# slow start (fragmented host, 20:16)
strata generate: 13446 of 12246 experts missing from VRAM (+ 1200 in the prompt loan's slots) mirrored in pinned host memory (25.71 GiB, 13.3 s); the GPU reads them over PCIe
strata serve: prompt 1981 tokens = 0 reused + 1981 read in 2404 ms (823.9 tok/s), 512 generated in 19018 ms (26.9 tok/s), drafts accepted 295 of 457, 1 checkpoints
strata serve: prompt 32701 tokens = 0 reused + 32701 read in 24756 ms (1320.9 tok/s), 512 generated in 18527 ms (27.6 tok/s), drafts accepted 291 of 433, 4 checkpoints

# fast start (after drop_caches + compact_memory, 20:47)
strata generate: 13446 of 12246 experts missing from VRAM (+ 1200 in the prompt loan's slots) mirrored in pinned host memory (25.71 GiB, 13.0 s); the GPU reads them over PCIe
strata serve: prompt 1981 tokens = 0 reused + 1981 read in 2084 ms (950.5 tok/s), 512 generated in 12080 ms (42.4 tok/s), drafts accepted 296 of 459, 1 checkpoints
strata serve: prompt 32701 tokens = 0 reused + 32701 read in 23736 ms (1377.7 tok/s), 512 generated in 11982 ms (42.7 tok/s), drafts accepted 293 of 432, 4 checkpoints

# /proc/buddyinfo Normal zone, order 0..10
fragmented (20:20): 2 1 1 2 0 1 493 148 9 1 0
compacted  (20:45): 11365 11364 8910 5426 2898 1520 859 422 225 2826 5191

Happy to test a patch on this box: hugepage-backed mirror chunks, an opt-in pre-compaction step, or a start-log line reporting the mirror's backing.

Originally created by @phg1024 on GitHub (Oct 22, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3681 ### Area [Engine] ### Desktop app, Terminal or source? Source (a build) ### What happened On a single Arc Pro B70, the `--stream-experts` mirror's PCIe bandwidth depends on **how fragmented host RAM is when the engine starts**. Decode speed follows it. With the same binary, config, link and boot, decode ranges from **27 to 43 tok/s**, depending only on host memory state at startup. The mirror is about 27 GiB, and about 55% of experts on this pack are read from it over PCIe. It is pinned once at start (`GgufExpertSource::mirror`, `sycl::malloc_host` in 2 GiB chunks), so whatever pages the driver hands out then stay for the life of the process. The effects: - **A service restart helps or hurts at random, and a host reboot "fixes" it.** - Every A/B comparison between separate server starts is noisy. I saw 26.9 → 32.6 tok/s for the same config within one evening. - Gen4-vs-Gen5 comparisons are easy to misread. A run three minutes after boot looked like a "+40% from Gen5", but most of that gain was fresh memory. **Measurements.** Same boot, same PCIe 4.0 x16 link with 0 AER errors throughout, same binary and config. Host memory before the "compacted" rows was reset with `sync; echo 3 > /proc/sys/vm/drop_caches; echo 1 > /proc/sys/vm/compact_memory`, then the engine was restarted. | host memory state at engine start | pinned H→D (512 MiB `memcpy`, best of 10) | GPU kernel zero-copy read of `malloc_host` memory | decode 2K / 32K (tok/s) | |---|---|---|---| | right after boot | 27.5 GB/s | 24.0 GB/s | 36.3 / 37.0 | | 45 min of uptime, page cache full (`MemFree` ≈ 0, 5,341 `compact_stall`s since boot), 4 engine starts | 11.0 and 17.6 GB/s (two runs, 1 min apart) | 9.6 and 15.0 GB/s | 30.1 / 30.7, then **26.9 / 27.6** | | same boot after `drop_caches` + `compact_memory`, engine restarted | **27.5 GB/s** | **23.9 GB/s** | **42.4 / 42.7** | - Draft acceptance is the same across all rows: 295–296 of 457–459 at 2K, 291–293 of 432–433 at 32K. - The text output of runs across separate engine starts is byte-identical at temperature 0. - GPU clock is ~2.6 GHz with `throttle/reasons = none`. - GPU power falls from ~165–195 W to ~135 W in the slow state, so the GPU is waiting on the mirror. - On the same box at PCIe 5.0, an instance started three minutes after boot ran at 42–45 tok/s (2026-10-19). An instance started after two days of uptime ran at 25–27 tok/s (2026-10-21). **Suspected mechanism (not yet verified).** - The IOMMU is in translated mode: all 22 groups are `DMA-FQ`, the Ubuntu default, with no `iommu=` on the command line. - On a fragmented host, the xe/TTM system-memory pages behind `malloc_host` are mostly order-0. The GPU's reads of the mirror then hit IOMMU translation (IOTLB misses) on scattered 4 KiB pages. With mostly high-order pages, the same reads run at full link speed. - #3201 (comment on the IOMMU check) already showed `DMA-FQ` costing pinned copy bandwidth on a Gen3 box (7.7–9.2 against 12.3 GB/s with `iommu=pt`). That covers the translation part. The dependence on fragmentation at start is the new part. - What would confirm or refute the mechanism: the same fragmented-vs-compacted A/B with `iommu=pt`. I have not run it yet and will add it here. **Why this is a Strata issue and not only host tuning.** - The `mirror()` allocation is the one large pinned allocation whose page backing Strata does not control. - The CPU arena already tries `MAP_HUGETLB`, then `MADV_HUGEPAGE` (`core/pinned.dp.cpp`), but the mirror goes straight to `sycl::malloc_host`. - At minimum, the start log could report how the mirror is backed or warn when the host is fragmented, so users stop chasing PCIe settings. **Workaround that works today:** run `drop_caches` + `compact_memory` as root right before the engine starts, for example in `ExecStartPre`. That gave 42.4 / 42.7 tok/s. ### Smallest steps or command that reproduce it 1. Boot, start the engine with `--stream-experts` on a pack where a large share of experts is mirrored, and run the same short benchmark (2K and 32K prompts, 512 tokens, temperature 0). Note the decode speed. 2. Let the host fill its page cache: read the GGUFs or other large files, or run a few benchmark rounds, until `MemFree` is near 0 and `/proc/buddyinfo` shows few high-order blocks. Restart the engine and benchmark again. Decode drops. 3. As root, run `sync; echo 3 > /proc/sys/vm/drop_caches; echo 1 > /proc/sys/vm/compact_memory`. Restart the engine and benchmark again. Decode recovers. The microbenchmark below shows the same split without the engine: the zero-copy row is the access pattern the decode path uses on the mirror. <details><summary>bw.cpp (SYCL, <code>icpx -fsycl -O2 bw.cpp -o bw</code>)</summary> ```cpp #include <sycl/sycl.hpp> #include <chrono> #include <cstdio> #include <cstdlib> #include <cstring> int main(){ sycl::queue q{sycl::gpu_selector_v}; const size_t N = 512ull<<20; const int R = 10; char* d = sycl::malloc_device<char>(N, q); char* h = sycl::malloc_host<char>(N, q); memset(h, 1, N); auto bw=[&](const char* name, void* dst, const void* src){ q.memcpy(dst, src, N).wait(); double best=0; for(int r=0;r<R;r++){ auto t0=std::chrono::steady_clock::now(); q.memcpy(dst,src,N).wait(); double s=std::chrono::duration<double>(std::chrono::steady_clock::now()-t0).count(); best=std::max(best,N/s/1e9);} printf("%-24s best %.1f GB/s\n", name, best); }; bw("pinned host->device", d, h); bw("pinned device->host", h, d); const unsigned* hs=(const unsigned*)h; unsigned* out=sycl::malloc_device<unsigned>(1,q); size_t n4=N/4; for(int r=0;r<3;r++){ auto t0=std::chrono::steady_clock::now(); q.parallel_for(sycl::range<1>(n4/16), [=](sycl::id<1> i){ unsigned s=0; for(int k=0;k<16;k++) s+=hs[i*16+k]; if(s==12345) out[0]=s; }).wait(); double s=std::chrono::duration<double>(std::chrono::steady_clock::now()-t0).count(); printf("kernel zero-copy read %.1f GB/s\n", N/s/1e9);} } ``` </details> ### Reproduction status Reproduced locally ### Strata version Engine 0.1.45.3 (commit `e88ee39`). The mirror code is unchanged on `main` @ `011c9e6` (v0.2.2). ### Graphics card, memory and system Intel Arc Pro B70 32 GB (BMG-G31) in the CPU x16 slot, ReBAR on. i7-12700K, 64 GB DDR4 (61 GiB visible), ASUS Z690. Ubuntu 26.04, kernel 7.0.0-38, `xe`, GuC 70.58, compute-runtime 26.31.39395.16, IGC 2.40.16, Level Zero loader 1.32.0, oneAPI 2026.1. IOMMU `DMA-FQ`, THP `madvise`. ### Model, size and settings Qwen3.8-Flash-Next IQ3_S native pack, text only. `--stream-experts --expert-cache auto --vram-reserve-mib 2048 --kv int8 --kv-resident 32768 --max-context 262144 --spec 4 --spec-min-p 0.5 --mtp ... --prefill 8192`, `STRATA_VERIFY_DEVICE_PLAN=1 STRATA_VERIFY_NO_HOST=1`. In the runs above, 13,446 of 25,746 experts were mirrored (25.71 GiB). ### Logs Both starts are in the same boot, with the same config and binary. The mirror has the same size both times; only the host memory state differs. ``` # slow start (fragmented host, 20:16) strata generate: 13446 of 12246 experts missing from VRAM (+ 1200 in the prompt loan's slots) mirrored in pinned host memory (25.71 GiB, 13.3 s); the GPU reads them over PCIe strata serve: prompt 1981 tokens = 0 reused + 1981 read in 2404 ms (823.9 tok/s), 512 generated in 19018 ms (26.9 tok/s), drafts accepted 295 of 457, 1 checkpoints strata serve: prompt 32701 tokens = 0 reused + 32701 read in 24756 ms (1320.9 tok/s), 512 generated in 18527 ms (27.6 tok/s), drafts accepted 291 of 433, 4 checkpoints # fast start (after drop_caches + compact_memory, 20:47) strata generate: 13446 of 12246 experts missing from VRAM (+ 1200 in the prompt loan's slots) mirrored in pinned host memory (25.71 GiB, 13.0 s); the GPU reads them over PCIe strata serve: prompt 1981 tokens = 0 reused + 1981 read in 2084 ms (950.5 tok/s), 512 generated in 12080 ms (42.4 tok/s), drafts accepted 296 of 459, 1 checkpoints strata serve: prompt 32701 tokens = 0 reused + 32701 read in 23736 ms (1377.7 tok/s), 512 generated in 11982 ms (42.7 tok/s), drafts accepted 293 of 432, 4 checkpoints # /proc/buddyinfo Normal zone, order 0..10 fragmented (20:20): 2 1 1 2 0 1 493 148 9 1 0 compacted (20:45): 11365 11364 8910 5426 2898 1520 859 422 225 2826 5191 ``` Happy to test a patch on this box: hugepage-backed mirror chunks, an opt-in pre-compaction step, or a start-log line reporting the mirror's backing.
Author
Owner

@phg1024 commented on GitHub (Oct 22, 2026):

Follow-up: refined cause, a root-free reproduction, and an opt-in fix measured in the engine

Short version. "Fragmentation" in the original report was too broad. What matters is whether the mirror's pinned chunks are allocated from free memory or under reclaim.

  • Chunks the xe driver hands out while the kernel reclaims page cache are read by the GPU at roughly 55–85% of the bandwidth of chunks taken from free memory. CPU reads of the same chunks run at full speed.
  • The engine's own start-up reads (weights, the VRAM expert fill) fill the page cache before GgufExpertSource::mirror() runs. So on a 64 GB host, MemFree at that point is often below 1 GiB, against 25.7 GiB needed for the mirror.
  • Dropping the GGUF files' page cache just before the chunks are allocated made decode stable across 24 engine starts and a 5-hour soak with random restarts. That is an opt-in posix_fadvise, with the patch below.

Unless noted otherwise, everything below was measured on the same box as in the report, now at PCIe 4.0 x16 with 0 AER errors throughout. Engine: main @ 011c9e6 (v0.2.2) plus the patch.

1. Where the pages come from (Level Zero is not the variable)

With NEOReadDebugKeys=1 PrintBOCreateDestroyResult=1 LogAllocationMemoryPool=1 PrintBOChunkingLogs=1, a 2 GiB sycl::malloc_host is a single system-memory BO:

Chunking available: 0; enabled for: shared allocations 0, device allocations 0; minimalChunkingSize: 2097152
Performing DRM_IOCTL_XE_GEM_CREATE with {vmid=0x0 size=0x80000000 flags=0x1 placement=0x1 caching=1 } ... BO-65 with size: 2147483648
Type: BUFFER_HOST_MEMORY Pool: System4KBPages ... Size: 2147483648

The UMD passes no page-size hint, so the physical backing is decided by xe/TTM in the kernel.

2. GPU vs CPU reads of the same chunks

This is a standalone SYCL microbenchmark: 13 × 2 GiB malloc_host chunks, the mirror's shape. For each chunk it measures a GPU copy-engine H2D, a GPU kernel zero-copy read, and a CPU read with 8 threads. Values are GB/s, listed per chunk in allocation order.

host state when allocating MemFree GPU copy H2D GPU kernel read CPU read
page cache dropped 60 GB 27 ×13 24 ×13 30–31 ×13
after one engine start/stop and a 22 GB file read 11 GB 27 27 27 23 16 16 16 19 20 18 21 20 22 24 24 24 20 14 14 14 17 18 16 18 17 19 30–31 ×13
page cache dropped again (no root: posix_fadvise on the model files) 61 GB 27 ×13 24 ×13 30–31 ×13

In the slow state, the first ~6 GiB came from free memory at full speed. Every chunk that needed reclaim is slow for the GPU only, never for the CPU. I have not yet separated whether the cost is IOMMU translation or the GPU's own PTE granularity on small pages. iommu=pt is the next test, and it needs a reboot.

3. Reproduction without root

  1. Drop the page cache of the model files with posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) on each GGUF. Then start the engine and benchmark it: fast.
  2. Stop the engine, read any ~22 GB file (cat other.gguf > /dev/null), start it again and benchmark: slow.

It reproduced on every pair below.

4. In the engine: STRATA_MIRROR_DROP_CACHE A/B over 24 starts

  • Protocol: 3 arms run as 2 blocks each, in the order off, before, both, both, before, off. Here off is a build mode that only reports MemFree and drops nothing.
  • Each block: drop the model files' page cache, then make 4 consecutive engine starts with a 22 GB unrelated file read between starts.
  • Each start: a 2K and a 32K needle prompt, 512 tokens, temperature 0.
  • Correctness: 48/48 needles found.

Decode is in tok/s as 2K / 32K, with one value per block. MemFree is read in the engine right before the chunks are allocated.

start off before both
1 40.4/40.8, 44.1/44.4 44.1/44.4, 44.2/44.5 44.1/44.5, 44.1/44.5
2 37.4/38.3, 36.8/37.5 44.2/44.5, 44.1/44.4 43.1/43.6, 43.3/43.7
3 38.4/39.1, 38.4/39.2 44.2/44.5, 44.1/44.5 42.1/42.4, 42.2/42.6
4 36.4/37.2, 36.9/37.6 44.2/44.5, 44.2/44.5 41.2/41.6, 41.4/41.8
MemFree at allocation start 1: 22.5–23.5 GiB; starts 2–4: 0.7–1.0 GiB after the drop: 51.4 GiB at start 1, 30.4 GiB at starts 2–4 same as before
  • Cost of before: the mirror fill reads from NVMe instead of the cache, 13.0 s → 14.4 s per start.
  • Negative result: dropping the mirrored ranges after filling the mirror (after, my first attempt) made restarts 2–4 slower than off: 27.6–30.3 against 35.5–38.9 tok/s, again as two ABBA blocks. both drifts down over restarts. I do not have a clean explanation for either, so the patch below does only before.

5. Five-hour soak with before on the live service

  • Load: Poisson arrivals with a 120 s mean; prompts of 1K–128K plus 57 follow-up turns, 170 requests in all.
  • Restarts: 6 random restarts, 5 of them right after reading a 16–22 GB unrelated file.
  • Correctness: 0 errors and 0 wrong answers. AER 0, xe engine resets 0.
  • Memory at each restart: MemFree before the drop was 1.2–5.9 GiB, and 29.1–41.4 GiB after it.
  • Speed: a fixed 2K probe, run after every restart and every 30 min, stayed at 58.0–59.5 tok/s in all 13 runs.
  • Caveat: the soak had no control arm. The controlled comparison is section 4.

6. Patch (opt-in; the default path is unchanged)

The binary I measured is a measurement build with extra modes (log, after, both). Its before path is exactly the lines below. This trimmed diff itself has not been rebuilt and re-run; I will do that before opening a PR.

sycl/src/core/gguf_expert_source.cpp (against 011c9e6)
@@ -4,6 +4,7 @@
 
 #include <algorithm>
 #include <atomic>
+#include <cstdlib>
 #include <cstring>
 #include <utility>
 #include <fcntl.h>
@@ -132,4 +133,12 @@ int64_t GgufExpertSource::mirror(const std::vector<std::pair<int64_t, int64_t>>&
     // is built from chunks under that. Battlemage and the CUDA/HIP builds never hit the limit, but chunking is neutral
     // for them. One chunk per (up to) 2 GiB of experts.
     constexpr uint64_t kChunk = 2ull << 30;
+#if !defined(_WIN32)
+    // STRATA_MIRROR_DROP_CACHE=before (#3681): drop the GGUF files' page cache before the pinned chunks are allocated,
+    // so they come out of free memory rather than reclaim. Chunks the xe driver hands out under reclaim are read by
+    // the GPU at 55-85% of the bandwidth of chunks from free memory (CPU reads are unaffected). The mirror's own reads
+    // below then come from the disk (+1.4 s for 25.7 GiB on NVMe).
+    if (const char* v = std::getenv("STRATA_MIRROR_DROP_CACHE"); v != nullptr && std::strcmp(v, "before") == 0)
+        for (int fd : fds_) if (fd >= 0) (void) posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
+#endif
     std::vector<uint8_t*> chunks;

Limits:

  • Linux, xe, one Arc Pro B70 box. CUDA and HIP were not tested.
  • It only frees what the engine's own files hold in the page cache. If other processes hold the memory, before cannot help; root-side compaction or iommu=pt (still untested) would be the next step.

What I would propose next: a PR with this opt-in plus one start-log line reporting MemFree before and after the drop. I can also run the same A/B on another backend if someone wants to compare, and add the iommu=pt result here once I have it.

<!-- gh-comment-id:6348466930 --> @phg1024 commented on GitHub (Oct 22, 2026): ## Follow-up: refined cause, a root-free reproduction, and an opt-in fix measured in the engine **Short version.** "Fragmentation" in the original report was too broad. What matters is whether the mirror's pinned chunks are allocated from **free memory** or **under reclaim**. - Chunks the xe driver hands out while the kernel reclaims page cache are read by the GPU at roughly 55–85% of the bandwidth of chunks taken from free memory. CPU reads of the same chunks run at full speed. - The engine's own start-up reads (weights, the VRAM expert fill) fill the page cache before `GgufExpertSource::mirror()` runs. So on a 64 GB host, MemFree at that point is often below 1 GiB, against 25.7 GiB needed for the mirror. - Dropping the GGUF files' page cache **just before** the chunks are allocated made decode stable across 24 engine starts and a 5-hour soak with random restarts. That is an opt-in `posix_fadvise`, with the patch below. Unless noted otherwise, everything below was measured on the same box as in the report, now at PCIe 4.0 x16 with 0 AER errors throughout. Engine: `main` @ `011c9e6` (v0.2.2) plus the patch. ### 1. Where the pages come from (Level Zero is not the variable) With `NEOReadDebugKeys=1 PrintBOCreateDestroyResult=1 LogAllocationMemoryPool=1 PrintBOChunkingLogs=1`, a 2 GiB `sycl::malloc_host` is a single system-memory BO: ``` Chunking available: 0; enabled for: shared allocations 0, device allocations 0; minimalChunkingSize: 2097152 Performing DRM_IOCTL_XE_GEM_CREATE with {vmid=0x0 size=0x80000000 flags=0x1 placement=0x1 caching=1 } ... BO-65 with size: 2147483648 Type: BUFFER_HOST_MEMORY Pool: System4KBPages ... Size: 2147483648 ``` The UMD passes no page-size hint, so the physical backing is decided by xe/TTM in the kernel. ### 2. GPU vs CPU reads of the same chunks This is a standalone SYCL microbenchmark: 13 × 2 GiB `malloc_host` chunks, the mirror's shape. For each chunk it measures a GPU copy-engine H2D, a GPU kernel zero-copy read, and a CPU read with 8 threads. Values are GB/s, listed per chunk in allocation order. | host state when allocating | MemFree | GPU copy H2D | GPU kernel read | CPU read | |---|---|---|---|---| | page cache dropped | 60 GB | 27 ×13 | 24 ×13 | 30–31 ×13 | | after one engine start/stop and a 22 GB file read | **11 GB** | **27 27 27** 23 16 16 16 19 20 18 21 20 22 | **24 24 24** 20 14 14 14 17 18 16 18 17 19 | 30–31 ×13 | | page cache dropped again (no root: `posix_fadvise` on the model files) | 61 GB | 27 ×13 | 24 ×13 | 30–31 ×13 | In the slow state, the first ~6 GiB came from free memory at full speed. Every chunk that needed reclaim is slow for the GPU only, never for the CPU. I have not yet separated whether the cost is IOMMU translation or the GPU's own PTE granularity on small pages. `iommu=pt` is the next test, and it needs a reboot. ### 3. Reproduction without root 1. Drop the page cache of the model files with `posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED)` on each GGUF. Then start the engine and benchmark it: fast. 2. Stop the engine, read any ~22 GB file (`cat other.gguf > /dev/null`), start it again and benchmark: slow. It reproduced on every pair below. ### 4. In the engine: `STRATA_MIRROR_DROP_CACHE` A/B over 24 starts - **Protocol:** 3 arms run as 2 blocks each, in the order `off, before, both, both, before, off`. Here `off` is a build mode that only reports MemFree and drops nothing. - **Each block:** drop the model files' page cache, then make 4 consecutive engine starts with a 22 GB unrelated file read between starts. - **Each start:** a 2K and a 32K needle prompt, 512 tokens, temperature 0. - **Correctness:** 48/48 needles found. Decode is in tok/s as 2K / 32K, with one value per block. MemFree is read in the engine right before the chunks are allocated. | start | off | **before** | both | |---|---|---|---| | 1 | 40.4/40.8, 44.1/44.4 | **44.1/44.4, 44.2/44.5** | 44.1/44.5, 44.1/44.5 | | 2 | 37.4/38.3, 36.8/37.5 | **44.2/44.5, 44.1/44.4** | 43.1/43.6, 43.3/43.7 | | 3 | 38.4/39.1, 38.4/39.2 | **44.2/44.5, 44.1/44.5** | 42.1/42.4, 42.2/42.6 | | 4 | 36.4/37.2, 36.9/37.6 | **44.2/44.5, 44.2/44.5** | 41.2/41.6, 41.4/41.8 | | MemFree at allocation | start 1: 22.5–23.5 GiB; starts 2–4: **0.7–1.0 GiB** | after the drop: 51.4 GiB at start 1, **30.4 GiB** at starts 2–4 | same as `before` | - **Cost of `before`:** the mirror fill reads from NVMe instead of the cache, 13.0 s → 14.4 s per start. - **Negative result:** dropping the mirrored ranges **after** filling the mirror (`after`, my first attempt) made restarts 2–4 *slower* than off: 27.6–30.3 against 35.5–38.9 tok/s, again as two ABBA blocks. `both` drifts down over restarts. I do not have a clean explanation for either, so the patch below does only `before`. ### 5. Five-hour soak with `before` on the live service - **Load:** Poisson arrivals with a 120 s mean; prompts of 1K–128K plus 57 follow-up turns, 170 requests in all. - **Restarts:** 6 random restarts, 5 of them right after reading a 16–22 GB unrelated file. - **Correctness:** 0 errors and 0 wrong answers. AER 0, xe engine resets 0. - **Memory at each restart:** MemFree before the drop was 1.2–5.9 GiB, and 29.1–41.4 GiB after it. - **Speed:** a fixed 2K probe, run after every restart and every 30 min, stayed at **58.0–59.5 tok/s** in all 13 runs. - **Caveat:** the soak had no control arm. The controlled comparison is section 4. ### 6. Patch (opt-in; the default path is unchanged) The binary I measured is a measurement build with extra modes (`log`, `after`, `both`). Its `before` path is exactly the lines below. This trimmed diff itself has not been rebuilt and re-run; I will do that before opening a PR. <details><summary>sycl/src/core/gguf_expert_source.cpp (against 011c9e6)</summary> ```diff @@ -4,6 +4,7 @@ #include <algorithm> #include <atomic> +#include <cstdlib> #include <cstring> #include <utility> #include <fcntl.h> @@ -132,4 +133,12 @@ int64_t GgufExpertSource::mirror(const std::vector<std::pair<int64_t, int64_t>>& // is built from chunks under that. Battlemage and the CUDA/HIP builds never hit the limit, but chunking is neutral // for them. One chunk per (up to) 2 GiB of experts. constexpr uint64_t kChunk = 2ull << 30; +#if !defined(_WIN32) + // STRATA_MIRROR_DROP_CACHE=before (#3681): drop the GGUF files' page cache before the pinned chunks are allocated, + // so they come out of free memory rather than reclaim. Chunks the xe driver hands out under reclaim are read by + // the GPU at 55-85% of the bandwidth of chunks from free memory (CPU reads are unaffected). The mirror's own reads + // below then come from the disk (+1.4 s for 25.7 GiB on NVMe). + if (const char* v = std::getenv("STRATA_MIRROR_DROP_CACHE"); v != nullptr && std::strcmp(v, "before") == 0) + for (int fd : fds_) if (fd >= 0) (void) posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED); +#endif std::vector<uint8_t*> chunks; ``` </details> **Limits:** - Linux, `xe`, one Arc Pro B70 box. CUDA and HIP were not tested. - It only frees what the engine's own files hold in the page cache. If other processes hold the memory, `before` cannot help; root-side compaction or `iommu=pt` (still untested) would be the next step. **What I would propose next:** a PR with this opt-in plus one start-log line reporting MemFree before and after the drop. I can also run the same A/B on another backend if someone wants to compare, and add the `iommu=pt` result here once I have it.
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:6659611402 --> @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#1524
No description provided.