Skip to content

Commit 5ca6afd

Browse files
committed
Fix: set Swappiness when no mem limits
This hard codes -1 on inspect for Docker's API to return `null` and be compatible Signed-off-by: Nicola Sella <[email protected]>
1 parent 4120115 commit 5ca6afd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/api/handlers/compat/containers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
526526
hc.CgroupnsMode = container.CgroupnsModeHost
527527
}
528528

529+
swappiness := int64(-1)
530+
hc.MemorySwappiness = &swappiness
531+
532+
// Docker reports null instead of 0 for unset Swappiness
533+
if *hc.MemorySwappiness == -1 {
534+
hc.MemorySwappiness = nil
535+
}
529536
// k8s-file == json-file
530537
if hc.LogConfig.Type == define.KubernetesLogging {
531538
hc.LogConfig.Type = define.JSONLogging

test/apiv2/20-containers.at

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,16 @@ if root && test -e /dev/nullb0; then
782782
podman rm -f updateCtr
783783
fi
784784

785+
# test MemorySwappiness
786+
podman run -d --rm --name swappiness_with_mem_limit --memory 200M quay.io/libpod/alpine:latest top
787+
podman run -d --rm --name swappiness_without_mem_limit quay.io/libpod/alpine:latest top
788+
789+
t GET containers/swappiness_with_mem_limit/json 200 \
790+
.HostConfig.MemorySwappiness=null
791+
t GET containers/swappiness_without_mem_limit/json 200 \
792+
.HostConfig.MemorySwappiness=null
793+
794+
podman stop -t0 swappiness_with_mem_limit swappiness_without_mem_limit
785795

786796
# test if API support -1 for ulimits https://github.com/containers/podman/issues/24886
787797

0 commit comments

Comments
 (0)