redis resource_error ai_generated true

Error: BGSAVE failed because fork failed: Cannot allocate memory

ID: redis/err-bgsave-failed-disk

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
1Evidence
2023-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Redis 6.2.8 active
Redis 7.0.13 active
Linux kernel 5.10 active
Linux kernel 6.1 active

Root Cause

The Redis server's attempt to fork a child process for BGSAVE failed due to insufficient system memory, often because of overcommit memory settings or high memory usage.

generic

中文

Redis 服务器尝试 fork 子进程以执行 BGSAVE 失败,原因是系统内存不足,通常是由于内存过提交设置或高内存使用率。

Official Documentation

https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/

Workarounds

  1. 90% success Enable overcommit memory on the Linux host: `echo 1 > /proc/sys/vm/overcommit_memory` and make it persistent in /etc/sysctl.conf with `vm.overcommit_memory = 1`.
    Enable overcommit memory on the Linux host: `echo 1 > /proc/sys/vm/overcommit_memory` and make it persistent in /etc/sysctl.conf with `vm.overcommit_memory = 1`.
  2. 75% success Reduce Redis memory usage by setting a lower `maxmemory` value or evicting keys with `maxmemory-policy allkeys-lru`. Restart Redis after changes.
    Reduce Redis memory usage by setting a lower `maxmemory` value or evicting keys with `maxmemory-policy allkeys-lru`. Restart Redis after changes.
  3. 80% success Use a smaller fork-friendly configuration: set `repl-diskless-sync yes` to avoid fork during replication, or switch to AOF with `appendonly yes` and `no-appendfsync-on-rewrite yes`.
    Use a smaller fork-friendly configuration: set `repl-diskless-sync yes` to avoid fork during replication, or switch to AOF with `appendonly yes` and `no-appendfsync-on-rewrite yes`.

中文步骤

  1. Enable overcommit memory on the Linux host: `echo 1 > /proc/sys/vm/overcommit_memory` and make it persistent in /etc/sysctl.conf with `vm.overcommit_memory = 1`.
  2. Reduce Redis memory usage by setting a lower `maxmemory` value or evicting keys with `maxmemory-policy allkeys-lru`. Restart Redis after changes.
  3. Use a smaller fork-friendly configuration: set `repl-diskless-sync yes` to avoid fork during replication, or switch to AOF with `appendonly yes` and `no-appendfsync-on-rewrite yes`.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The fork failure is at the OS level, not Redis config.

  2. 70% fail

    Swap can provide a buffer; disabling it may cause immediate OOM kills.