Skip to content

Commit b19f856

Browse files
harcheiholder101
andcommitted
Graduate swap to Beta 1
Signed-off-by: Harshal Patil <[email protected]> Co-authored-by: Itamar Holder <[email protected]>
1 parent ade6b45 commit b19f856

File tree

2 files changed

+82
-15
lines changed

2 files changed

+82
-15
lines changed

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

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
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+
- [Set Aside Swap for System Critical Daemon](#set-aside-swap-for-system-critical-daemon)
13+
- [Steps to Calculate Swap Limit](#steps-to-calculate-swap-limit)
14+
- [Example](#example)
1115
- [User Stories](#user-stories)
1216
- [Improved Node Stability](#improved-node-stability)
1317
- [Long-running applications that swap out startup memory](#long-running-applications-that-swap-out-startup-memory)
@@ -17,6 +21,7 @@
1721
- [Virtualization management overhead](#virtualization-management-overhead)
1822
- [Notes/Constraints/Caveats (Optional)](#notesconstraintscaveats-optional)
1923
- [Risks and Mitigations](#risks-and-mitigations)
24+
- [Security risk](#security-risk)
2025
- [Design Details](#design-details)
2126
- [Enabling swap as an end user](#enabling-swap-as-an-end-user)
2227
- [API Changes](#api-changes)
@@ -30,7 +35,8 @@
3035
- [Graduation Criteria](#graduation-criteria)
3136
- [Alpha](#alpha)
3237
- [Alpha2](#alpha2)
33-
- [Beta](#beta)
38+
- [Beta 1](#beta-1)
39+
- [Beta 2](#beta-2)
3440
- [GA](#ga)
3541
- [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy)
3642
- [Version Skew Strategy](#version-skew-strategy)
@@ -166,6 +172,54 @@ administrators can configure the kubelet such that:
166172

167173
This proposal enables scenarios 1 and 2 above, but not 3.
168174

175+
### Enable Swap Support only for Burstable QoS Pods
176+
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.
177+
178+
Swap access is granted only for pods of Burstable QoS. Guaranteed QoS pods are usually higher-priority pods, therefore we want to avoid swap's performance penalty for them. Best-Effort pods, on the contrary, are low-priority pods that are the first to be killed during node pressures. In addition, they're unpredictable, therefore it's hard to assess how much swap memory is a reasonable amount to allocate for them.
179+
180+
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.
181+
182+
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.
183+
184+
#### Set Aside Swap for System Critical Daemon
185+
186+
System critical daemons (such as Kubelet) are essential for node health. Usually, an appropriate portion of system resources (e.g., memory, CPU) is reserved as system reserved. However, swap doesn't inherently support reserving a portion out of the total available. For instance, in the case of memory, we set `memory.min` on the node-level cgroup to ensure an adequate amount of memory is set aside, away from the pods, and for system critical daemons. But there is no equivalent for swap; i.e., no `memory.swap.min` is supported in the kernel.
187+
188+
Since this proposal advocates enabling swap only for the Burstable QoS pods, this can be done by setting `memory.swap.max` on the cgroups used by the Burstable QoS pods. The value of this `memory.swap.max` can be calculated by:
189+
190+
memory.swap.max = total swap memory available on the system - system reserve (memory)
191+
192+
This is the total amount of swap available for all the Burstable QoS pods; let's call it `TotalPodsSwapAvailable`. This will ensure that the system critical daemons will have access to the swap at least equal to the system reserved memory. This will indirectly act as having support for swap in system reserved.
193+
194+
### Steps to Calculate Swap Limit
195+
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.
199+
200+
2. **Multiply the container memory proportion by the available swap memory for Pods:**
201+
- Meaning: `ContainerMemoryProportion * TotalPodsSwapAvailable`.
202+
203+
#### Example
204+
Suppose we have a Burstable QoS pod with two containers:
205+
206+
- Container A: Memory request 20 GB
207+
- Container B: Memory request 10 GB
208+
209+
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,
210+
211+
Step 1: Determine the containers memory proportion:
212+
- Container A: `20G/40G` = `0.5`.
213+
- Container B: `10G/40G` = `0.25`.
214+
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`.
218+
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.
220+
221+
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.
222+
169223
### User Stories
170224

171225
#### Improved Node Stability
@@ -300,6 +354,14 @@ and/or workloads in a number of different scenarios.
300354
Since swap provisioning is out of scope of this proposal, this enhancement
301355
poses low risk to Kubernetes clusters that will not enable swap.
302356

357+
#### Security risk
358+
359+
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 OS 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.
360+
361+
To guarantee that system daemons are not swapped, the kubelet must configure the `memory.swap.max` setting to `0` within the system reserved cgroup. Moreover, to make sure that burstable pods are able to utilize swap space, kubelet should verify that the cgroup associated with burstable pods should not be nested under the cgroup designated for system reserved.
362+
363+
Additionally, end user may decide to disable swap completely for a Pod or a container in beta 1 by making Pod guaranteed or set request == limit for a container. This way, there will be no swap enabled for the corresponding containers and there will be no information exposure risks.
364+
303365
## Design Details
304366

305367
We summarize the implementation plan as following:
@@ -487,14 +549,14 @@ Test grid tabs enabled:
487549

488550
No new e2e tests introduced.
489551

490-
For alpha2 [Current stage]:
552+
For alpha2:
491553

492554
- Add e2e tests that exercise all available swap configurations via the CRI.
493555
- Verify MemoryPressure behavior with swap enabled and document any changes
494556
for configuring eviction.
495557
- Verify new system-reserved settings for swap memory.
496558

497-
For beta [Future]:
559+
For beta 1:
498560

499561
- Add e2e tests that verify pod-level control of swap utilization.
500562
- Add e2e tests that verify swap performance with pods using a tmpfs.
@@ -536,21 +598,22 @@ Here are specific improvements to be made:
536598
swap limit for workloads.
537599
- Investigate eviction behavior with swap enabled.
538600

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).
601+
#### Beta 1
602+
- Enable Swap Support using Burstable QoS Pods only.
603+
- Enable Swap Support for Cgroup v2 Only.
546604
- Add swap memory to the Kubelet stats api.
547605
- Determine a set of metrics for node QoS in order to evaluate the performance
548606
of nodes with and without swap enabled.
549-
- Better understand relationship of swap with memory QoS in cgroup v2
550-
(particularly `memory.high` usage).
551-
- Collect feedback from test user cases.
607+
- Make sure node e2e jobs that use swap are healthy
552608
- Improve coverage for appropriate scenarios in testgrid.
553609

610+
#### Beta 2
611+
- Publish a Kubernetes doc page encoring user to use encrypted swap if they wish to enable this feature.
612+
- Handle usage of swap during container restart boundaries for writes to tmpfs
613+
(which may require pod cgroup change beyond what container runtime will do at
614+
container cgroup boundary).
615+
616+
554617
[via cgroups]: #restrict-swap-usage-at-the-cgroup-level
555618

556619
#### GA
@@ -559,6 +622,8 @@ _(Tentative.)_
559622

560623
- Test a wide variety of scenarios that may be affected by swap support.
561624
- Remove feature flag.
625+
- Remove the Swap Support using Burstable QoS Pods only deprecated in Beta 2.
626+
562627

563628
### Upgrade / Downgrade Strategy
564629

keps/sig-node/2400-node-swap/kep.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ authors:
44
- "@ehashman"
55
- "@ike-ma"
66
- "@SergeyKanzhelev"
7+
- "@harche"
8+
- "@iholder101"
79
owning-sig: sig-node
810
participating-sigs:
911
- sig-node
@@ -18,12 +20,12 @@ approvers:
1820
- "@dchen1107"
1921

2022
# The target maturity stage in the current dev cycle for this KEP.
21-
stage: alpha
23+
stage: beta
2224

2325
# The most recent milestone for which work toward delivery of this KEP has been
2426
# done. This can be the current (upcoming) milestone, if it is being actively
2527
# worked on.
26-
latest-milestone: "v1.27"
28+
latest-milestone: "v1.28"
2729

2830
# The milestone at which this feature was, or is targeted to be, at each stage.
2931
milestone:

0 commit comments

Comments
 (0)