Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Critical]: Can't save in background: fork: Cannot allocate memory #89

Closed
MathBunny opened this issue Apr 2, 2019 · 1 comment
Closed
Assignees

Comments

@MathBunny
Copy link
Owner

User reported issue that seems related to #86. The effect is that users are periodically logged off, as redis-server appears unable to allocate sufficient memory to store key/value pairs (call to malloc fails).

For the future, proper implementation of a more fault tolerant version of #81 should prevent this from happening. Additionally, Redis should not be in the critical path and simply used for caching only.

@MathBunny
Copy link
Owner Author

Apparently, the issue is well documented here.

Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits. In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages. A page will be duplicated only when it changes in the child or in the parent. Since in theory all the pages may change while the child process is saving, Linux can't tell in advance how much memory the child will take, so if the overcommit_memory setting is set to zero fork will fail unless there is as much free RAM as required to really duplicate all the parent memory pages, with the result that if you have a Redis dataset of 3 GB and just 2 GB of free memory it will fail.

Setting overcommit_memory to 1 tells Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant