Skip to content

Commit 1961152

Browse files
committed
Update and simplify swap limit calculation
Signed-off-by: Itamar Holder <iholder@redhat.com>
1 parent 5c678ef commit 1961152

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

keps/sig-node/2400-node-swap/README.md

+13-26
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,12 @@ This is the total amount of swap available for all the Burstable QoS pods; let's
193193

194194
### Steps to Calculate Swap Limit
195195

196-
1. **Calculate the total memory requests of the pod:**
197-
- Sum up the memory requests of all containers in the pod. Let's call this value `TotalMemory`.
196+
1. **Calculate the container's memory proportionate to the node's memory:**
197+
- Divide the container's memory request by the total node's physical memory. Let's call this value `ContainerMemoryProportion`.
198+
- 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.
198199

199-
2. **Determine the swap proportion for each container:**
200-
- 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`.
201-
- 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.
202-
203-
3. **Calculate the total swap memory available:**
204-
- `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`.
205-
206-
4. **Calculate the swap limit for each container:**
207-
- 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.
200+
2. **Multiply the container memory proportion by the available swap memory for Pods:**
201+
- Meaning: `ContainerMemoryProportion * TotalPodsSwapAvailable`.
208202

209203
#### Example
210204
Suppose we have a Burstable QoS pod with two containers:
@@ -214,21 +208,15 @@ Suppose we have a Burstable QoS pod with two containers:
214208

215209
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,
216210

217-
Step 1: Calculate `TotalPodsSwapAvailable`, which denotes total available swap memory: 40 GB - 2 GB = 38 GB
218-
219-
Step 2: Calculate the total memory requests of the pod: 20 GB + 10 GB = 30 GB
220-
221-
Step 2: Determine the requested memory proportion for each container:
222-
- Container A: (20 GB) / (30 GB) = 2/3
223-
- Container B: (10 GB) / (30 GB) = 1/3
224-
225-
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
211+
Step 1: Determine the containers memory proportion:
212+
- Container A: `20G/40G` = `0.5`.
213+
- Container B: `10G/40G` = `0.25`.
226214

227-
Step 4: Calculate the swap limit for each container:
228-
- Container A: (2/3) * 20 GB * 0.95 ≈ 12.66 GB
229-
- Container B: (1/3) * 10 GB * 0.95 ≈ 3.16 GB
215+
Step 2: Determine swap limitation for the containers:
216+
- Container A: `ContainerMemoryProportion * TotalPodsSwapAvailable` = `0.5 * 38G` = `19G`.
217+
- Container B: `ContainerMemoryProportion * TotalPodsSwapAvailable` = `0.25 * 38G` = `9.5G`.
230218

231-
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.
219+
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.
232220

233221
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.
234222

@@ -619,8 +607,7 @@ Here are specific improvements to be made:
619607
- 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.
620608

621609
#### Beta 2
622-
- 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.
623-
- Publish a Kubernetes doc page encouring user to use encrypted swap if they wish to enable this feature.
610+
- Publish a Kubernetes doc page encoring user to use encrypted swap if they wish to enable this feature.
624611
- Handle usage of swap during container restart boundaries for writes to tmpfs
625612
(which may require pod cgroup change beyond what container runtime will do at
626613
container cgroup boundary).

0 commit comments

Comments
 (0)