Skip to content

v0.4.4 takes over 15 minutes to prepare a 119 GiB host prefix cache on fragmented Linux memory #616

In review

Description

@ktsaou

On a Linux host with transparent huge pages (THP) and THP defragmentation both set to madvise, FLARE v0.4.4 spent 914.6 seconds in Prepare host prefix cache. The disk namespace was empty. With THP still enabled in madvise mode and defragmentation set to defer from process launch, the same signed core prepared the same-sized cache in 71.1 seconds. During the slow startup, tools inspecting processes on the host also became slow to respond.

Observations

Runtime THP defragmentation during startup Disk records staged Host-cache phase
2bdc8472, previous deployment madvise 5,244 131.8 s
v0.4.4, first private start madvise 0 914.6 s
v0.4.4, second private start after clearing the filesystem page cache madvise initially, switched to defer after about 18 minutes 959 1,279.5 s
v0.4.4, production start defer throughout 965 71.1 s

All starts used a 119.4 GiB host prefix cache with 133,790 slots. The three v0.4.4 runs used the same executable and signed core. Host load varied between runs. The v0.4.4 runtime carries a local retry for sealing the embedding-table memfd. Its allocator and Selene slab code match the release tag.

Linux reported abundant available memory. During the second slow start, both NUMA nodes' Normal zones had zero free 2 MiB blocks in a /proc/buddyinfo sample. The partially populated slab had over 52 GiB of anonymous huge pages in /proc/PID/smaps. Direct-compaction stalls were rising. After the operator changed the defragmentation policy, the process finished populating the slab. Near the end of the same journal phase, eight consecutive main-thread samples showed an ioctl on an NVIDIA device. These runs did not time population and device registration separately.

Environment and reproduction

  • Linux 7.0.0-42-generic, 4 KiB base pages, two NUMA nodes, two discrete RTX PRO 6000 Blackwell GPUs.
  • FLARE v0.4.4 at 993396063fe8. The Qwen TP2 C32 MTP core uses RAM for the embedding table, --prefix-cache-memory 128G and an enabled local disk tier.
  • On a similarly fragmented test host, capture the THP enablement and defragmentation settings, the Normal-zone free-block counts, and the Prepare host prefix cache elapsed time when starting the same core. The first v0.4.4 result above occurred with zero disk records, so a large persisted cache is unnecessary to observe the delay.

Suspected cause and expected behavior

PR 589 changed eos::map_host from populating the mapping before advising huge pages to issuing MADV_HUGEPAGE before MADV_POPULATE_WRITE. Selene uses this function for the contiguous host slab. On Linux, madvise defragmentation permits synchronous reclaim and compaction for a huge-page-advised range. The ordering and observations are consistent with compaction delaying initial population. They do not quantify its share of the full journal phase. Allocator change · Tagged allocator · Selene slab · Linux THP policy

Could the large slab use an allocation strategy that falls back promptly to base pages when contiguous huge pages are scarce? Separate startup timings for slab population and CUDA registration would also make this regression easier to diagnose. Our working mitigation changes the host-wide THP defragmentation policy, which also affects unrelated workloads.

Activity

  1. flare-autobot commented on Nov 30, 2026

    @flare-autobot
    Collaborator

    Verified on origin/main (493f24c3).

    Root Cause

    In eos/src/unix.rs:85-119, map_host creates an anonymous mapping, unconditionally advises MADV_HUGEPAGE over the entire range, and prefaults it in a single madvise(MADV_POPULATE_WRITE) syscall. Contiguous host prefix-cache slabs (SlabPool::new in selene/src/slab.rs:162-178, invoked from selene/src/offload.rs:642-658 whenever disk offload, pool sharing, KV compression, or non-VMM fallback is active) and remote pool staging (Region::anonymous in selene/src/pool/shm.rs:74-86) both allocate through eos::map_host.

    Under Linux transparent huge pages (THP) configured with defrag=madvise (or defer+madvise or always), advising MADV_HUGEPAGE before MADV_POPULATE_WRITE enables synchronous direct reclaim and compaction whenever contiguous PMD-sized (2 MiB on 4 KiB kernels) blocks are unavailable. Faulting a 119 GiB mapping in one call keeps mmap_lock held across sustained compaction stalls and amplifies host-wide contention. In addition, NativeModel::prepare_offload (helios/src/runtime_core/model.rs:924-981) ran slab population, CUDA host registration, and disk record scanning inside Prepare host prefix cache without intermediate step details or separate elapsed timings in Prepared::summary() (selene/src/offload.rs:400-444).

    Implemented Fix

    All cache schemes and contiguous host-slab offload configurations share eos::map_host and selene::offload, so the fix applies across every supported model contract without model-specific paths, runtime flags, or environment variables:

    • Policy-aware Linux slab population and single-VMA preservation (eos/src/unix.rs):
      • map_host rejects bytes == 0 with EINVAL, wraps the anonymous mapping in an RAII MappingGuard that calls munmap on population failure, retries MADV_POPULATE_WRITE on EINTR, falls back to page-strided volatile writes only on EINVAL or ENOSYS, and propagates fatal errors.
      • On Linux, map_host inspects /sys/kernel/mm/transparent_hugepage/{enabled,defrag,hpage_pmd_size} (deriving portable 2 MiB / 32 MiB / 512 MiB PMD defaults for 4 KiB / 16 KiB / 64 KiB kernels when hpage_pmd_size is unreadable):
        • enabled=never: populates in bounded 64 MiB base-page chunks without THP advice.
        • defrag=defer or never: advises MADV_HUGEPAGE upfront and populates in bounded 64 MiB chunks.
        • enabled=always with defrag=madvise or defer+madvise: omits MADV_HUGEPAGE and populates in bounded 64 MiB chunks via the kernel's opportunistic path.
        • Synchronous-compaction policies (enabled=madvise with defrag=madvise|defer+madvise|always, or enabled=always with defrag=always, or unknown policy): pre-anchors one shared anon_vma on the unsplit mapping, walks growing PMD-aligned chunks up to max(16 MiB, hpage_pmd_size) while checking order-weighted free huge pages in /proc/buddyinfo, chunk fault latency thresholds, and /proc/vmstat compact_stall, falls back promptly to 64 MiB base-page chunks when free huge pages are low or compaction stalls begin, and issues a final whole-range madvise (MADV_NOHUGEPAGE after fallback, MADV_HUGEPAGE otherwise) so Linux merges all sub-VMAs back into one contiguous VMA before cuMemHostRegister_v2 or ibv_reg_mr.
    • Separate startup timings and live step updates (selene/src/offload.rs, helios/src/offload/mod.rs, helios/src/runtime_core/model.rs, docs/prefix-cache-offload.md):
      • Records PrepareTimings (slab_populate, cuda_register, disk_scan), exposes prepare_with_inputs_budget_with_progress (preserving existing signatures), updates live phase.detail(...) labels during Prepare host prefix cache (including resetting step and timer when split-by-rank VMM allocation falls back to a contiguous slab), and appends allocate, populate, register, and scan durations inside Prepared::summary() while leaving restore-only and disabled summaries unchanged.

    Verification & Unrun Checks

    Two-NUMA x86_64 Linux 6.8.0-151-generic + discrete NVIDIA RTX PRO 6000 Blackwell Max-Q (SM120) (4 KiB base pages, 2 MiB hpage_pmd_size, THP enabled=madvise, defrag=madvise, initial free huge pages ~12.4 GiB across both Normal zones out of 236.8 GiB available RAM):

    • eos: 11/11 tests passed; selene (--features test-support): 552 unit + 1 integration tests passed.
    • Direct A/B benchmark (eos::map_host vs prior MADV_HUGEPAGE + single MADV_POPULATE_WRITE) and discrete SM120 cuMemHostRegister_v2 + DMA round-trip:
      • 48 GiB fragmented cold start: 30.99 s (compact_stall +62, 1 merged VMA, AnonHugePages=2,046 MiB, VmFlags nh) vs 128.56 s (compact_stall +25,654) on the prior path (4.15x faster); cuMemHostRegister_v2(48 GiB, PORTABLE) 9.48 s (rc=0), 4 MiB head->SM120->tail DMA round-trip passed.
      • 48 GiB post-compaction (huge pages available): 13.78 s (AnonHugePages=43,230 MiB, 90% huge pages, 1 VMA).
      • 119 GiB (eos::map_host(119 GiB)): populate 57.19 s (compact_stall +2,031, 1 merged VMA, AnonHugePages=43,454 MiB, VmFlags nh) + cuMemHostRegister_v2(119 GiB, PORTABLE) 11.27 s (rc=0, 68.46 s combined), 4 MiB head->SM120->tail DMA round-trip passed.

    Linux ARM64 SM121 (NVIDIA GB10, Linux 7.0.0-1025-nvidia, THP enabled=madvise, defrag=madvise):

    • eos: 11/11 tests passed, including live /proc/self/smaps single-VMA merging on both normal map_host and forced mid-mapping fallback (adaptive_mid_mapping_fallback_merges_into_single_vma).
    • selene (--features test-support): 552 unit + 1 integration tests passed (including 4 offload timing and progress-step tests); selene --tests --features rdma compiled cleanly.
    • selene-manager (--features test-support): 412 passed across 11 binaries (1 ignored) and 11/11 passed on tests/pool_store.rs follow-up (one pre-existing timing-ratio test a_freed_window_credit_is_granted_without_waiting_for_the_clock flaked identically on unmodified parent commit 59adc480).
    • helios (--features runtime-core,server with prepared frontend templates): 1,753 lib and 62 integration tests passed; flare: 245 passed; flare-cli: 228 passed.
    • CUDA host registration (FLARE_RUN_CUDA_TESTS=1 on NVIDIA GB10): host_registration_unregisters_when_dropped_on_another_thread and batched_copies_round_trip_through_registered_memory both passed, and a direct cuMemHostRegister_v2 + H2D/D2H check passed on pure-THP (16 MiB, 1 VMA), pure-base-page (16 MiB, 1 VMA), and mixed THP-prefix plus base-page-tail merged allocations (32 MiB, 1 VMA, AnonHugePages=8192 kB, VmFlags nh).

    Unrun checks:

    • End-to-end flare run with --prefix-cache-memory and --prefix-cache-disk and tests/server/test_prefix_cache_offload.py (the discrete SM120 host lacked cmake for native turbojpeg-sys builds, and the SM121 host had no exported cores).
    • Live RDMA ibv_reg_mr registration, 16 KiB/64 KiB ARM64 Linux kernels, and kernels without CONFIG_TRANSPARENT_HUGEPAGE (covered by deterministic parser and policy unit tests only).

    A companion pull request containing this fix is open at #625.

  2. added
    area:memory
    area:preparation
    area:selene
    bug
    performance
    priority:P2
    triage:investigate
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:memoryarea:preparationarea:selenebugperformancepriority:P2triage:investigate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions