As I was working on a docker-compose stack I received the following warning message that was coming from the Redis service:
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
Here are few ways to tackle it down.
The easiest and shortest answer would be to do as the warning says.
Step 1. Open /etc/sysctl.conf file.
sudo vim /etc/sysctl.conf
Step 2. Update or add the following line at the end of the file.
vm.overcommit_memory = 1
Step 3. Save the file and reboot the machine.
It’s worth to mention that this needs to be done on the host machine. Not related to the Docker container at all.
Although, Redis recommends setting the
vm.overcommit_memory to 1 by their official FAQ docs, a much better and safer approach would be to do nothing and ignore the warning.
However, if you do experience performance issue, try to scale up the instance in terms of memory.
Last but not least, try playing around with redis-overcommit-on-host GitHub repo.