# Redis: # Can't save in background: fork: Cannot allocate memory / WARNING overcommit_memory is set to 0!

**Code:** `Can't save in background: fork: Cannot allocate memory` · **Category:** Redis · **Seen on:** Redis, Linux

Redis couldn't fork to write an RDB/AOF snapshot because the OS refused to allocate memory.

## Meaning

Set `vm.overcommit_memory = 1` (`sudo sysctl vm.overcommit_memory=1` and persist in `/etc/sysctl.conf`), ensure there is enough free RAM + swap, reduce dataset size, and disable THP. Forking duplicates page tables, so large instances need headroom (up to 2× in write-heavy loads).

## Common causes

- `vm.overcommit_memory=0` with a large dataset
- Not enough free RAM
- Containers with tight memory limits
- THP enabled
- Frequent snapshots with heavy writes

## Quick fix

1. `sudo sysctl vm.overcommit_memory=1` and add to /etc/sysctl.conf
2. Give the instance more RAM/headroom
3. Disable THP; tune `save` intervals

## Detailed fix by platform

### Linux

1. `sudo sysctl vm.overcommit_memory=1 && echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf`

## How to diagnose

1. **Overcommit** — Value?
2. **RAM** — Headroom?
3. **Limits** — Container memory?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/redis/fork-cannot-allocate-memory-overcommit)
