docker memory limit

The default host docker container can be used all the memory and CPU, we can  docker run  to limit the use of memory and CPU.

Some kernel does not support  Linux capabilities.  By  Docker info  to check the order, if the kernel does not support, will have the following error

WARNING: No swap limit support

On linux host, if the kernel found there is not enough memory, and will be reported OOME or Out Of Memory Exception, and will kill the process to free memory, any process are likely to be kill, including docker, which could cause the entire system downtime.

docker try to mitigate by adjusting docker daemon OOM priority risk, so it is more likely to be killed than other processes on the system.

Options description
-m or --memory= The container can be used with maximum memory, the memory for the minimum 4m, the unit may be b, k, m, g
--memory-swap* The maximum memory to the hard disk can be used for containers of
--memory-swappiness By default, the kernel may be swapped out of the container a proportion anonymous page set from 0 to 100, 0 represents off
--memory-reservation Memory Reservation
--kernel-memory Core memory limit. Minimum 4M
--oom-kill-disable Whether to block OOM killer to kill the container, not the default setting

 

 

 

 

 

 

--memory-swap Introduction

Only when --memory after setting, - memory-swap to take effect

1, if --memory-swapset to a positive integer, then both --memoryand  --memory-swapmust be set. --memory-swapIt indicates that the memory can be used and the total amount of the exchange, and --memorythe number of non-switched memory use control. Thus, if --memory="300m", and --memory-swap="1g", the container may be used in the memory 300m and 700m ( 1g - 300m) exchange.

2, if --memory-swapset 0, the setting is ignored, and the value is treated as not set.

3, if --memory-swapset to the same value --memory, and --memoryis set to a positive integer, no swap use .

4, if --memory-swapis not set and --memoryis --memoryset, if the host is configured to swap memory containers , the container can be used twice settings exchange. For example, if --memory="300m"and --memory-swapare not provided, the container can be used to exchange 300m and 600m of memory.

5, if --memory-swapexplicitly set -1, it allows unlimited use of the container exchange, up to the number available on the host system.

Prevent the containers exchange

If --memoryand --memory-swapset to the same value, it is possible to prevent any exchange of containers. This is because the--memory-swap combination of memory and the amount of exchange that can be used, but --memoryonly use the amount of physical memory.

--memory-swappiness detail

  • A value of 0 will turn off anonymous page exchange.
  • The value of all the anonymous pages 100 to exchangeable.
  • By default, if not set --memory-swappiness, then the value inherited from the host.

--kernel-memory detail

Kernel memory limit represents the total memory allocated to the container. Consider the following scenarios:

  • Unlimited memory, unlimited kernel memory : This is the default behavior.
  • Unlimited memory, kernel memory is limited : When the amount of memory required for all large memory cgroup on the host actually exists, it is appropriate. You can configure the kernel memory to never overwrite the contents available on the host, but requires more memory containers need to wait for it.
  • Limited memory, unlimited kernel memory : memory is limited overall, but not limited kernel memory.
  • Limited memory, limited kernel memory : restrict user and kernel memory is very useful for debugging problems related to memory. If you are using an unexpected number of containers of any type of memory, it will run out of memory without affecting other containers or hosts. In this setting, if the kernel memory limit is lower than the user memory limit, the kernel memory deficiency can lead to vessel encountered OOM error. If the kernel memory limit higher than the user memory limit, the kernel limit will not result in the vessel encountered OOM.

When you open any kernel memory limitations of each process will be based on the host track "high water mark" statistics so you can track what process (for the container in this case) is using extra memory. By /proc/<PID>/statuson the host view , you can see that in each process .

 

Guess you like

Origin www.cnblogs.com/cptao/p/10936256.html