Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 KiB
5090 decode: huge pages for the resident expert banks (claude/hugepages)
Date 2026-11-01. RTX 5090 server rnr5090 (Ryzen 9 9950X3D, 121 GiB, kernel 7.0.0-38), frozen corpus, ~245k context, 5 turns. Base = main fe5910135 (code of 11e021161).
Labels: M measured in the run named, E estimate, C code reading.
Follows baseline-pair-5090 section 5 (vanilla 7-8 % slower when its arena gets only partial THP) and cpu-service-5090 section 6.
1. Which host memory the decode reads, and how it is mapped
| reader | memory | mapping (M: /proc/<pid>/smaps of b05p2-ours, runs/baseline-pair-c, 2026-10-31 23:41Z) |
|---|---|---|
CPU expert pool (cpu.compute) |
the resident bank copy: 144 tensors (gate/up/down x 48 layers) of shard 0 copied into heap Vec<u8>s by load_resident_expert_source (C: gguf_resident.rs load_resident_tensor) |
one private anonymous VMA of 46.84 GiB RSS (the 144 glibc mmap chunks merged), 4 KiB pages, AnonHugePages 0 |
| PCIe expert uploads (copy kernel / DMA) | the same banks, registered with cuMemHostRegister(DEVICEMAP) (C: mapped_expert_bank.rs); the GPU sits behind the AMD IOMMU in translated DMA-FQ mode (/sys/kernel/iommu_groups/*/type), so its reads also walk the IOMMU page table |
same VMA |
| KAR memfd (holder, 51.5 GiB shmem) | PLE rows only, read with pread (C: qwen4exp_kar_ple.rs read_exact_at) through the kernel's own direct map |
mapped read-only once by leleka-memory for mlock/mincore only: Rss 0; never dereferenced |
| pinned staging / arenas | cuMemHostAlloc buffers |
29 shared /dev/zero (shmem) mappings, 3.7 GiB RSS, 4 KiB |
System (M, read only): THP enabled=madvise, defrag=madvise, shmem_enabled=never (also per-size inherit), khugepaged max_ptes_none=511, HugePages_Total=0,
nr_overcommit_hugepages=0, CONFIG_READ_ONLY_THP_FOR_FS not set, ext4 /data. Process: VmPin 0 (the NVIDIA driver does not account its pins there).
Consequences: the 46.8 GiB the decode actually reads can use THP from userspace (anonymous memory + MADV_HUGEPAGE, which enabled=madvise honours). The memfd cannot get THP at
allocation while shmem_enabled=never (MADV_HUGEPAGE on shmem is ignored, MFD_HUGETLB needs reserved hugetlbfs pages), but the decode does not read it through a mapping, so
it does not matter for this path; scripts/e2e/decode/owner-shmem-thp.sh (root, not run) is the switch should a future path map it. The old LELEKA_BANK_THP=on knob
(claude/decode-parity, "took no effect") only advised the unaligned heap Vec.
2. Change (opt-in, off by default)
LELEKA_HUGEPAGES=on (thp = skip the hugetlbfs attempt; LELEKA_BANK_THP=on now means thp), crates/model-format/src/huge_pages.rs:
- each bank in its own 2 MiB-aligned private anonymous mapping (over-allocate 2 MiB, trim) instead of a heap
Vec; MAP_HUGETLB | MAP_HUGE_2MBonly whenHugePages_Freecovers the bank (none on rnr5090; nothing reserved);- otherwise
MADV_HUGEPAGE+MADV_POPULATE_WRITE(fault in before the file is read into it), then the sameread_tensor_into(same FD, bounds and size fences as the heap copy); huge_pages::settle()after the bank load and the shard page-cache drop, before the banks are page-locked: coverage from/proc/self/smapsandMADV_COLLAPSEof 2 MiB ranges that fell back (Linux 6.1+, independent of the sysfs knobs; best effort). One log lineleleka-hugepages: ...per stack start.- budget charge unchanged (
lenbytes; THP uses the same pages as the heap copy).
3. Identity (runs/hugepages-id, job hp-id2, 2026-11-01 03:34Z)
Replay of night5-long-256k (5 requests, 48 forced tokens each, top-16 logprobs), static tier, 8,000 slots, one CPU worker, one test binary /data/leleka-e2e/hugepages/rt-hugepages
(a8171b2cc). M.
comparison (q_pair, 353 rows) |
identical | different | flips |
|---|---|---|---|
| heap A/A | 353 | 0 | 0 |
| huge-page A/A | 353 | 0 | 0 |
| huge-page vs heap (arm 0, arm 1) | 353, 353 | 0, 0 | 0, 0 |
q_tail_gate PASS in both processes. The huge-page process really ran on huge pages: AnonHugePages 44.9 GiB of the process (idOn.smaps.txt), coverage line 92.6 % after fill,
95.8 % after collapse (this test path does not drop the shard page cache first, so 16 collapses hit ENOMEM; khugepaged finished the rest). The first attempt (hp-id) failed at the
binding because my MTP staging directory was 0775 (the binding requires 0700); fixed in the script, no measurement lost.
4. Paired A/B (runs/hugepages-ab, job hp-ab, 2026-11-01 01:56-03:21Z)
One binary /data/leleka-e2e/hugepages/bin-hugepages (a8171b2cc), arms by environment only: hpoff (defaults) and hpon (LELEKA_HUGEPAGES=on). Both: seed off, upstream ranked profile,
auto slots (12,192 in every run), prefix cache auto, spec-min-p 0, PCIe share 0.45 (the product default, set explicitly). 8 pairs in ABBA order (pair k = runs 2k-1, 2k; the first
arm alternates), so each arm follows each arm equally often. Frozen corpus, 5 turns, final-turn input 246,885 tokens in all 16 runs; all 16 VALID. State recorded by
baseline-sampler.py (pre / during / post). Uptime 37-38.5 h. M.
| arm | n | all-turn tok/s mean (sd) | range | tokens/round | ms/round (sd) | process AnonHugePages | free >= 2 MiB after exit |
|---|---|---|---|---|---|---|---|
| hpoff | 8 | 146.5 (1.49 = 1.02 %) | 143.7-148.2 | 2.031 | 13.86 (0.12) | 0 | 46.8 GiB |
| hpon | 8 | 148.4 (0.92 = 0.62 %) | 146.7-149.7 | 2.042 | 13.75 (0.14) | 46.78 GiB (99.9 %) | 52.1 GiB |
Pair differences (hpon - hpoff, same pair): tok/s +0.08 +2.93 +2.11 +3.73 +1.44 -0.38 +0.22 +0.16 % -> mean +1.29 % (se 0.54, t 2.4, 7/8 positive); ms/round -0.035 -0.038 -0.027 +0.053 -0.371 +0.002 -0.315 -0.160 -> mean -0.11 ms (-0.8 %, se 0.055, t -2.0, 6/8 lower); tokens/round +0.011 (noise).
Window decomposition (windows 20+ of turns 3-5, from DBG window lines, mean of the 8 runs per arm):
| arm | window ms | host pool ms | GPU wait ms | CPU experts / window | PCIe experts / window | pool us per CPU expert |
|---|---|---|---|---|---|---|
| hpoff | 11.84 | 2.81 | 8.87 | 33.2 | 7.0 | 84.8 (84.1-85.4) |
| hpon | 11.88 | 2.93 | 8.79 | 35.2 | 8.3 | 83.3 (82.7-84.4) |
Pool time per CPU expert is lower in 8 of 8 pairs (-0.1 to -2.3 us, mean -1.5 us, -1.8 %). The hpon runs happened to serve ~2 more CPU and ~1.3 more PCIe experts per window (VRAM share 95.6-96.0 % against 95.7-96.1 %; the generated text differs between runs of either arm because window width and swaps are timing-dependent policies) and still had the same window time and 0.08 ms less GPU wait. "pool us per CPU expert" is window pool time / CPU experts and includes the per-window fixed costs, so it is not the 61 us of cpu-service section 6.
Reading it: huge pages are a real but small lossless gain for ours, +1.3 % tok/s / -0.8 % ms/round at the edge of this n (p about 0.05 and 0.08, two-sided), with the CPU-pool per-expert cost the cleanest signal (8/8). They do not explain the bulk of the remaining per-expert difference to vanilla (vanilla's 7-8 % THP effect in baseline-pair is on vanilla's own code, whose window is shorter; the TLB part of ours is ~1.5 us of ~84 per expert here). Run-to-run spread of hpon is lower (sd 0.62 % against 1.02 %), n=8, not tested for significance.
5. Fragmented vs unfragmented memory, load time, exit state (M, same runs)
- Coverage under fragmentation. Before every hpon run free memory in >= 2 MiB blocks was 43.0-52.7 GiB (after an hpoff run 43.0-47.8, after an hpon run 50.4-52.7). The fault-time fill got 87.8-92.3 % huge pages; the collapse after the shard page-cache drop brought every run to 99.9 % (46.78 of 46.84 GiB) in 0.48-0.78 s, 0 failures. So in the fragmentation ours itself leaves behind, the opt-in reaches full coverage.
- Predecessor. hpon after hpoff 148.2 tok/s (n=4) / after hpon 148.5 (n=4); hpoff after hpoff 146.6 (n=3; plus the first run) / after hpon 146.2 (n=4). Neither arm depends on
its predecessor. A compacted ("fresh") machine was not tested: that needs
owner-compact-memory.shasPRE_ARM_HOOK(root, owner). - Exit fragmentation. After an hpoff run 46.8 GiB (45.6-48.3) are free in >= 2 MiB blocks, after an hpon run 52.1 GiB (50.4-53.1): the huge-page banks go back to the buddy
allocator as 2 MiB blocks. baseline-pair found vanilla gets its full 46.8 GiB arena on huge pages only with >= 48 GiB of such blocks: every hpon exit leaves more than that,
6 of 8 hpoff exits less (43.0-47.9; two at 48.2-48.3). So
LELEKA_HUGEPAGES=onshould also remove the "vanilla after ours" penalty of the interleaved baseline (E, not measured). - Load time. Bank admission 50.1 s (hpoff) vs 53.4 s (hpon), stack ready 134.3 vs 135.3 s (means of 8; both IO-dominated and noisy, 98-217 s). hpon causes ~20,000 direct
compaction stalls per start (
compact_stall, against 79-527 for hpoff) while it faults the banks in under a full page cache; this is not visible in the ready time.
6. What this does not change, and owner items
- Default stays off (opt-in,
LELEKA_HUGEPAGES=on); a default flip is the orchestrator's call on this A/B plus the identity gate. - The KAR memfd stays on 4 KiB shmem pages; not on the decode path (section 1).
scripts/e2e/decode/owner-shmem-thp.sh(root, NOT run) togglesshmem_enabledshould a future path map it. The 3.7 GiB ofcuMemHostAllocstaging (shared/dev/zero) is shmem as well and also stays 4 KiB. - Not run, owner:
owner-compact-memory.shasPRE_ARM_HOOKfor the compacted-memory case. No hugetlbfs pages were reserved; withvm.nr_hugepagesset by the owner the same flag would use them (MAP_HUGETLB, untested on the server).
7. Reproduce
scripts/e2e/decode/hugepages-install.sh <dir with the binaries> (server) freezes /data/leleka-e2e/hugepages/{tools,bin-hugepages,rt-hugepages} and writes MANIFEST.sha256; stubs
hp-ab.sh / hp-id2.sh in ~/work/gpu-runs/holder2/jobs/ exec tools/hugepages-ab.sh / tools/hugepages-id.sh. Analysis: python3 -I tools/hugepages-analyze.py /data/leleka-e2e/runs/hugepages-ab --csv hugepages-ab.csv (runs/hugepages-ab/ANALYSIS.*.txt, hugepages-ab.csv).