Repository navigation
Provider: RAM-only prefix cache for memory_only (zero data retention) requests - #2573
Closed
jonathan308 wants to merge 14 commits into
Closed
jonathan308 wants to merge 14 commits into
jonathan308 wants to merge 14 commits into
Conversation
A memory_only request (zero data retention) never touches the SSD tier, so on complete-checkpoint slots it prefilled cold on every repeat. Its checkpoints now go to a RAM-only tier with the SSD tier's lookup and restore semantics and no file: - MemoryOnlyCheckpointTier copies the engine's export into one wired region per checkpoint (mmap + MADV_ZERO_WIRED_PAGES + minherit(NONE) + mlock; nothing is kept if wiring fails) and restores it through the engine's own import. Same scope-salted chain tags (per-process key), position rules and identity, salt and exact-prefix checks. Ordinary receipts are refused and counted. - MemoryOnlyCheckpointPool: process-wide budget min(cap, fleet KV headroom / 4), off below 1 GiB; each entry charged to the process ledger and admitted only with a whole budget of headroom beside it; LRU; the SSD tier's TTL and TTL mode; released on memory pressure, before a model load (and counted as reclaimable), on any refused charge, on unload and at shutdown, in both the provider loop and the standalone server. - The SSD store forwards memory-only receipts to its attached tier at PR 1's gates; the bridge stages from it and keeps the prefix cache on for memory_only text requests only on single-Mac slots with a tier. The tier is not attached to GLM-5.3-Flash, DiffusionGemma, pairs or slots built with DARKBLOOM_PREFIX_CACHE_MEMORY=1. - DARKBLOOM_ZDR_PREFIX_CACHE_RAM=auto|off, DARKBLOOM_ZDR_PREFIX_CACHE_RAM_MAX_MB, darkbloom_zdr_prefix_ram_* counters on local /metrics. - The prompt-token piece cache drops a piece 30 minutes after its last use (DARKBLOOM_TTFT_PROMPT_CACHE_TTL_SECONDS, default 1800, 0 = no TTL), for every request.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
A RAM entry is not a durable commit, so the tier now completes every donation with no positions and the engine publishes no ready evidence for a memory_only receipt. Tests read the stored count instead, use a budget below one page for the oversize case, and check the SSD store's own state rather than the process-wide counter other suites also move.
…ull queue refuses - The tier settles a donation its queue refuses (full or shut down): the pipeline hands it back without `onDropped`, so the engine's completion, which closes the donor's publication batch, never ran. - The bridge's RAM stage is its own branch before the base's memory-only barrier, which is unchanged. - The pool removes committed entries in one place, refreshes its gauges under the same lock as a lookup, and names the headroom it requires. - The factory's switch is `attachesMemoryOnlyTier`; helper visibility, comments and two docs sentences tightened; one loop helper shared by the release and handler suites.
…the MiMo guards The RAM-only tier's budget is host memory, so both servers update it at the top of the survivors' re-slice, whatever native MiMo ownership allows.
# Conflicts: # provider-swift/Sources/ProviderCore/KVCacheSSD/SSDHybridCheckpointStore.swift
…d, more tests - A refused charge the tier's entries cover now releases the least recently used ones and retries once, so an ordinary request is admitted on its first call; a charge that can't fit either way leaves the tier held. Engine-owned refusals release only the shortfall, off the admission lock. - closeAndWait now also waits for a restore still filling an engine import. - A re-donation of a held prefix copies nothing (counted as duplicate), so a fixed TTL keeps counting from the first store. - The tier releases its entries before the Mac sleeps, so no hibernation image holds them. - With a budget of 0 the tier is not offered, so marked requests don't capture checkpoints that can't be kept; an export larger than the budget is refused before it is copied. - Nemotron Super gets no tier, as documented. The attach rule is one policy function. - A load releases the tier before evicting a model even with both reclaim rollbacks set; shutdown releases it before the native-owner wait. - The pool is reached through the memory budget, so tests use a private pool. - refused_busy for a full queue; the sweep interval follows a TTL under 60 s; a budget shrunk during a copy still holds; admission refuses before evicting when in-flight copies leave no room; the read scratch covers the manifest decode.
# Conflicts: # docs/provider/direct-mode.md # provider-swift/Sources/ProviderCore/Inference/PrefixCache/RequestCachePolicy.swift
Release before sleep and the partial release on a covered refused charge; the up-to-2x admission cost when free memory bounds headroom; budget 0 and oversize exports; duplicates and the fixed TTL; transient heap copies; Nemotron Super and native MiMo in the configuration row; the changelog no longer repeats #2575's piece-cache change.
# Conflicts: # docs/provider/direct-mode.md # docs/reference/ssd-kv-cache.md
jonathan308
marked this pull request as ready for review
November 23, 2026 10:01
This was referenced Nov 24, 2026
Collaborator
Author
|
Closing: this branch's head (8592233) is already contained in dev. |
This branch was successfully 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.
A RAM-only prefix cache for
memory_only(zero data retention) requestsStacked on #2575 (the
memory_onlycache policy). With #2575 alone, a request whose sealed_darkbloom_cachecarriescache_policy: memory_onlynever touches the SSD tier. On every complete-checkpoint model (gpt-oss-20b, Gemma 4, Qwen 3.5, Qwen 3.6, …) that means it prefills cold on every repeat, because these slots have no RAM prefix tier at all: the engine takes one complete-checkpoint store, and its recurrent RAM bank only runs without one.This PR gives those requests a RAM-only tier with the SSD tier's lookup and restore semantics. The provider writes nothing to a file, the retained pages are wired so they never reach the swap file, and the tier is released before the Mac sleeps, so no hibernation image holds it.
Before / After (observable behaviour)
flowchart LR subgraph Before A1[memory_only request, repeated prefix] --> B1[SSD tier refused, cache off] B1 --> C1[cold prefill every time] D1[ordinary request] --> E1[encrypted SSD tier] end subgraph After A2[memory_only request, repeated prefix] --> B2[RAM-only tier: wired, TTL 30 min, wiped on pressure/sleep/load/unload/exit] B2 --> C2[restored from RAM: cached tokens reported, tier memory] D2[ordinary request] --> E2[encrypted SSD tier, unchanged] endBefore / After (code flow)
flowchart TD subgraph Before S1[EngineV2Bridge submission] -->|memory_only| X1[no SSD stage] G1[engine takeStaged / donate] --> H1[SSDHybridCheckpointStore] H1 -->|memory-only receipt| R1[refused, released unwritten] end subgraph After S2[EngineV2Bridge submission] -->|memory_only| T2[store.memoryOnlyTier.stage] G2[engine takeStaged / donate] --> H2[SSDHybridCheckpointStore] H2 -->|memory-only receipt| T3[MemoryOnlyCheckpointTier] H2 -->|ordinary receipt| F2[SSD files, unchanged] T3 --> P2[MemoryOnlyCheckpointPool: mlock'ed regions, budget, LRU, TTL] Q2[pressure / sleep / load gate / unload / shutdown: release all] --> P2 Y2[refused charge the tier covers: release LRU entries, retry once] --> P2 endWhat changes
KVCacheRAM/(new):MemoryOnlyCheckpointTier: one slot's tier. A donation copies the engine's export (readSegment) and its encoded manifest into one wired region. A restore replays them through the engine's own import (planCompleteCheckpointImport→appendSegment→finish→takeStaged). It uses the same scope-salted chain tags (SSDLookupKeys, under a per-process key), position floor and identity/salt/exact-prefix checks as the SSD tier. It refuses any ordinary receipt (counted; stays 0).MemoryOnlyCheckpointPool: the process-wide budget, LRU, TTL (the SSD tier's, sliding orDARKBLOOM_SSD_KV_TTL_MODE=fixed), release points and counters.LockedHostRegion:mmap+MADV_ZERO_WIRED_PAGES+minherit(VM_INHERIT_NONE)+mlock. Release zeroes, unlocks and unmaps. If wiring fails, nothing is stored.MemoryOnlyPrefixCachePolicy: the switch and budget.SSDHybridCheckpointStoreforwards memory-only receipts to itsmemoryOnlyTier(takeStaged,donate,completeStaging,abandonStaging, close).acceptsCheckpointis unchanged, so ordinary captures are exactly as before.memory, with no chain anchors.GlobalKVCacheBudget.memoryOnlyPool(.sharedin production), so both servers and the ledger use one pool and tests use private ones.MemoryOnlyPrefixCachePolicy.attachesTier). It is not attached to GLM-5.3-Flash, DiffusionGemma, native MiMo, Nemotron Super (its builder passesallowsMemoryOnlyTier: false), pairs, or a slot built withDARKBLOOM_PREFIX_CACHE_MEMORY=1.min(8 GiB, fleet KV headroom / 4), off below 1 GiB, recomputed at each load and unload.reserveHostBuffers) and needs a whole budget of ledger headroom beside it.duplicate), so underDARKBLOOM_SSD_KV_TTL_MODE=fixedan entry still expires 30 minutes after its first store.DARKBLOOM_PREFIX_CACHE_MEMORY=1resident tiers, which have no TTL, marked requests run with the prefix cache off. They skip the prompt-token piece cache as in Provider: a memory_only cache policy per request, and SSD cache records without token IDs #2575.PromptPieceTokenStoredrops a piece unused forDARKBLOOM_TTFT_PROMPT_CACHE_TTL_SECONDS(default 1800, lower only).0restores the earlier behaviour, where a piece stayed until displaced, the model unloaded or the process exited. That is the kill switch.docs/architecture/prefix-cache.md).docs/reference/configuration.md):DARKBLOOM_ZDR_PREFIX_CACHE_RAM=auto|off, defaultauto. The tier holds nothing until a marked request donates, and the coordinator's marking is off by default; that marking is the real gate.offis the kill switch.DARKBLOOM_ZDR_PREFIX_CACHE_RAM_MAX_MBreplaces the cap.darkbloom_zdr_prefix_ram_*on local/metrics(lookups, hit tokens, stores by outcome includingduplicateandrefused_busy, evictions by reason includingsleepandshortfall, bytes, entries, budget). Counts only.Sizing (one model resident, default 4 GiB reserve; from
UnifiedMemoryCap.kvBudgetBytes)"—" means the model doesn't load at that size, or the budget is under 1 GiB. 8 GiB holds about 42 / 22 / 30 / 22 native-layout checkpoints of an 8,192-token prefix.
What is and isn't wired
The tier's retained bytes are wired (
mlock): every payload segment and the manifest, which carries the prefix token IDs and the scope. The heap holds only HMAC tags, sizes and times.Data of a request in flight is ordinary process memory, as for every request today. That covers:
Under heavy pressure macOS could page it to its swap file, which is always encrypted with a key that is never stored, and a Mac that hibernates writes it to its sleep image. Wiring the KV pool is a possible later step.
One documented exception, and a proposal
The operator opt-in
DARKBLOOM_PREFIX_CACHE_MEMORY=1(off by default, forwarded by the LaunchAgent) enables the engine-resident tiers: paged resident blocks and the recurrent bank, and Nemotron Super's bank instead of its SSD checkpoints. Those tiers have no TTL and no API to clear them.memory_onlyrequests never use them: on such a slot they run with the prefix cache off.Proposal, not implemented here: release builds ignore
DARKBLOOM_PREFIX_CACHE_MEMORYand fail closed to the SSD and RAM-only tiers, so the 30-minute bound holds on every provider. Debug and local qualification builds keep the opt-in. To be decided by the release owners at merge.Pairs and clusters
Unchanged from #2575: a pair serves a
memory_onlyrequest with its prefix cache off. A resident-only pair partition is a later step.Validation
provider-swift/Tests/ProviderCoreTests/KVCacheRAM/, plus 4 TTL cases inPromptTokenCacheTests):handleInferenceRequeston a realEngineV2with the paged backend: the secondmemory_onlyrequest reports 512 cached tokens from tiermemory, the SSD store writes, stages and keeps nothing, no SSD-tier evidence is sent, and an ordinary request after them gets nothing from RAM.devagain when it retargets there after Provider: a memory_only cache policy per request, and SSD cache records without token IDs #2575 lands.memory_onlybyte reaches a file or an SSD read, write, index, epoch or evidence path; every retained byte is wired and zeroed on release; a wiring failure stores nothing; ordinary and marked traffic are separated both ways. Its findings are fixed here: Nemotron Super excluded, close joins restores, the covered-charge release and retry, budget 0 not offered, duplicates, release before sleep, the load release with rollbacks set, private pools in tests, and the added test cases.