Redis Database error Overcommit memory (OOM) Problem resolution

Source: Internet
Author: User
Tags redis

One, what is overcommit or oom problem

Linux replies "Yes" to most requests for memory so that more programs can be run. Memory is not used immediately after the memory is applied. This technique is called overcommit. OOM Killer (oom=out-of-memory) occurs when Linux discovers that there is not enough memory. It chooses to kill some processes (user-state processes, not kernel threads) to free up memory.

What processes will Linux choose to kill when Oom-killer occurs? The function that selects the process is the Oom_badness function (in mm/oom_kill.c), which computes the number of points (0~1000) for each process. The higher the number of points, the more likely this process will be killed. The number of points per process is related to Oom_score_adj, and Oom_score_adj can be set (-1000 lowest, 1000 highest).
Kernel parameter overcommit_memory, which is the memory allocation policy
Optional values: 0, 1, 2.

0 indicates that the kernel will check if there is enough available memory to use the process, and if there is enough memory available, the memory request is allowed, otherwise the memory request fails and the error is returned to the application process.
1 indicates that the kernel allows all physical memory to be allocated regardless of the current state of memory.
2, which indicates that the kernel allows to allocate more memory than the sum of all physical memory and swap space

Second, the problems that arise

Redis run after a period of time to hang up, PS view process no problem, check Redis log, found that there are warning, as follows:
[26145] Modified Dec 19:54:54 # 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.overcom Mit_memory=1 ' for this to take effect.
Telnet to 6379, any operation will return not permitted,
[root@localhost redis]# telnet 127.0.0.1 6379
Trying 127.0.0.1 ...
Connected to 127.0.0.1.
Escape character is ' ^] '.
Keys *
-err Operation not permitted

Redis does not set Requirepass, it is not possible because permissions problems cause not permitted.

Third, the solution

1, modify kernel parameters, 3 methods, choose one of the following:

(1) Edit/etc/sysctl.conf, change Vm.overcommit_memory=1, and then sysctl-p the configuration file into effect
(2) Sysctl Vm.overcommit_memory=1
(3) echo 1 >/proc/sys/vm/overcommit_memory

2, modify redis.conf, and then restart Redis

MaxMemory 5368709120
Maxmemory-policy ALLKEYS-LRU
Maxmemory-samples 3

Set MaxMemory, it is recommended to set to 1/2 to 3/4 of physical memory, not larger than the maximum physical memory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.