Redis VM/Swap (Legacy)

Difficulty: Advanced

Question

Did Redis ever support keeping part of its dataset on disk when it did not fit in RAM? What happened to that feature, and what are the options today?

Answer

Yes. Redis 2.0 shipped an optional Virtual Memory (VM) feature that moved rarely used values to a swap file on disk and kept only keys and hot values in RAM. It was deprecated in Redis 2.4 and removed in 2.6, because it made latency unpredictable and complicated the code, while RAM was getting cheaper. Since then, open-source Redis requires the whole dataset to fit in memory; disk is used only for persistence.

How the old VM worked

  • Keys always stayed in memory; values that had not been accessed for a while could be swapped out to a file, page by page.
  • Reading a swapped value required loading it back from disk, which was handled by I/O threads so the main thread could keep serving other clients.
  • Configuration lived in options like vm-enabled, vm-max-memory and vm-swap-file.

Why it was dropped

  • Unpredictable latency. A command could take microseconds or many milliseconds depending on whether its value was on disk. Redis's main promise is consistently low latency.
  • Slow restarts and saves. Snapshots had to read swapped values back from disk.
  • Complexity. Threaded I/O and blocking clients waiting for values added a lot of code for a niche benefit.
  • Better alternatives. For data larger than RAM, a disk-based database or sharding across several Redis nodes worked better.

An experimental successor called diskstore was also abandoned for similar reasons.

Persistence is not disk storage

It is a common confusion in interviews. RDB snapshots and the AOF write Redis data to disk, but only to rebuild memory after a restart. Reads are always served from RAM. If the dataset grows beyond RAM, Redis either evicts keys (with a maxmemory-policy other than noeviction) or rejects writes with an OOM error.

OS swapping is a failure mode, not a feature

If maxmemory is not set and the machine runs low on RAM, Linux may swap Redis's own memory pages to disk. Every access to a swapped page then causes a disk read on the single main thread, and latency collapses for every client. Signs include mem_fragmentation_ratio below 1.0 and high swap usage in /proc/<pid>/smaps. Set maxmemory with headroom and monitor RSS.

Options today when data exceeds RAM

ApproachNotes
Shard with Redis ClusterSpread data across nodes so each fits in RAM
Evict cold dataUse Redis as a cache with LRU/LFU and keep the source of truth in a database
Commercial tieringRedis Enterprise / Redis Cloud offer RAM plus flash tiering (marketed as Auto Tiering, now Redis Flex)
Disk-based Redis-compatible storesApache Kvrocks (RocksDB backed) speaks the Redis protocol with data on SSD

Each option trades something: cost, latency on cold reads, or full command compatibility.

Disk usage in Redis 2.0 VM vs modern Redis. Modern Redis uses disk only to rebuild memory, never to serve reads.
Redis 2.0 with VMRedis today
Where reads are servedRAM or swap fileRAM only
Dataset larger than RAMCold values swapped outEvict, reject writes, or shard
LatencyUnpredictable on cold valuesConsistently low
Role of diskStorage and persistencePersistence only (RDB, AOF)

Key points

  • Redis 2.0 had an optional Virtual Memory feature that swapped cold values to disk
  • It was deprecated in 2.4 and removed in 2.6
  • Open-source Redis today serves all reads from RAM; RDB and AOF are only for recovery
  • OS swapping of Redis memory destroys latency; set maxmemory with headroom
  • For larger-than-RAM data, shard, evict, or use tiered or disk-based alternatives

Common follow-up questions

  • What happens when Redis reaches maxmemory with the noeviction policy?
  • How would you detect that Redis is being swapped by the OS?
  • How does Redis Cluster help when a dataset outgrows one machine?
  • When would you choose a disk-backed Redis-compatible store?

Interview tips

  • Get the version history right (2.0 added, 2.4 deprecated, 2.6 removed) and explain why
  • Clarify the difference between persistence and disk-based storage
  • Mention OS swap as a real production risk; it shows practical experience

Concepts covered

Redis Virtual Memory, In-memory design, OS swap, Tiered storage, Persistence vs storage

More Redis & Caching questions