KV Cache Paging

KV Cache Paging is a memory management technique for Large Language Model (LLM) inference that treats Key-Value (KV) cache blocks as discrete pages. By decoupling logical token sequences from physical GPU memory allocation, it enables non-contiguous storage of KV states, significantly reducing memory fragmentation and improving throughput for variable-length generation workloads.

Core Mechanism

  • Block-based Allocation: Instead of allocating fixed-size buffers for maximum context length per request, the system divides KV cache into smaller blocks (pages).
  • Non-contiguous Storage: As tokens are generated, new blocks are allocated from a global pool regardless of their physical proximity to previous blocks.
  • VRAM Optimization: This approach addresses the critical challenge of efficiently serving LLMs at scale by maximizing GPU memory utilization, preventing waste from over-provisioning for worst-case context lengths.

Implementation & Impact

References