Skip to content

Commit 31c6e9c

Browse files
committed
Graduate swap to Beta 1
Signed-off-by: Harshal Patil <harpatil@redhat.com>
1 parent 7f4ad2f commit 31c6e9c

File tree

1 file changed

+85
-10
lines changed

1 file changed

+85
-10
lines changed

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

+85-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- [Goals](#goals)
99
- [Non-Goals](#non-goals)
1010
- [Proposal](#proposal)
11+
- [Enable Swap Support only for Burstable QoS Pods](#enable-swap-support-only-for-burstable-qos-pods)
12+
- [Example 1 - Configured swap memory on the host is equal to the physical memory](#example-1---configured-swap-memory-on-the-host-is-equal-to-the-physical-memory)
13+
- [Example 2 - Configured swap memory on the host is NOT equal to the physical memory](#example-2---configured-swap-memory-on-the-host-is-not-equal-to-the-physical-memory)
1114
- [User Stories](#user-stories)
1215
- [Improved Node Stability](#improved-node-stability)
1316
- [Long-running applications that swap out startup memory](#long-running-applications-that-swap-out-startup-memory)
@@ -30,7 +33,8 @@
3033
- [Graduation Criteria](#graduation-criteria)
3134
- [Alpha](#alpha)
3235
- [Alpha2](#alpha2)
33-
- [Beta](#beta)
36+
- [Beta 1](#beta-1)
37+
- [Beta 2](#beta-2)
3438
- [GA](#ga)
3539
- [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy)
3640
- [Version Skew Strategy](#version-skew-strategy)
@@ -166,6 +170,71 @@ administrators can configure the kubelet such that:
166170

167171
This proposal enables scenarios 1 and 2 above, but not 3.
168172

173+
### Enable Swap Support only for Burstable QoS Pods
174+
Before enabling swap support through the pod API, it is crucial to build confidence in this feature by carefully assessing its impact on workloads and Kubernetes. As an initial step, we propose enabling swap support for Burstable QoS Pods by automatically calculating the appropriate swap values, rather than allowing users to input these values manually. By doing so, we can ensure a thorough understanding of the feature's performance and stability before considering the manual input of swap values in a subsequent beta release. This cautious approach will ensure the efficient allocation of resources and the smooth integration of swap support into Kubernetes.
175+
176+
Allocate the swap limit equal to the requested memory for each container and adjust the proportion of swap based on the total swap memory available, we can follow these steps:
177+
178+
1. **Calculate the total memory requests of the pod:**
179+
- Sum up the memory requests of all containers in the pod. Let's call this value `TotalMemory`.
180+
181+
2. **Determine the swap proportion for each container:**
182+
- 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`.
183+
184+
3. **Calculate the total swap memory available:**
185+
- Determine the total swap memory available in the system. If the total swap memory is equal to the total physical memory, you can skip this step. Otherwise, calculate the proportion of available swap memory compared to the total physical memory. Let's call this value `SwapMemoryProportion`.
186+
187+
4. **Calculate the swap limit for each container:**
188+
- 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.
189+
190+
#### Example 1 - Configured swap memory on the host is equal to the physical memory
191+
Suppose we have a Burstable QoS pod with two containers:
192+
193+
- Container A: Memory request 2 GB
194+
- Container B: Memory request 1 GB
195+
196+
Let's assume the total physical memory is 4 GB and the total swap memory available is also 4 GB.
197+
198+
Step 1: Calculate the total memory requests of the pod: 2 GB + 1 GB = 3 GB
199+
200+
Step 2: Determine the requested memory proportion for each container:
201+
- Container A: (2 GB) / (3 GB) = 2/3
202+
- Container B: (1 GB) / (3 GB) = 1/3
203+
204+
Step 3: Calculate the total swap memory available: Since the total swap memory (4 GB) is equal to the total physical memory (4 GB), the `SwapMemoryProportion` will be 1.
205+
206+
Step 4: Calculate the swap limit for each container:
207+
- Container A: (2/3) * 2 GB * 1 = 4/3 GB ≈ 1.33 GB
208+
- Container B: (1/3) * 1 GB * 1 = 1/3 GB ≈ 0.33 GB
209+
210+
In this example, Container A would have a swap limit of 1.33 GB, and Container B would have a swap limit of 0.33 GB.
211+
212+
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.
213+
214+
#### Example 2 - Configured swap memory on the host is NOT equal to the physical memory
215+
216+
If the total physical memory is 4 GB and the total swap memory available is 2 GB, we can adjust the example 1 using the same approach:
217+
218+
Suppose we have a Burstable QoS pod with two containers:
219+
220+
- Container A: Memory request 2 GB
221+
- Container B: Memory request 1 GB
222+
223+
Step 1: Calculate the total memory requests of the pod: 2 GB + 1 GB = 3 GB
224+
225+
Step 2: Determine the requested memory proportion for each container:
226+
- Container A: (2 GB) / (3 GB) = 2/3
227+
- Container B: (1 GB) / (3 GB) = 1/3
228+
229+
Step 3: Calculate the total swap memory available: Since the total swap memory (2 GB) is not equal to the total physical memory (4 GB), the `SwapMemoryProportion` will be 2 GB / 4 GB = 1/2.
230+
231+
Step 4: Calculate the swap limit for each container:
232+
- Container A: (2/3) * 2 GB * (1/2) = 4/6 GB ≈ 0.67 GB
233+
- Container B: (1/3) * 1 GB * (1/2) = 1/6 GB ≈ 0.17 GB
234+
235+
In this example, with 2 GB of total swap memory available, Container A would have a swap limit of 0.67 GB, and Container B would have a swap limit of 0.17 GB.
236+
237+
169238
### User Stories
170239

171240
#### Improved Node Stability
@@ -300,6 +369,8 @@ and/or workloads in a number of different scenarios.
300369
Since swap provisioning is out of scope of this proposal, this enhancement
301370
poses low risk to Kubernetes clusters that will not enable swap.
302371

372+
Enabling swap on a system without encryption poses a security risk, as critical information, such as Kubernetes secrets, may be swapped out to the disk. If an unauthorized individual gains access to the disk, they could potentially obtain these secrets. To mitigate this risk, it is recommended to use encrypted swap. However, handling encrypted swap is not within the scope of kubelet; rather, it is a general Linux configuration concern and should be addressed at that level. Nevertheless, it is essential to provide documentation that warns users of this potential issue, ensuring they are aware of the potential security implications and can take appropriate steps to safeguard their system.
373+
303374
## Design Details
304375

305376
We summarize the implementation plan as following:
@@ -494,7 +565,7 @@ For alpha2 [Current stage]:
494565
for configuring eviction.
495566
- Verify new system-reserved settings for swap memory.
496567

497-
For beta [Future]:
568+
For beta 1 [Future]:
498569

499570
- Add e2e tests that verify pod-level control of swap utilization.
500571
- Add e2e tests that verify swap performance with pods using a tmpfs.
@@ -536,20 +607,24 @@ Here are specific improvements to be made:
536607
swap limit for workloads.
537608
- Investigate eviction behavior with swap enabled.
538609

539-
540-
#### Beta
541-
542-
- Add support for controlling swap consumption at the pod level [via cgroups].
543-
- Handle usage of swap during container restart boundaries for writes to tmpfs
544-
(which may require pod cgroup change beyond what container runtime will do at
545-
container cgroup boundary).
610+
#### Beta 1
611+
- Enable Swap Support using Burstable QoS Pods only.
546612
- Add swap memory to the Kubelet stats api.
547613
- Determine a set of metrics for node QoS in order to evaluate the performance
548614
of nodes with and without swap enabled.
549615
- Better understand relationship of swap with memory QoS in cgroup v2
550616
(particularly `memory.high` usage).
551-
- Collect feedback from test user cases.
617+
- Make sure node e2e jobs that use swap are healthy
618+
- Publish a Kubernetes doc page encouring user to use encrypted swap if they wish to enable this feature.
552619
- Improve coverage for appropriate scenarios in testgrid.
620+
- Collect feedback from test user cases.
621+
- Handle usage of swap during container restart boundaries for writes to tmpfs
622+
(which may require pod cgroup change beyond what container runtime will do at
623+
container cgroup boundary).
624+
625+
#### Beta 2
626+
- 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.
627+
553628

554629
[via cgroups]: #restrict-swap-usage-at-the-cgroup-level
555630

0 commit comments

Comments
 (0)