redis
resource_error
ai_generated
true
错误:BGSAVE 失败,因为 fork 失败:无法分配内存
Error: BGSAVE failed because fork failed: Cannot allocate memory
ID: redis/err-bgsave-failed-disk
80%修复率
90%置信度
1证据数
2023-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Redis 6.2.8 | active | — | — | — |
| Redis 7.0.13 | active | — | — | — |
| Linux kernel 5.10 | active | — | — | — |
| Linux kernel 6.1 | active | — | — | — |
根因分析
Redis 服务器尝试 fork 子进程以执行 BGSAVE 失败,原因是系统内存不足,通常是由于内存过提交设置或高内存使用率。
English
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.
官方文档
https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/解决方案
-
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`.
-
Reduce Redis memory usage by setting a lower `maxmemory` value or evicting keys with `maxmemory-policy allkeys-lru`. Restart Redis after changes.
-
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`.
无效尝试
常见但无效的做法:
-
95% 失败
The fork failure is at the OS level, not Redis config.
-
70% 失败
Swap can provide a buffer; disabling it may cause immediate OOM kills.