Some of the company's Redis servers are unclear, view the Redis logs, and find the following tips:
1 |
[
34145
]
01
Jan
17
:
42
:
02 # 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<br> /etc/sysctl.conf and then reboot or run the command
‘sysctl vm.overcommit_memory=1‘
f.
|
Overcommit_memory parameter Description: Set the memory allocation policy (optional, according to the actual situation of the server settings)/proc/sys/vm/overcommit_memory Optional values: 0, 1, 2. 0, indicates that the kernel will check for sufficient available memory to be used by the process, and if sufficient memory is available, the memory request is allowed; otherwise, the memory request fails and the error is returned to the application process. 1, which means that the kernel allows all physical memory to be allocated regardless of the current memory state. 2, which indicates that the kernel allows allocating more memory than the sum of all physical memory and swap space
Note: Redis in the dump data, will fork out a sub-process, in theory the child process occupies the same memory and the parent is the same, such as the parent occupies 8G of memory, this time also to allocate 8G of memory to child, if the memory is not affordable, Will often cause the Redis server down or IO load is too high, inefficient. So the more optimized memory allocation policy here should be set to 1 (indicating that the kernel allows all physical memory to be allocated regardless of the current memory state).
It also involves Overcommit and oom.
What is Overcommit and Oom in Unix, when a user process uses the malloc () function to request memory, if the return value is NULL, the process knows that there is currently no available memory space and will do the appropriate processing. Many processes print error messages and exit.
Linux uses a different approach, which responds "yes" to most requests for memory, so that it can run a larger number of programs. Memory is not used immediately after memory is applied. This technique is called overcommit. When memory is low, OOM killer (oom=out-of-memory) occurs. It chooses to kill some processes (the user-state process, not the kernel thread) in order to free up memory.
Overcommit strategy for Linux under Overcommit there are three strategies (documentation/vm/overcommit-accounting): 0. Heuristic strategy. Reasonable overcommit will be accepted and unreasonable overcommit will be rejected. 1. Any overcommit will be accepted. 2. Commit is rejected when the system allocates more memory than swap+n%* physical RAM (N% determined by Vm.overcommit_ratio). The Overcommit policy is set through Vm.overcommit_memory. The percentage of Overcommit is set by Vm.overcommit_ratio.
# echo 2 >/proc/sys/vm/overcommit_memory
# echo >/proc/sys/vm/overcommit_ratio
When oom-killer occurs, the function that Linux chooses to kill which process selection process is the Oom_badness function (in mm/oom_kill.c), the function calculates the number of points (0~1000) per process. The higher the number of points, the more likely the process is to be killed. The number of points per process is related to Oom_score_adj, and Oom_score_adj can be set (-1000 min, 1000 max).
Questions about Redis Overcommit_memory under Linux