Questions about Redis Overcommit_memory under Linux

Source: Internet
Author: User
Tags redis server

Reprinted from: http://skly-java.iteye.com/blog/2167400

Startup error

1.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 the take effect.

2.warning:the TCP Backlog setting of 511 cannot be enforced because/proc/sys/net/core/somaxconn are set to the lower Valu E of 128.

Workaround

The first warning is resolved in two ways (overcommit_memory)

1. Echo "Vm.overcommit_memory=1" >/etc/sysctl.conf

Then sysctl-p/etc/sysctl.conf make the configuration file effective

2. Echo 1 >/proc/sys/vm/overcommit_memory do not need to start the machine to take effect, temporary effect, restart the machine is invalid, to be permanent, the configuration file sysctl.conf bar

Linux-related points of knowledge : transfer from: http://blog.csdn.net/hncdsun/article/details/5093983

Sysctl The kernel parameters that are configured and displayed in the/proc/sys directory. You can use Sysctl to set up or reset networking features such as IP forwarding, IP fragment removal, and source routing checks. Users only need to edit the/etc/sysctl.conf file to manually or automatically perform the functions controlled by sysctl.

Command format:

Sysctl [-n] [-e]-W variable=value

Sysctl [-n] [-e]-P <filename> (default/etc/sysctl.conf)

Sysctl [-n] [-e]-A

The meaning of common parameters:

-W temporarily changes the value of a specified parameter, such as

Sysctl-w net.ipv4.ip_forward=1

-a displays all system parameters

-P loads the system parameters from the specified file, which is loaded from the/etc/sysctl.conf if not specified

If you just want to temporarily change the value of a system parameter, you can do it in two ways, for example, to enable the IP routing forwarding feature:

1) #echo 1 >/proc/sys/net/ipv4/ip_forward

2) #sysctl-W net.ipv4.ip_forward=1

Both of these methods may immediately turn on routing, but if the system restarts, or the

# Service Network Restart

command, the value you set is lost and you can modify the/etc/sysctl.conf file if you want to permanently retain the configuration

Change Net.ipv4.ip_forward=0 to Net.ipv4.ip_forward=1

A second warning resolves

1. Echo 511 >/proc/sys/net/core/somaxconn

overcommit_memory parameter Description :

Set the memory allocation policy/proc/sys/vm/overcommit_memory (optional, set according to the actual situation of the server)
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's strategy


There are three strategies for Linux under Overcommit (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, Linux chooses which processes to kill


The function that selects a process is the oom_badness function (in MM/OOM_KILL.C), which 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

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.