MemKV
Internals

Storage Internals

How MemKV stores blocks on NVMe, keeps drive sets consistent, and frees space.

Extent-based storage

MemKV splits large context blocks across several NVMe drives so it can read and write them in parallel. Two settings control the split:

  • storage.block_size is the extent size: the unit of space MemKV allocates on a drive. Default 4 MiB. An allocation larger than one extent is striped across drives; a smaller one fits in a single extent. Use a smaller size for many small objects and a larger size for sustained bulk transfers.
  • memory.block_size is the chunk size of the bounce buffers that stage RDMA transfers. Default 2 MiB. Each RDMA READ or WRITE moves one chunk; a transfer that spans several extents flows through many chunks in a pipeline.

The two settings are independent. At the defaults, two 2 MiB chunks fill one 4 MiB extent.

Versioning

MemKV releases are named by date (RELEASE.<commit-date>). Every record carries a version field: the wire-protocol header, the device superblock, the journal header, the B+Tree index header, and the embedded failure registry. Each on-drive decoder accepts only the exact version its build writes. The current on-drive layout is final: later releases extend it with feature flags instead of a new version. A release that finds a feature it does not support refuses the drive and leaves it untouched; it never resets it. The wire protocol is stable in the same way: a server serves clients (the inference plugins and the admin client) from its own release and any earlier one, starting with RELEASE.2026-11-20T23-40-14Z.

What this means when you upgrade:

  • Upgrade servers first, then clients. A newer server accepts requests from older clients. A client newer than its server is not supported.

Drive sets

The drives of one server form a set of at most 64 drives. Each drive records its set and its position in storage.drives.

  • Keep the drive order. MemKV refuses to start, and leaves the drives untouched, if a drive is listed at a different position, comes from another set, or the number of drives changed. NVMe names can change between reboots, so list drives by a stable path such as /dev/disk/by-id/….
  • Replace a blank drive with memkv drive reset <drive> --peer <drive> --position <n>. The new drive takes its set from the peer. If the old drive had failed, then run memkv admin drives reset <position> with the server running. A position that reached storage.flap_threshold failures is blacklisted and cannot be reset, even with a new drive; returning it to service means reformatting every drive with memkv setup --force, which erases the set.
  • Reset a failed drive while the server runs with memkv admin drives reset <position>. The reset clears only that drive. Blocks stored entirely on the other drives stay readable by key; a block with a chunk on the reset drive is lost.

See drive reset for the commands.

Capacity reclaim

MemKV holds a cache, so it frees space on its own instead of filling the drives and refusing writes. When storage use passes storage.eviction.high_watermark (70% by default), a background worker evicts the least recently used blocks until use drops below low_watermark (60%). The freed space goes through the same batched TRIM path as an explicit delete.

MemKV refuses a write of a new key when it would bring storage use to 95% of usable capacity. So high_watermark must be below 95, or the server refuses to start.

When the journal is full, a write waits up to 10 seconds for space instead of failing at once. memkv_journal_space_waits_total counts these waits.

This matters most for engines that never delete. SGLang's storage-backend interface has no per-key delete, because it expects each backend to manage its own retention. Without reclaim on the server, a HiCache deployment would fill its drives once and then fail every later write.

Set storage.eviction.enabled: false only when the client manages retention and you prefer failed writes to losing a cached block. See Configuration for these settings.

Block deletion and TRIM

A DELETE marks blocks as free in the in-memory index and queues a TRIM request to a background worker. The worker merges adjacent ranges and sends NVMe TRIM (BLKDISCARD) commands every 5 seconds, or sooner when the batch reaches 1,024 extents. Batching keeps TRIM latency off the request path, and the TRIM commands let the SSD controller run garbage collection so write performance stays high.