Valkey with more data than RAM

What happens to a Redis-compatible cache when its data does not fit in memory, and the kernel compresses the overflow (zram, zswap) or pages it to SSD (disk swap)? Valkey 9.2 with 40 GB and 64 GB of data on a 32 GB server, lz4 and zstd at several levels, six workloads, measured with kvbench.

Archived report (v1). Measured 2026-11-23 to 25 on a Vultr bare-metal Intel Xeon E-2286G (6 cores, 32 GB RAM, SATA SSD) with the first benchmark protocol (one 2-minute window per point, all points in a fixed order after one load, single-threaded Valkey). Kept for reference; see the current report for the rerun on newer hardware with the revised protocol.
AI-generated results. This benchmark was designed, run and analyzed with an AI assistant (Claude). Results were spot-checked by a person, but not every number and explanation has been verified in detail, and they may contain mistakes. All code and raw data are published on GitHub; please open an issue if you find a problem.

Key findings

Explore the results

The zswap shrinker

zswap is a compressed cache in front of a normal swap device. Pages the kernel swaps out are compressed into a RAM pool instead of being written to disk, and read back from the pool without any disk I/O. Pages leave the pool for the disk only by writeback.

Shrinker off (shrinker_enabled=N): writeback happens only when the pool reaches max_pool_percent of RAM. Until then everything stays compressed in RAM and zswap behaves like zram.

Shrinker on (Y, the default on this kernel): the pool takes part in memory reclaim like other caches. Whenever memory is tight, zswap writes its coldest compressed pages to disk, even with the pool far below its limit. That helps when swapped-out memory is really idle. In a cache the "cold" pages are still read, and memory stays tight as long as the data exceeds RAM, so those pages become disk reads in Valkey's single thread.

For caches whose data exceeds RAM: use zram, or set zswap.shrinker_enabled=0.

64 GB of data, uniform access: throughput at full load

Same compressor, shrinker on (kernel default) vs off

Client-side compression instead of kernel compression

The application compresses each value before SET and decompresses it after GET (kvbench --client-compress); Valkey stores the compressed bytes. Disk swap was enabled only as overflow and was never used: the compressed data fits in RAM.

Where the memory is

Valkey's memory at the end of the uniform full-load run: how much stays resident (uncompressed) and how much is swapped out, with the compression ratio the kernel achieved on Valkey's real pages (bare values compress 3.8x with lz4 and 7.3x with zstd 3).

Fixed vs variable value sizes

Values uniformly distributed between 0 and 2000 bytes (mean ~1006 B) instead of a fixed 1024 B. The same 30M keys take 14% less memory (jemalloc stores a 1 KiB value plus header in a 1280-byte slot); with 35M keys the variable data set matches the fixed one's memory. Throughput in ops/s with page faults per operation.

Kvrocks, Lavik and TidesKV

The same data sets on stores that keep data on SSD and use RAM as a cache, on the same 6 server CPUs as Valkey: Kvrocks 2.17 (RocksDB) with its shipped configuration (snappy) and with lz4 or zstd, Lavik 0.3.2 (values on SSD, key index in RAM), and TidesKV 0.1.0 (TidesDB) with lz4 or zstd.

Non-default store settings: Kvrocks starts from its shipped kvrocks.conf with only bind/port/dir and workers 6 changed (variants change rocksdb.compression); TidesKV defaults with bind/port/dir, workers 6 and sync-mode none (zstd variant: compression zstd); Lavik defaults with --threads 6, --pin-workers on the server CPUs and a 300 GB data file. Kvrocks and Lavik 40 GB results are from a rerun: the first run overlapped other work on the benchmark host.

How it was measured

Settings that are not defaults

ComponentSetting
Valkey 9.2.0--save "", --appendonly no, --protected-mode no (loopback only); everything else default
Hostvm.overcommit_memory=1, turbo off, performance governor, conntrack skipped for loopback
Disk swapswap file on the second SSD (64 GB; 96 GB for the 64 GB data set), swappiness 60
zramone device (64 / 96 GB), no disk swap, swappiness 180, page-cluster 0, watermark_boost_factor 0, watermark_scale_factor 125; zstd level via algorithm_params (default 3)
zswapzsmalloc, max_pool_percent 50, same swap file as disk swap, swappiness 100, same three sysctls as zram; shrinker_enabled kernel default Y unless marked "shrinker off"