Skip to content

Commit 0666011

Browse files
committed
clarify CPU and memory limit enforcement differences
Clairify the container runtime and kubelet do not enforece memory limits, the kernel does. Also clarify that workloads won't always be OOM killed, and more clearly spell out the differences between memory and CPU limits Signed-off-by: Peter Hunt <[email protected]>
1 parent 3301d47 commit 0666011

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

content/en/docs/concepts/configuration/manage-resources-containers.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,37 @@ that system resource specifically for that container to use.
2828

2929
If the node where a Pod is running has enough of a resource available, it's possible (and
3030
allowed) for a container to use more resource than its `request` for that resource specifies.
31-
However, a container is not allowed to use more than its resource `limit`.
3231

3332
For example, if you set a `memory` request of 256 MiB for a container, and that container is in
3433
a Pod scheduled to a Node with 8GiB of memory and no other Pods, then the container can try to use
3534
more RAM.
3635

37-
If you set a `memory` limit of 4GiB for that container, the kubelet (and
38-
{{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}) enforce the limit.
39-
The runtime prevents the container from using more than the configured resource limit. For example:
40-
when a process in the container tries to consume more than the allowed amount of memory,
41-
the system kernel terminates the process that attempted the allocation, with an out of memory
42-
(OOM) error.
36+
Limits are a different story. Both `cpu` and `memory` limits are applied by the kubelet (and
37+
{{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}),
38+
and are ultimately enforced by the kernel. On Linux nodes, the Linux kernel
39+
enforces limits with
40+
{{< glossary_tooltip text="cgroups" term_id="cgroup" >}}.
41+
The behavior of `cpu` and `memory` limit enforcement is slightly different.
42+
43+
`cpu` limits are enforced by CPU throttling. When a container approaches
44+
its `cpu` limit, the kernel will restrict access to the CPU corresponding to the
45+
container's limit. Thus, a `cpu` limit is a hard limit the kernel enforces.
46+
Containers may not use more CPU than is specified in their `cpu` limit.
47+
48+
`memory` limits are enforced by the kernel with out of memory (OOM) kills. When
49+
a container uses more than its `memory` limit, the kernel may terminate it. However,
50+
terminations only happen when the kernel detects memory pressure. Thus, a
51+
container that over allocates memory may not be immediately killed. This means
52+
`memory` limits are enforced reactively. A container may use more memory than
53+
its `memory` limit, but if it does, it may get killed.
4354

44-
Limits can be implemented either reactively (the system intervenes once it sees a violation)
45-
or by enforcement (the system prevents the container from ever exceeding the limit). Different
46-
runtimes can have different ways to implement the same restrictions.
55+
{{< note >}}
56+
There is an alpha feature `MemoryQoS` which attempts to add more preemptive
57+
limit enforcement for memory (as opposed to reactive enforcement by the OOM
58+
killer). However, this effort is
59+
[stalled](https://github.com/kubernetes/enhancements/tree/a47155b340/keps/sig-node/2570-memory-qos#latest-update-stalled)
60+
due to a potential livelock situation a memory hungry can cause.
61+
{{< /note >}}
4762

4863
{{< note >}}
4964
If you specify a limit for a resource, but do not specify any request, and no admission-time
@@ -883,5 +898,4 @@ memory limit (and possibly request) for that container.
883898
and its [resource requirements](/docs/reference/kubernetes-api/workload-resources/pod-v1/#resources)
884899
* Read about [project quotas](https://www.linux.org/docs/man8/xfs_quota.html) in XFS
885900
* Read more about the [kube-scheduler configuration reference (v1)](/docs/reference/config-api/kube-scheduler-config.v1/)
886-
* Read more about [Quality of Service classes for Pods](/docs/concepts/workloads/pods/pod-qos/)
887-
901+
* Read more about [Quality of Service classes for Pods](/docs/concepts/workloads/pods/pod-qos/)

0 commit comments

Comments
 (0)