Repository navigation
spark-runtime: shift Ling shard mmaps off ARM64 contpte boundaries - #445
Open
data-angel wants to merge 1 commit into
Open
data-angel wants to merge 1 commit into
data-angel wants to merge 1 commit into
Conversation
On Linux aarch64 with CONFIG_ARM64_CONTPTE=y and GB10 hardware ATS, a 64 KiB-aligned file-backed mmap lets contpte_set_ptes / __contpte_try_fold fold 16 contiguous 4 KiB PTEs of a large file folio into a 64 KiB PTE_CONT entry. When multiple GPU warps concurrently fault subpages 1..15 of an unmapped large folio over ATS, faulting 32-byte cache sectors silently read subpage 0 of that 64 KiB folio ((addr & ~0xffff) | (addr & 0xfff)), causing run-to-run greedy divergence on FP8 strict Ling-3.2-air (Atlas-Inf#439). On linux/aarch64, map Ling shards by reserving a private PROT_NONE span, mapping the file MAP_PRIVATE | MAP_FIXED at a 2 MiB-aligned address plus one base page, and unmapping the unused guard edges. Shifting va_base by one base page breaks (va >> PAGE_SHIFT) % CONT_PTES == pfn % CONT_PTES for buddy-allocated large folios across 4K/16K/64K kernels (and 2 MiB PMDs) permanently across kswapd reclaim and re-faults, while preserving 4 KiB tensor alignment and zero-copy ATS reads. Move ling_paging unit tests to ling_paging_tests.rs to stay under the 500-LoC file cap and add coverage for the guard/shift placement math and live aarch64 base-address offset.
This was referenced Dec 3, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Linux aarch64 (
CONFIG_ARM64_CONTPTE=y) with NVIDIA GB10 hardware ATS, 64 KiB-aligned file-backedmmaps allowcontpte_set_ptes/__contpte_try_foldto fold 16 contiguous 4 KiB PTEs of a large file folio into a 64 KiBPTE_CONTmapping. When multiple GPU warps concurrently fault subpages1..15of an unmapped 64 KiB folio over ATS, faulting 32-byte GPU cache sectors silently read subpage0((addr & ~0xffff) | (addr & 0xfff)), returning valid FP8 weight bytes from 4-60 KiB earlier in the shard. Subsequent reads see settled PTEs and return the true bytes.This change shifts
LingPagingReader'sMAP_PRIVATEshard base by one base page off a 2 MiB boundary (va_base % 2 MiB == page_size) onlinux/aarch64by reserving aPROT_NONEVA span, overlayingMAP_PRIVATE | MAP_FIXED, and unmapping the unused prefix and suffix. Buddy-allocated large folios (order >= 4) have aligned PFNs, so(va >> PAGE_SHIFT) % CONT_PTES != pfn % CONT_PTESholds permanently acrosskswapdreclaim and re-faults across 4 KiB (64 KiBPTE_CONT), 16 KiB (2 MiB), and 64 KiB (2 MiB) kernels as well as 2 MiB PMDs. Tensor alignment (4 KiB, hence 4/16/128-byte), RAM footprint, CUDA graph capture, and zero-copy ATS reads are unchanged.Moves
ling_pagingunit tests tocrates/spark-runtime/src/weights/ling_paging_tests.rsso both files stay under the 500-LoC cap (415and175lines).Closes #439
Evidence
Tested on GB10 (
ennspark03, Linux7.0.0-1019-nvidiaaarch64,CONFIG_ARM64_4K_PAGES=y,CONFIG_ARM64_CONTPTE=y, NVIDIA Open Kernel Module580.178.04,uvm_ats_mode=1,uvm_disable_hmm=Y):inclusionAI/Ling-3.2-airshardsMAP_PRIVATEand unmapping PTEs viamadvise(MADV_DONTNEED)with 54+ GiB free RAM (pgsteal_file=0) reproduced the mismatch 4 times across shards 2, 7, and 9. Every corrupted byte matched(foff & ~0xffff) | (foff & 0xfff), while a second GPU read (g2) and CPUmmapmatchedpreadbyte for byte.va % 65536 == 0) and once shifted by+4096(va % 65536 == 4096), alternating every iteration:MAP_PRIVATE(5,000 iters):29 / 5,000corrupt (19,863 words) aligned vs0 / 5,000shiftedMAP_SHARED(5,000 iters):16 / 5,000corrupt (7,418 words) aligned vs0 / 5,000shifted45 / 10,000vs0 / 10,000(p < 3e-14).MADV_NOHUGEPAGEstill failed (2 / 5,000MAP_SHARED,6 / 5,000MAP_PRIVATE) because it only controls PMD THP, not ARM64contpte.inclusionAI/Ling-3.2-airFP8 strict on GB10: Measured on4f763f9with the+4096VA shift (128 KiBbase alignment,va % 65536 == 4096, verified live in/proc/1/mapson all 12 deferred shards;ATLAS_KV_MAX_BLOCKS=32769, CUDA graph decode on):POSIX_FADV_DONTNEED) before boot A on the 8-promptgreedy_eqsuite (C1,temperature=0,cached: [0..0]): 8/8 identical acrossreasoning,content,finish_reason, andcompletion_tokens(7xlength/320, 1xstop/246; hashescfa0d2,a842a5,b019ed,c07367,b7fa1a,0b1fa5,e806b0,96d91a). Cold prompt 0 wall time 193.2 s vs 191.4 s unpatched, decode 3.1-10.6 tok/s.LING439_REPEAT=1onling_fp8_gate_up_shared): 0 mismatches across 1,760 token/layer launches.38485bfb9, based onmaine5530ce4d) widens the guard alignment from32 * page_size(128 KiB) to2 MiBsova_base % 65536 == 4096holds identically on 4 KiB kernels and also covers 16 KiB / 64 KiBCONT_PTESand 2 MiB PMDs. The PR tip passed Rust 1.93.1 Linux aarch64fmt,clippy --workspace --tests,ling_pagingunit tests (7/7), andcargo doc; the 2-boot GPU serve run above was recorded on4f763f9with the 128 KiB shift before widening the alignment to 2 MiB.Test plan
cargo fmt --all -- --checkATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --locked --workspace --tests(Rust 1.93.1, Linux aarch64)ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test --locked -p spark-runtime --lib -- ling_paging(7/7 passed on Linux aarch64, including liveshifts_mapping_base_off_arm64_contpte_boundaryand cross-platformcontpte_shifted_span_fits_inside_guard_for_all_page_alignments)RUSTDOCFLAGS="-D warnings" ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo doc --locked -p spark-runtime --no-depspython3 scripts/check_spdx.py,python3 scripts/check_kernel_shadows.py,typos, and 500-LoC cap (ling_paging.rs: 415 lines,ling_paging_tests.rs: 175 lines)inclusionAI/Ling-3.2-airFP8 strict (8/8 identical across 2 fresh boots + 0/1,760 repeat mismatches on4f763f9++4096shift)Notes for reviewers
LingPagingReaderis the only file-backedmmappassed to GPU ATS in the workspace (ling_moe_fast.rs,ling_moe_load.rs,ling_sante.rs);spark-storagemmaps are RDMA/NIC-only.ATLAS_*environment variables or CLI flags are added.Authorship
AI-authored: Antigravity (Gemini), directed and reviewed by a human; no hand-written code.
CLA