diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go index 596248e43b..4a002278da 100644 --- a/pkg/api/handlers/compat/containers.go +++ b/pkg/api/handlers/compat/containers.go @@ -526,6 +526,13 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp hc.CgroupnsMode = container.CgroupnsModeHost } + swappiness := int64(-1) + hc.MemorySwappiness = &swappiness + + // Docker reports null instead of 0 for unset Swappiness + if *hc.MemorySwappiness == -1 { + hc.MemorySwappiness = nil + } // k8s-file == json-file if hc.LogConfig.Type == define.KubernetesLogging { hc.LogConfig.Type = define.JSONLogging diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 94ff485050..e125013a1a 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -782,6 +782,16 @@ if root && test -e /dev/nullb0; then podman rm -f updateCtr fi +# test MemorySwappiness +podman run -d --rm --name swappiness_with_mem_limit --memory 200M quay.io/libpod/alpine:latest top +podman run -d --rm --name swappiness_without_mem_limit quay.io/libpod/alpine:latest top + +t GET containers/swappiness_with_mem_limit/json 200 \ + .HostConfig.MemorySwappiness=null +t GET containers/swappiness_without_mem_limit/json 200 \ + .HostConfig.MemorySwappiness=null + +podman stop -t0 swappiness_with_mem_limit swappiness_without_mem_limit # test if API support -1 for ulimits https://github.com/containers/podman/issues/24886