Valkey 9.2 now takes RDB snapshots without fork(): how it prevents OOMs and what it costsArticle · digest for November 24
Conceptual 3D illustration of Valkey 9.2 memory architecture showing continuous forkless RDB snapshot streaming in a background thread with RAM overflow protection
Article4 sections≈ 8 min

Valkey 9.2 now takes RDB snapshots without fork(): how it prevents OOMs and what it costs

You trigger BGSAVE to dump a backup to disk, or you attach a fresh replica. From the outside, everything looks quiet: queries finish in sub-millisecond time and the app runs normally. Inside Linux, however, a frantic race for memory starts the very same second. If your service is writing heavily, the RAM graph climbs straight toward the ceiling. Then the Linux OOM killer steps in and silently terminates the most memory-hungry process. Your server crashes right in the middle of a backup.

In Valkey 9.2 (the stable release of the open-source Redis fork from November 19, 2026), this long-standing problem was fixed at the core. The database can now take RDB snapshots and send full syncs to replicas in a background thread without calling fork(). Let's look at how the new mode works under the hood, why it has a 512-byte threshold, and what you pay in exchange for stable memory.

Why good old fork() demanded double the RAM for years

Let's review the classic setup that Valkey inherited from Redis. When you take an RDB snapshot (a binary dump of the entire in-memory database at a specific moment), you need point-in-time consistency. Simply put, the file must contain every key exactly as it looked when BGSAVE started, with no mix of old and new values.

The traditional solution relied on Linux fork(). This system call creates a child process as a logical copy of the parent. Thanks to Copy-on-Write (CoW), the kernel doesn't duplicate gigabytes of RAM right away. Both processes point to the same physical memory pages: the child writes them to disk while the parent keeps serving clients.

The catch shows up under heavy writes. As soon as the main process changes a single byte on a shared page, the kernel copies the entire page so the child won't see the edit. A standard page is 4 KB, and with Transparent Huge Pages enabled it jumps to 2 MB. If the snapshot takes a while and the app keeps overwriting keys, the copied pages can easily match the size of the whole database. That's where the classic production rule came from: keep 50% of RAM free just for BGSAVE, or get hit by an OOM during peak hours. On top of that, fork() itself causes a noticeable pause on large instances while the kernel copies page tables.

How forkless snapshots work inside Valkey 9.2

In Valkey 9.2.0, the engine skips process cloning altogether. A background thread inside the same Valkey process builds the snapshot: no fork(), no page-table copying, and no CoW memory spikes. The mechanism handles both heavy tasks—background BGSAVE dumps and full replica syncs (PSYNC), whether via disk or directly over the network in diskless mode.

Keeping threads coordinated comes with a small fixed memory tax: the forkless infrastructure adds 4 bytes of metadata per key. Across one million keys, those 4 MB are barely noticeable. On a dense cache holding 100 million tiny entries, however, RAM usage grows by about 400 MB. That's tiny compared to the risk of doubling tens of gigabytes under CoW, but it's worth factoring into your capacity math.

The point-in-time consistency flow is straightforward. The main thread hands keys to the background thread for serialization. If a client writes to a key that has already been written to the RDB stream, the update goes through immediately. If the key is still waiting in line, Valkey has to preserve its old version first. From there, the path splits into two cases.

The 512-byte limit: small keys fly through, large keys wait

Picture a busy instance under heavy writes during a long BGSAVE. Two kinds of keys live in the database. The first is a simple string—a short session token or counter where the key name plus value totals a couple hundred bytes. The second is a hefty JSON profile cache, a large Hash, or a multi-kilobyte list that the service overwrites hundreds of times a second.

Isometric diagram of the forkless snapshot mechanism showing the fast copy pool for keys up to 512 bytes and blocking for larger data structures

Small strings sail right through. If a key is a string and the combined size of its name and value is 512 bytes or less, Valkey copies the old version into a reusable memory pool. The main thread updates the original and replies to the client right away, while the background thread serializes the copy and returns the block to the pool. That 512-byte limit is hardcoded and cannot be changed in config.

Large keys don't get to use the pool. If a string exceeds 512 bytes, or if you're storing a Hash, List, or Sorted Set, the conflicting write command blocks until the background thread finishes serializing the old version of that key.

This is where the trade-off shifts. RAM no longer doubles, and your RSS graph stays flat. Instead, the cost moves to write latency—specifically the p99 tail. If heavy updates hit large keys during BGSAVE, clients will see stalls where everything used to feel instant.

Two production gotchas in the new mode

First: large hot keys. If your database holds heavy JSON strings, big hashes, or lists under constant writes, measure p99 write latency during BGSAVE under load. Without testing, you might trade OOM anxiety for client timeouts.

Second: silent fallback to fork(). In prefer-forkless mode, the server can still fall back to classic fork(), for example when a third-party module lacks the VALKEYMODULE_OPTIONS_HANDLE_FORKLESS flag. Until stats confirm zero fallbacks on your real traffic, trimming RAM headroom down to 99% is risky.

Getting a background thread to cooperate with live writes wasn't easy. The pre-release 9.2.0 bug fixes show tricky race conditions: commands like ZUNION, ZINTER, ZINTERCARD, and ZDIFF could write corrupted entries to RDB if reading the same set during a snapshot, the LFU eviction policy hit a data race, and list-reading commands (LINDEX, LRANGE, LPOS) were mistakenly flagged as format-mutating. All of these were fixed before release, but the complexity explains why the feature ships disabled by default.

Release 9.2 also packs several other useful upgrades: streaming replication compression repl-compression (LZ4 cuts network traffic by 52% at under 1% CPU), zstd or lz4 RDB compression, a B+ Tree structure for large Sorted Sets that saves 36–43% memory per element, and write throttling when replicas fall behind.

How to enable forkless in Valkey 9.2 and when to stick with fork()

By default, valkey.conf in 9.2 sets forkless-infrastructure-enabled no and forkless-policy require-fork. If you saw bgsave-default-method in release candidates, note that it was renamed to forkless-policy for 9.2.0.

To switch to the new mode, add two directives to your config:

# Enable per-key metadata (+4 bytes per key).
# Immutable at runtime: requires a server restart.
forkless-infrastructure-enabled yes

# Use forkless for BGSAVE and full sync wherever possible,
# falling back to fork() if incompatible.
forkless-policy prefer-forkless

You can't toggle forkless-infrastructure-enabled at runtime via CONFIG SET, so a server restart is required. Enabling the infrastructure alone doesn't change snapshot behavior; forkless-policy prefer-forkless is what actually turns it on.

After restarting, run BGSAVE under test load and verify with valkey-cli that the snapshot ran without fork() or fallbacks:

# Trigger a background snapshot
valkey-cli BGSAVE

# Confirm the snapshot ran in forkless mode
valkey-cli INFO persistence | grep -E \
  "rdb_last_bgsave_type|rdb_bgsave_in_progress|forkless"
# Expected output includes: rdb_last_bgsave_type:forkless

# Check whether any silent fallbacks to fork() occurred
valkey-cli INFO debug | grep forkless_fallbacks

Alongside the snapshot type, INFO persistence now reports forkless_estimated_seconds_remaining—which works for diskless replica syncs too. Fallback counters moved to INFO debug. If fallbacks stay at zero and your p99 write latency remains within SLA, you're good to go. Also keep the scope in mind: in 9.2.0, forkless applies to RDB snapshots and full replica syncs, while AOF rewrites still use fork().

CriterionClassic require-forkNew prefer-forkless
Peak RAM during BGSAVEUp to 2× database size from CoWFlat RSS, no CoW spikes
Fixed memory overhead0 bytes per key+4 bytes metadata per key
Snapshot startup pauseYes (copying page tables)No fork() syscall
Writes to small strings (<= 512 B)Non-blockingNon-blocking (copy pool)
Writes to large hot keysNon-blockingWaits for key serialization
AOF rewriteUses fork()Still uses fork()
Runtime toggleEnabled by defaultRequires server restart

Which mode to pick depends on your data profile. If your Valkey instance holds millions of small, write-heavy strings and you're tired of keeping double RAM headroom just for occasional snapshots, prefer-forkless removes the main cause of nighttime OOM crashes. If your memory is full of heavy JSON blobs, big hashes, or lists under constant updates with strict latency SLAs, classic fork() with proper RAM headroom still delivers more predictable response times.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 4