Skip to content

Commit 80df8f2

Browse files
authored
Merge pull request #24126 from inknos/issue-23824
Docker compat: Return null when swappiness is unset instead of -1
2 parents e3b5d0f + 8dd7ac5 commit 80df8f2

5 files changed

Lines changed: 21 additions & 8 deletions

File tree

docs/source/markdown/podman-container-inspect.1.md.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ $ podman container inspect foobar
296296
"KernelMemory": 0,
297297
"MemoryReservation": 0,
298298
"MemorySwap": 0,
299-
"MemorySwappiness": 0,
299+
"MemorySwappiness": null,
300300
"OomKillDisable": false,
301301
"PidsLimit": 2048,
302302
"Ulimits": [],

libpod/container_inspect_linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC
6161
hostConfig.MemorySwap = *ctrSpec.Linux.Resources.Memory.Swap
6262
}
6363
if ctrSpec.Linux.Resources.Memory.Swappiness != nil {
64-
hostConfig.MemorySwappiness = int64(*ctrSpec.Linux.Resources.Memory.Swappiness)
65-
} else {
66-
// Swappiness has a default of -1
67-
hostConfig.MemorySwappiness = -1
64+
swappiness := int64(*ctrSpec.Linux.Resources.Memory.Swappiness)
65+
hostConfig.MemorySwappiness = &swappiness
6866
}
6967
if ctrSpec.Linux.Resources.Memory.DisableOOMKiller != nil {
7068
hostConfig.OomKillDisable = *ctrSpec.Linux.Resources.Memory.DisableOOMKiller

libpod/define/container_inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ type InspectContainerHostConfig struct {
643643
// MemorySwappiness is the willingness of the kernel to page container
644644
// memory to swap. It is an integer from 0 to 100, with low numbers
645645
// being more likely to be put into swap.
646-
// -1, the default, will not set swappiness and use the system defaults.
647-
MemorySwappiness int64 `json:"MemorySwappiness"`
646+
// nil means swappiness is unset and the system default is used.
647+
MemorySwappiness *int64 `json:"MemorySwappiness"`
648648
// OomKillDisable indicates whether the kernel OOM killer is disabled
649649
// for the container.
650650
OomKillDisable bool `json:"OomKillDisable"`

test/apiv2/20-containers.at

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,21 @@ t GET containers/$cid/json 200 \
870870
t DELETE containers/$cid 204
871871
podman rmi test1
872872

873+
# test MemorySwappiness
874+
podman run -d --rm --name swappiness_with_mem_limit --memory 200M $IMAGE top
875+
podman run -d --rm --name swappiness_without_mem_limit $IMAGE top
876+
877+
t GET containers/swappiness_with_mem_limit/json 200 \
878+
.HostConfig.MemorySwappiness=null
879+
t GET containers/swappiness_without_mem_limit/json 200 \
880+
.HostConfig.MemorySwappiness=null
881+
882+
t GET libpod/containers/swappiness_with_mem_limit/json 200 \
883+
.HostConfig.MemorySwappiness=null
884+
t GET libpod/containers/swappiness_without_mem_limit/json 200 \
885+
.HostConfig.MemorySwappiness=null
886+
887+
podman stop -t0 swappiness_with_mem_limit swappiness_without_mem_limit
873888

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

test/e2e/container_clone_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ var _ = Describe("Podman container clone", func() {
140140
cloneInspect.WaitWithDefaultTimeout()
141141
Expect(cloneInspect).To(ExitCleanly())
142142
cloneData = cloneInspect.InspectContainerToJSON()
143-
Expect(cloneData[0].HostConfig).To(HaveField("MemorySwappiness", int64(0)))
143+
Expect(cloneData[0].HostConfig.MemorySwappiness).To(BeNil())
144144
})
145145

146146
It("podman container clone in a pod", func() {

0 commit comments

Comments
 (0)