diff --git a/keps/sig-node/2400-node-swap/README.md b/keps/sig-node/2400-node-swap/README.md index 4e06f2753154..bcd030127176 100644 --- a/keps/sig-node/2400-node-swap/README.md +++ b/keps/sig-node/2400-node-swap/README.md @@ -193,18 +193,12 @@ This is the total amount of swap available for all the Burstable QoS pods; let's ### Steps to Calculate Swap Limit -1. **Calculate the total memory requests of the pod:** - - Sum up the memory requests of all containers in the pod. Let's call this value `TotalMemory`. +1. **Calculate the container's memory proportionate to the node's memory:** + - Divide the container's memory request by the total node's physical memory. Let's call this value `ContainerMemoryProportion`. + - If a container is defined with memory requests == memory limits, its `ContainerMemoryProportion` is defined as 0. Therefore, as can be seen below, its overall swap limit is also 0. -2. **Determine the swap proportion for each container:** - - For each container, divide its memory request by the `TotalMemory`. The result will be the proportion of requested memory for that container within the pod. Let's call this value `RequestedMemoryProportion`. - - If a container is defined with memory requests == memory limits, its `RequestedMemoryProportion` is defined as 0.Therefore, as can be seen below, its overall swap limit is also 0. - -3. **Calculate the total swap memory available:** - - `TotalPodsSwapAvailable` is the total amount of memory available for the pods. Divide the available swap memory by the total physical memory. Let's call this value `SwapMemoryProportion`. - -4. **Calculate the swap limit for each container:** - - Multiply the `RequestedMemoryProportion` of a container by its memory request and then multiply the result by the `SwapMemoryProportion`. The result will be the adjusted swap limit for that specific container within the pod. +2. **Multiply the container memory proportion by the available swap memory for Pods:** + - Meaning: `ContainerMemoryProportion * TotalPodsSwapAvailable`. #### Example Suppose we have a Burstable QoS pod with two containers: @@ -214,21 +208,15 @@ Suppose we have a Burstable QoS pod with two containers: Let's assume the total physical memory is 40 GB and the total swap memory available is also 40 GB. Also assume that the system reserved memory is configured at 2GB, -Step 1: Calculate `TotalPodsSwapAvailable`, which denotes total available swap memory: 40 GB - 2 GB = 38 GB - -Step 2: Calculate the total memory requests of the pod: 20 GB + 10 GB = 30 GB - -Step 2: Determine the requested memory proportion for each container: -- Container A: (20 GB) / (30 GB) = 2/3 -- Container B: (10 GB) / (30 GB) = 1/3 - -Step 3: Calculate the total swap memory available: Since the total swap memory (38 GB) and physical memory (40 GB), the `SwapMemoryProportion` will be 38 GB / 40 GB = 0.95 +Step 1: Determine the containers memory proportion: +- Container A: `20G/40G` = `0.5`. +- Container B: `10G/40G` = `0.25`. -Step 4: Calculate the swap limit for each container: -- Container A: (2/3) * 20 GB * 0.95 ≈ 12.66 GB -- Container B: (1/3) * 10 GB * 0.95 ≈ 3.16 GB +Step 2: Determine swap limitation for the containers: +- Container A: `ContainerMemoryProportion * TotalPodsSwapAvailable` = `0.5 * 38G` = `19G`. +- Container B: `ContainerMemoryProportion * TotalPodsSwapAvailable` = `0.25 * 38G` = `9.5G`. -In this example, Container A would have a swap limit of 12.66 GB, and Container B would have a swap limit of 3.16 GB. +In this example, Container A would have a swap limit of 19 GB, and Container B would have a swap limit of 9.5 GB. This approach allocates swap limits based on each container's memory request and adjusts the proportion based on the total swap memory available in the system. It ensures that each container gets a fair share of the swap space and helps maintain resource allocation efficiency. @@ -619,8 +607,7 @@ Here are specific improvements to be made: - Remove support for setting unlimited amount of swap (including [swapBehavior](https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-MemorySwapConfiguration) flag of the Kubelet) as any workload with aggressive memory allocation can bring down a node with having no limits on swap usage. #### Beta 2 -- Add support for controlling swap consumption at the container level [via cgroups] in Pod API in [container resources](https://github.com/kubernetes/kubernetes/blob/94a15929cf13354fdf3747cb266d511154f8c97b/staging/src/k8s.io/api/core/v1/types.go#L2443). More specifically add a new [ResourceName](https://github.com/kubernetes/kubernetes/blob/94a15929cf13354fdf3747cb266d511154f8c97b/staging/src/k8s.io/api/core/v1/types.go#L5522) `swap`. This will make sure we stay consistent with other resources like `cpu`, `memory` etc. -- Publish a Kubernetes doc page encouring user to use encrypted swap if they wish to enable this feature. +- Publish a Kubernetes doc page encoring user to use encrypted swap if they wish to enable this feature. - Handle usage of swap during container restart boundaries for writes to tmpfs (which may require pod cgroup change beyond what container runtime will do at container cgroup boundary).