ZICQ
中 Log in / Sign up
Newsroom Compute & Architecture #SGLang #Unified GPU Memory #KV Cache #Hybrid Attention #GPU Memory Management

SGLang Unifies KV Cache and Recurrent State in One GPU Memory Arena

Avatar of Mr.Xu

By Mr.Xu Compiled & Reviewed by Editorial

Published:

中文阅读 (Chinese) English Version
Co-reading Select any sentence in the article to highlight, annotate, or copy a quote card. Join discussion ↓

Summary:SGLang introduces `--enable-unified-memory` to place full-attention KV cache, sliding-window KV, and recurrent state in a single GPU-memory arena. Rather than enforcing hard runtime partitions among state types, the allocator lets demand determine how shared capacity is distributed while preserving each pool's native page or slot geometry. The central layout change packs each token's rows across layers into one entry. This allows target and speculative-draft KV to share allocation and lifetime,


SGLang's Unified Memory is not CUDA-style unified virtual memory across CPUs and GPUs, nor does it offload the KV cache to host memory. It establishes a single allocator inside GPU memory so that inference states with different lifetimes can share the same capacity budget. The update primarily addresses memory-allocation mismatch in hybrid-attention models rather than changing model algorithms.

From static pools to one GPU arena

SGLang traditionally places three state types in separate sub-pools. Full-attention KV cache retains the complete context, sliding-window KV cache keeps only a bounded suffix, and recurrent state stores fixed-size convolutional and temporal state for each running request. --swa-full-tokens-ratio and --mamba-full-memory-ratio determine their proportions at startup, and a pool cannot borrow idle capacity from another pool at runtime.

For conventional multi-head KV caches, first-order memory consumption can be approximated as follows:

  • Full attention: M_full ≈ 2 × L_full × H_kv × d_head × S × b
  • Sliding-window attention: M_swa ≈ 2 × L_swa × H_kv × d_head × W × b
  • Recurrent state: M_state ≈ N_req × Σ(size(conv_l) + size(temporal_l))

Here, L is the layer count, H_kv the number of KV heads, S the context length, W the window size, N_req the number of concurrent requests, and b the bytes per element. MLA, DSA, and mixed-dtype state require exact tensor-level accounting, but the allocation problem remains: long contexts continuously expand full-attention KV, while many short requests mainly consume window pages and recurrent-state slots.

Unified Memory removes these runtime hard partitions and turns total capacity into a joint budget. The ratio flags remain boot-sizing targets rather than walls. Model weights, operator workspaces, and communication buffers are not automatically included in this state arena.

One entry per token

Instead of maintaining one buffer per layer, the new layout packs a token's rows across relevant layers into a logical entry. A page is a run of entries, and each layer accesses its own data by striding across those entries. This produces three immediate benefits:

  1. Cross-layer KV for a token can be allocated, reclaimed, and relocated as one unit rather than through per-layer lifecycles.
  2. Target and speculative-draft models can share a token ID and primary allocation. Draft rows may occupy additional lanes in the same entry even when their sizes or dtypes differ.
  3. A DSA layer's top-k index can sit beside the MLA KV it references, preventing the index and KV from being reclaimed or relocated independently.

Recurrent state uses a different geometry. Each state slot contains the convolutional and temporal state for all state layers, but it remains an independently allocated slot rather than being forced into ordinary KV pages. Mixing shapes and dtypes inside an entry also means address generation, metadata, and backend kernels must correctly track each row group's offset and extent.

One arena, different geometries

The underlying arena is a byte-addressed region, not a uniform array of identically sized pages. Full-attention KV grows downward from the high-address end, while sliding-window KV and recurrent state grow upward from the low end. Floating state bands between them can move to open a reusable gap.

When capacity is released, lazy compaction relocates live objects toward the two ends and leaves a central region available to any state type. The project's zero-fragmentation claim primarily means that bytes are not stranded by fixed ownership; it does not eliminate data movement, alignment constraints, or allocator metadata. --page-size controls Token-page granularity: larger pages reduce metadata and migration frequency but may waste more space on short requests, while smaller pages improve reuse at the cost of more management overhead.

Admission, scheduling, and in-flight safety

A shared demand model drives decisions from request admission through decode-side preallocation in prefill–decode disaggregation. Recurrent state is normally reserved when a request starts, while full-attention KV keeps growing, so the scheduler must determine whether a complete request can fit and reorganize capacity as pressure changes.

Page reclamation cannot rely solely on logical reference counts. GPU kernels may still read KV that has been evicted or relocated, so the lifecycle manager must wait until in-flight work is complete before reusing addresses and must update target, draft, and per-layer views consistently. SGLang describes this as a scheduler-aware page lifecycle, but the available material does not disclose whether it uses stream events, read-write counters, or another synchronization mechanism.

The design currently works with overlap scheduling, Radix Cache, HiCache, prefill–decode disaggregation, speculative decoding, pipeline parallelism, decode context parallelism, and data-parallel attention. HiCache remains an external cache tier; unified memory governs GPU-side capacity sharing among state types.

Engineering trade-offs and measured performance

Principal benefits:

  • Higher GPU-memory utilization for hybrid models under long contexts, high concurrency, and shifting demand patterns.
  • Less need to guess fixed sub-pool ratios before deployment.
  • Simpler lifecycle management for cross-layer KV, speculative drafts, and DSA indices.

Engineering costs:

  • Compaction may copy large live KV blocks, consume HBM bandwidth, and compete with decoding, potentially increasing tail latency.
  • A shared arena weakens isolation between pools. A large request can consume capacity needed by others unless admission, preemption, or eviction protects tenants and requests.
  • Mixed shapes, mixed dtypes, and several allocation geometries increase address-mapping, metadata, and state-machine complexity.
  • Unified capacity does not eliminate OOM. Total KV, recurrent state, model weights, and workspaces must still fit in GPU memory, and transient peaks still require scheduling decisions.
  • The design is closely coupled to GPU kernels and memory-management backends, so equivalent performance should not be assumed on other accelerators.

The available public material does not include same-system A/B results against the default allocator. It reports no memory-utilization gain, throughput, TTFT, TPOT, p95 or p99 latency, compaction volume, or speculative acceptance rate. The fixed-partition removal, zero-fragmentation design, and compatibility list therefore establish the direction of the work but do not yet quantify its production benefit.

Deployment recommendations

  1. Confirm that the selected SGLang branch contains --enable-unified-memory, then validate it against the intended GPU, CUDA, and driver combination.
  2. Compare the default fixed-pool path with unified memory using identical models, input and output lengths, batch sizes, cache state, and warm-up procedure. Tune the fixed-pool baseline before using it as a control.
  3. Test long contexts, high-concurrency short requests, rapidly growing histories, hybrid-state migration, speculative decoding, and prefill–decode disaggregation independently; one traffic mix can conceal contention.
  4. Sweep the supported --page-size values and record effective memory, relocation volume, allocator overhead, TTFT, TPOT, throughput, and tail latency.
  5. Monitor admission failures, preemptions, evictions, Radix Cache hit rate, speculative acceptance rate, and GPU memory pressure. Add tenant isolation or concurrency controls where shared-arena interference is possible.
  6. Roll out the feature gradually behind a disable switch. If compaction jitter or tail-latency regression appears on a particular model, fall back to fixed sub-pool allocation.

Source: LMSYS / SGLang Blog (2026-11-11)

— END —

Tags: #SGLang #Unified GPU Memory #KV Cache #Hybrid Attention #GPU Memory Management

Editorial & Fact-Checking Note: This article is compiled from primary research, official release documentation, and source papers by the ZICQ Newsroom pipeline with automated entity verification and human editorial review. If you notice any technical inaccuracy, please submit a correction via our corrections policy or email our editorial desk directly.

What's your take on this story?
Explore & Submit Works

Community Comments

Loading live comments and annotations…