KVSwap: Disk-aware KV Cache Offloading for Long-Context On-device Inference

Huawei Zhang, Chunwei Xia, Zheng Wang

TL;DR

KVSwap is a new software framework that enables long-context LLM inference on memory-constrained mobile and embedded devices by offloading the Key-Value (KV) cache to disk. By using a compact in-memory "summary" to predict and prefetch only the most critical cache entries in hardware-friendly groups, KVSwap achieves up to 4.1x higher throughput than existing methods while maintaining high generation quality under tight memory budgets.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly used for long-context tasks like document summarization and video analysis. However, running these models locally on devices like smartphones or Jetson modules hits a "memory capacity wall."

The culprit is the KV cache—the memory used to store past token representations so the model doesn't have to recompute them. Unlike model weights, which are fixed, the KV cache grows linearly with sequence length and batch size. For a 4B-parameter model at a 16K token context, the KV cache can exceed 9GB, quickly surpassing the 8–32GB of shared RAM typically found on mobile SoCs.

Existing solutions often offload the cache from GPU to CPU memory, but this is ineffective on mobile devices where the GPU and CPU share the same physical RAM. Offloading to secondary storage (disk/NAND flash) is a natural alternative, but it faces two massive hurdles:

  1. Low Bandwidth: Mobile storage (NVMe/eMMC) is 100x slower than RAM.
  2. Read Amplification: Disks read data in large blocks. Requesting a single "important" token's KV entry often forces the hardware to read an entire 4KB page, wasting massive amounts of I/O bandwidth.

Methods

KVSwap introduces a "disk-aware" approach to cache management through several novel techniques:

  • Compressed K Cache: Instead of keeping the full Key (K) cache in memory, KVSwap maintains a highly compressed, low-rank version (using SVD-based approximation). This "summary" is used only to predict which tokens are important for the current attention step, not for the actual math.
  • Grouped Critical KV Prediction: To solve read amplification, KVSwap doesn't fetch individual tokens. Instead, it groups $G$ consecutive tokens together. If the predictor identifies a group as important, the entire block is prefetched. This aligns with the physical block-read characteristics of NVMe and eMMC.
  • KV Reuse Buffer: The authors observed that "important" tokens tend to stay important across several decoding steps (temporal locality). KVSwap keeps recently accessed groups in a small memory buffer to avoid redundant disk reads.
  • Rolling Buffer: New tokens are stored in a small in-memory rolling buffer until they form a complete group, at which point they are flushed to disk.
  • Greedy Parameter Solver: Since optimal settings (group size, compression ratio) vary by hardware and model, KVSwap includes an offline tuner that profiles the device and finds the best configuration to hide I/O latency behind computation.

Datasets

The authors evaluated KVSwap across a diverse range of models and tasks:

  • Models: LLaMA-3.1-8B, LLaMA-3.2-3B, Qwen3 (4B, 8B, 14B), and Qwen2.5-VL (for video).
  • Text Benchmarks: LongBench (multitask long-context), Needle-in-a-Haystack (NIAH) (retrieval), and RULER (complex long-context reasoning).
  • Video Benchmarks: MLVU (Multi-task Long Video Understanding), focusing on sub-scene captioning and video summarization with contexts up to 32K tokens.
  • Calibration: The C4 dataset was used for the offline precomputation of the low-rank adapters.

Key Insights and Ideas

  • Selection vs. Computation: The "aha moment" here is that you don't need high-precision data to decide what to read from disk. A lossy, low-rank "map" of the keys is sufficient to identify the attention "heavy hitters," allowing the system to keep the metadata footprint tiny.
  • Embracing Hardware Constraints: Most offloading papers treat the disk as a slow RAM. KVSwap treats it as a block device. By intentionally reading "extra" neighboring tokens (grouping), they actually increase effective throughput because they stop fighting the disk controller's internal logic.
  • I/O-Compute Overlap: By predicting the needs of Layer $N+1$ while Layer $N$ is still calculating, KVSwap effectively hides the slow disk latency, making the "disk wall" feel much thinner.

Key Results

  • Throughput: On an NVIDIA Jetson Orin AGX, KVSwap delivered up to 1.8x (NVMe) and 4.1x (eMMC) higher throughput compared to the strongest baselines (like ShadowKV or InfiniGen) at 32K context lengths.
  • Memory Efficiency: KVSwap achieved comparable or better throughput than the industry-standard vLLM while using 11x less KV cache memory.
  • Quality Preservation: Despite aggressive offloading and compression, KVSwap maintained generation quality with minimal accuracy loss (typically <5%), whereas baselines often saw accuracy collapse (45%+ loss) under the same tight memory budgets.
  • Scalability: Unlike other methods that spike in latency as the context grows, KVSwap’s throughput remains stable because the number of "selected" entries remains constant regardless of total sequence length.

Limitations and Future Work

  • Offline Tuning: While the offline tuning takes less than 30 minutes, it is still a required step for every new model/hardware combination.
  • Accuracy Trade-offs: Under extremely tight budgets (e.g., 1/34th of the full cache), there is still a measurable drop in reasoning capability, though it remains "usable" compared to competitors.
  • Prefilling: The current work focuses primarily on the decoding stage (generating tokens). While the authors suggest KVSwap can extend to the prefilling stage (processing the initial prompt), detailed optimizations for that phase are left for future work.
  • Write Latency: While read latency is hidden, the impact of continuous writes (saving new KV entries to disk) on long-term NAND endurance and performance consistency wasn't deeply explored.

Summary updated

BibTeX
@inproceedings{zhang2026kvswap,
  author = {Huawei Zhang and Chunwei Xia and Zheng Wang},
  title = {{KVSwap: Disk-aware KV Cache Offloading for Long-Context On-device Inference}},
  booktitle = {MobiSys},
  year = {2026},
  doi = {10.1145/3745756.3809234},
}
Figure