Files
leleka/docs/experiments/hugepages-5090.md
T

3.6 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_2MB only when HugePages_Free covers the bank (none on rnr5090; nothing reserved);
  • otherwise MADV_HUGEPAGE + MADV_POPULATE_WRITE (fault in before the file is read into it), then the same read_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/smaps and MADV_COLLAPSE of 2 MiB ranges that fell back (Linux 6.1+, independent of the sysfs knobs; best effort). One log line leleka-hugepages: ... per stack start.
  • budget charge unchanged (len bytes; THP uses the same pages as the heap copy).

3. Identity (runs/hugepages-id, job hp-id)

PENDING.

4. Paired A/B (runs/hugepages-ab, job hp-ab)

PENDING.