Skip to content

Commit 4929a75

Browse files
Merge pull request #6150 from haircommander/unlimited-swap-1.24
[1.24] server: allow for kubelet to specify -1 for swap
2 parents 3237d95 + 6b17c0b commit 4929a75

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

server/container_create_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrfactory.Cont
393393
}
394394
specgen.SetLinuxResourcesMemoryLimit(memoryLimit)
395395
if resources.MemorySwapLimitInBytes != 0 {
396-
if resources.MemorySwapLimitInBytes < resources.MemoryLimitInBytes {
396+
if resources.MemorySwapLimitInBytes > 0 && resources.MemorySwapLimitInBytes < resources.MemoryLimitInBytes {
397397
return nil, errors.Errorf(
398398
"container %s create failed because memory swap limit (%d) cannot be lower than memory limit (%d)",
399399
ctr.ID(),

test/cgroups.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ function teardown() {
8989
jq -e .linux.resources.memory.swap "$(runtime list | grep "$ctr_id" | awk '{ print $4 }')/config.json"
9090
}
9191

92+
@test "ctr with swap should succeed when swap is unlimited" {
93+
if ! grep -v Filename < /proc/swaps; then
94+
skip "swap not enabled"
95+
fi
96+
start_crio
97+
# memsw should be greater than or equal to memory limit
98+
# 210763776 = 1024*1024*200
99+
jq ' .linux.resources.memory_swap_limit_in_bytes = -1
100+
| .linux.resources.memory_limit_in_bytes = 210763776' \
101+
"$TESTDATA"/container_sleep.json > "$newconfig"
102+
103+
ctr_id=$(crictl run "$newconfig" "$TESTDATA"/sandbox_config.json)
104+
105+
if test -r "$CGROUP_MEM_SWAP_FILE"; then
106+
output=$(crictl exec --sync "$ctr_id" sh -c "cat $CGROUP_MEM_SWAP_FILE")
107+
[[ $output -gt 210763776 ]]
108+
fi
109+
}
110+
92111
@test "cgroupv2 unified support" {
93112
if ! is_cgroup_v2; then
94113
skip "node must be configured with cgroupv2 for this test"

0 commit comments

Comments
 (0)