Run in production

Configure DRAM, NVMe and S3 tiers

DRAM is always on. NVMe keeps blocks across restarts and holds far more. S3 adds a cold tier behind NVMe. Each lower tier is off until you set its first key.

Last updated

How the tiers fit

TierTurned on byHoldsSurvives a daemon restart
DRAMalways on (dram_arena_bytes)The hot prefix setNo
NVMenvme_paths + nvme_max_bytesThe warm tail, terabytes per nodeYes, rebuilt from the volume
S3s3_bucket + s3_region + s3_node_id, needs exactly one NVMe volumeCold segments behind NVMeNo: a spill target, not a backup

Blocks flow down under memory pressure and come back up when they are read again. Engines see one store; they never address a tier.

DRAM tier

The arena is one block of memory reserved at startup, outside the daemon's garbage-collected heap. Size it to the blocks you want served at memory speed; the daemon's own memory beyond the arena is small.

config.yaml
dram_arena_bytes: 17179869184   # 16 GiB
dram_hugepages: true
eviction_policy: "s3fifo"        # s3fifo | sampled-lru | none
eviction_watermark_pct: 95       # start freeing at 95% full
eviction_batch_pct: 5            # free down to 90%

Hugepages

Recommended above about 8 GiB. Reserve the pages on the host first. If they are not available, the daemon falls back to normal pages and logs a warning, so check the startup line arena ready bytes=... hugepages=true. The arena is pre-faulted at startup, so the first requests do not pay for page faults; the same line reports how long that took.

Shell
# reserve 2 MiB pages BEFORE starting the daemon: pages x 2 MiB = arena
echo 8192 | sudo tee /proc/sys/vm/nr_hugepages      # 16 GiB
# keep it across reboots
echo "vm.nr_hugepages = 8192" | sudo tee /etc/sysctl.d/90-kvblockd-hugepages.conf

Eviction

s3fifo keeps blocks that are read more than once ahead of blocks read once, which suits shared system prompts and documents. sampled-lru is the classic alternative. none turns eviction off: a full arena then refuses new writes with ERR_QUOTA_BYTES. With an NVMe tier, blocks are demoted to flash in the background as DRAM fills; see leave room for write bursts.

NVMe tier

Give each physical device its own filesystem and one directory. XFS is what our rigs use.

Shell
# one filesystem per physical device
sudo mkfs.xfs -f /dev/nvme1n1
sudo mkdir -p /mnt/nvme1/kvb
sudo mount -o noatime /dev/nvme1n1 /mnt/nvme1/kvb
sudo chown kvblockd:kvblockd /mnt/nvme1/kvb
config.yaml
nvme_paths: ["/mnt/nvme1/kvb", "/mnt/nvme2/kvb"]   # one per device; append only
nvme_max_bytes: 3400000000000      # required: total budget across all volumes (3.4 TB)
nvme_demote_watermark_pct: 90      # demote from DRAM at 90% full (below the eviction mark)
nvme_demote_batch_pct: 5           # each pass demotes down to 85%
nvme_admit_min_hits: 0             # write every DRAM victim to flash: right behind an engine cache
nvme_promote_window_ms: 60000      # a 2nd NVMe hit within 60 s moves the block back to DRAM
  • Order is ownership. Append new volumes to nvme_paths; do not reorder or remove entries between restarts.
  • Set nvme_admit_min_hits: 0 behind vLLM or SGLang. The default of 1 drops blocks that were never read while in DRAM instead of writing them to flash. Behind an engine cache that is most blocks, because the engine serves short-range reuse itself and a block's next use comes after it has left DRAM; in our trace simulations the default kept between 34% and 99% of what the NVMe tier could save, and 0 kept 92% to 100%. The cost is flash writes: every DRAM victim is written once. Watch kvb_nvme_admit_refusals_total (should stay near 0) and your drives' write rate.
  • Direct I/O. Writes go to append-only 256 MiB segments with O_DIRECT, 4 KiB aligned. On filesystems that refuse direct I/O, such as tmpfs or overlay, the daemon falls back to buffered I/O and logs it; use that for tests only.
  • Busy devices answer, they do not hang. Each volume has a pool of read workers (nvme_read_workers, 16). When it is saturated, the extra keys answer ERR_BUSY, which engines treat as a miss; kvb_nvme_read_busy_total counts them.
  • Leave room for write bursts. Demotion starts at nvme_demote_watermark_pct (90%) and eviction at eviction_watermark_pct (95%). Writes that cross that gap faster than demotion moves blocks to flash are evicted without ever reaching it; kvb_nvme_dram_only_evictions_total counts them (0.2.3 and later; before that they are only in kvb_evictions_total{tier="dram"}). For bursty writers, start demoting earlier and further: in our test with a 256 MiB arena, nvme_admit_min_hits: 0 and 64 MiB write waves at about 58 MiB/s, the defaults lost about 22% of the blocks and nvme_demote_watermark_pct: 60 with nvme_demote_batch_pct: 20 lost none. A sustained stream faster than the drives still evicts.
  • systemd: add each volume directory to ReadWritePaths in the unit.
  • Several volumes or S3, not both. The S3 tier works with exactly one NVMe volume; the daemon refuses s3_bucket with more than one entry in nvme_paths.

S3 tier

Every sealed 256 MiB NVMe segment is copied to S3 as one object in the background, while reads keep coming from NVMe. When NVMe space is reclaimed, the blocks in that segment become S3-resident; a later read fetches just that block with one ranged GET and verifies its checksum before returning it. Repeated cold reads bring the whole segment back to NVMe.

config.yaml
nvme_paths: ["/mnt/nvme1/kvb"]     # the S3 tier needs exactly one NVMe volume
s3_bucket: "my-kv-cold"            # turns the tier on; an unversioned bucket
s3_region: "us-east-1"             # always required; AWS_REGION is not read (any name for MinIO etc.)
s3_node_id: "node-a"               # required: unique per daemon, stable across restarts; A-Z a-z 0-9 . _ -
# s3_endpoint_override: "http://minio:9000"   # S3-compatible stores
# s3_path_style: true                         # usually needed with the override
s3_spill_queue: 8                  # background uploads in flight
s3_read_timeout_ms: 2000           # a slower cold read answers as a miss

Credentials

The daemon takes AWS credentials only from its environment: environment variables, the shared config file, or the instance or pod role. They never go in the kvblockd config file. The bucket must be unversioned (never had versioning enabled): the daemon checks at startup. The policy needs three actions on the objects and two on the bucket, which the daemon calls at startup to check versioning and take its inventory:

IAM policy
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"],
      "Resource": "arn:aws:s3:::my-kv-cold/*"
    },
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket", "s3:GetBucketVersioning"],
      "Resource": "arn:aws:s3:::my-kv-cold"
    }
  ]
}

The lifecycle rule is required

The daemon deletes objects it no longer needs, but a restart, a failed delete or a busy cleanup pass each leave an object behind. They cost storage, never correctness. A bucket expiration rule removes them; without one, storage grows in normal operation. Start at 7 days and lengthen it if your blocks are reused over longer periods: an expired object that is still wanted is a cold miss.

lifecycle.json
{"Rules": [{"ID": "kvb-orphan-backstop", "Status": "Enabled",
            "Filter": {"Prefix": ""},
            "Expiration": {"Days": 7}}]}
Shell
aws s3api put-bucket-lifecycle-configuration \
  --bucket my-kv-cold --lifecycle-configuration file://lifecycle.json

Watch the kvb_s3_ metrics: spills, restores and hits, plus kvb_s3_put_errors_total, kvb_s3_read_errors_total and kvb_s3_spill_drops_total. A dropped spill leaves the segment on NVMe and is retried.

Restarts and failures

  • Daemon restart

    DRAM blocks are gone. NVMe blocks come back from checkpoints and segment footers. Blocks that were S3-resident are misses after the restart, and every sealed segment is uploaded once more under the same key.

  • Crash (kill -9)

    Every acknowledged block on NVMe is recovered byte for byte or reported missing; nothing damaged is served.

  • NVMe device lost

    That device's blocks are misses. Replace the device, keep the order of nvme_paths, restart. The old objects in S3 expire through the lifecycle rule.

  • Node replaced

    Give the new daemon a new s3_node_id. Reuse an id only for the same daemon continuing; two daemons with one id overwrite each other's objects.

  • S3 slow or down

    Cold reads answer as misses after s3_read_timeout_ms; uploads queue up to s3_spill_queue and then wait locally.

A full three-tier config

A shared cache node with 64 GiB of hugepage DRAM, two NVMe devices and an S3 bucket.

/etc/kvblockd/config.yaml
listen_addr: "10.0.0.5:9440"
metrics_addr: "10.0.0.5:9442"
namespaces_path: "/etc/kvblockd/namespaces.yaml"

# hot
dram_arena_bytes: 68719476736      # 64 GiB
dram_hugepages: true

# warm: one volume, because the S3 tier below needs exactly one
nvme_paths: ["/mnt/nvme1/kvb"]
nvme_max_bytes: 1700000000000

# cold
s3_bucket: "my-kv-cold"
s3_region: "us-east-1"
s3_node_id: "kv-node-a"

Every key and its default is on the configuration reference. For sizing, see sizing and network.

Something missing or wrong on this page? Email rudray@kvstash.com and it gets fixed.