@@ -343,7 +343,7 @@ type KubeletConfiguration struct {
343
343
344
344
type MemorySwapConfiguration struct {
345
345
// Configure swap memory available to container workloads. May be one of
346
- // "", "NoSwap ": workloads cannot use swap
346
+ // "", "LimitedSwap ": workload combined memory and swap usage cannot exceed pod memory limit
347
347
// "UnlimitedSwap": workloads can use unlimited swap, up to the allocatable limit.
348
348
SwapBehavior string
349
349
}
@@ -353,13 +353,22 @@ We want to expose common swap configurations based on the [Docker] and open
353
353
container specification for the ` --memory-swap ` flag. Thus, the
354
354
` MemorySwapConfiguration.SwapBehavior ` setting will have the following effects:
355
355
356
- * If ` SwapBehavior ` is not set or set to ` "NoSwap" ` , containers do not have
357
- access to swap. This value effectively prevents a container from using swap,
358
- even if it is enabled on a system.
356
+ * If ` SwapBehavior ` is not set or set to ` "LimitedSwap" ` , containers do not have
357
+ access to swap beyond their memory limit. This value prevents a container
358
+ from using swap in excess of their memory limit, even if it is enabled on a
359
+ system.
360
+ * With cgroups v1, it is possible for a container to use _ some_ swap if its
361
+ combined memory and swap usage do not exceed the
362
+ [ ` memory.memsw.limit_in_bytes ` ] limit.
363
+ * With cgroups v2, swap is configured independently from memory. Thus, the
364
+ container runtimes can set [ ` memory.swap.max ` ] to 0 in this case, and _ no_ swap
365
+ usage will be permitted.
359
366
* If ` SwapBehavior ` is set to ` "UnlimitedSwap" ` , the container is allowed to
360
367
use unlimited swap, up to the maximum amount available on the host system.
361
368
362
369
[ docker ] : https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details
370
+ [ `memory.memsw.limit_in_bytes` ] : https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/memory.html
371
+ [ `memory.swap.max` ] : https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory
363
372
364
373
#### CRI Changes
365
374
@@ -400,7 +409,7 @@ phase of graduation.
400
409
#### Alpha
401
410
402
411
- Kubelet can be started with swap enabled and will support two configurations
403
- for Kubernetes workloads: ` NoSwap ` and ` UnlimitedSwap ` .
412
+ for Kubernetes workloads: ` LimitedSwap ` and ` UnlimitedSwap ` .
404
413
- Kubelet can configure CRI to allocate swap to Kubernetes workloads. By
405
414
default, workloads will not be allocated any swap.
406
415
- e2e test jobs are configured for Linux systems with swap enabled.
0 commit comments