# Error: BGSAVE failed because fork failed: Cannot allocate memory

- **ID:** `redis/err-bgsave-failed-disk`
- **Domain:** redis
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Redis 6.2.8 | active | — | — |
| Redis 7.0.13 | active | — | — |
| Linux kernel 5.10 | active | — | — |
| Linux kernel 6.1 | active | — | — |

## Workarounds

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`.** (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`.
   ```
2. **Reduce Redis memory usage by setting a lower `maxmemory` value or evicting keys with `maxmemory-policy allkeys-lru`. Restart Redis after changes.** (75% success)
   ```
   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`.** (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`.
   ```

## Dead Ends

- **** — The fork failure is at the OS level, not Redis config. (95% fail)
- **** — Swap can provide a buffer; disabling it may cause immediate OOM kills. (70% fail)
