[NoSQL Redis] FAQs Redis

Can’t save in background: fork: Cannot allocate memory

APP log

1
2
3
4
# ${RAILS_ROOT}/log/production.log
...
MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
...

Redis Log - Can’t save in background: fork: Cannot allocate memory

1
2
3
4
[[email protected] /root]# tail -f /var/log/redis/redis.log
1573:M 14 Jan 16:56:04.011 * 1 changes in 900 seconds. Saving...
1573:M 14 Jan 16:56:04.011 # Can't save in background: fork: Cannot allocate memory
1573:M 14 Feb 16:56:10.045 * 1 changes in 900 seconds. Saving...

In traditional way, Linux gives you three options for what happens when a process tries to allocate some more memory, controlled by the value of the vm.overcommit_memory sysctl:

The kernel gives you the memory unless it thinks you would clearly overcommit the system (mode 0, the default, ‘heuristic overcommit’).

the kernel always gives you the memory (mode 1, ‘always overcommit’).

the kernel refuses to give you more memory if it would take the committed address space over the commit limit (mode 2, what I call ‘strict overcommit’).
(Disclaimer: all of this assumes a relatively recent 2.6 kernel.)

These settings control how Linux handles virtual memory limits.

After changing this setting from 0 to 1 Redis started persisting the data immediately and the overall performance increased dramatically.

To do so either open the file /proc/sys/vm/overcommit_memory and remove 0 and put 1 or run the following command.

This might now work as the file may be already in use by the system.

1
$ echo 1 > /proc/sys/vm/overcommit_memory

So other way to do the same is to 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.

1
2
3
4
5
$ vi /etc/sysctl.conf
# /etc/sysctl.conf
vm.overcommit_memory=1

$ sysctl -p

See Can’t save in background: fork: Cannot allocate memory Redis ~ Appychip - https://jee-appy.blogspot.com/2016/04/can-not-save-in-background-fork-redis.html to learn more.

References

[1] Redis - https://redis.io/

[2] Can’t save in background: fork: Cannot allocate memory Redis ~ Appychip - https://jee-appy.blogspot.com/2016/04/can-not-save-in-background-fork-redis.html