mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Fix segfault in run with memory-swap
when unlimited (-1) was being passed to memory-swap, podman threw a segfault. Fixes #9429 Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -148,17 +148,16 @@ func getMemoryLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts) (*specs.Linu
|
|||||||
}
|
}
|
||||||
if m := c.MemorySwap; len(m) > 0 {
|
if m := c.MemorySwap; len(m) > 0 {
|
||||||
var ms int64
|
var ms int64
|
||||||
if m == "-1" {
|
// only set memory swap if it was set
|
||||||
ms = int64(-1)
|
// -1 indicates unlimited
|
||||||
s.ResourceLimits.Memory.Swap = &ms
|
if m != "-1" {
|
||||||
} else {
|
|
||||||
ms, err = units.RAMInBytes(m)
|
ms, err = units.RAMInBytes(m)
|
||||||
|
memory.Swap = &ms
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "invalid value for memory")
|
return nil, errors.Wrapf(err, "invalid value for memory")
|
||||||
}
|
}
|
||||||
|
hasLimits = true
|
||||||
}
|
}
|
||||||
memory.Swap = &ms
|
|
||||||
hasLimits = true
|
|
||||||
}
|
}
|
||||||
if m := c.KernelMemory; len(m) > 0 {
|
if m := c.KernelMemory; len(m) > 0 {
|
||||||
mk, err := units.RAMInBytes(m)
|
mk, err := units.RAMInBytes(m)
|
||||||
|
@ -2,6 +2,7 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
. "github.com/containers/podman/v2/test/utils"
|
. "github.com/containers/podman/v2/test/utils"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@ -90,4 +91,27 @@ var _ = Describe("Podman run memory", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
Expect(session.OutputToString()).To(Equal("41943040"))
|
Expect(session.OutputToString()).To(Equal("41943040"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run kernel-memory test", func() {
|
||||||
|
if podmanTest.Host.Distribution == "ubuntu" {
|
||||||
|
Skip("Unable to perform test on Ubuntu distributions due to memory management")
|
||||||
|
}
|
||||||
|
var session *PodmanSessionIntegration
|
||||||
|
if CGROUPSV2 {
|
||||||
|
session = podmanTest.Podman([]string{"run", "--memory", "256m", "--memory-swap", "-1", ALPINE, "cat", "/sys/fs/cgroup/memory.swap.max"})
|
||||||
|
} else {
|
||||||
|
session = podmanTest.Podman([]string{"run", "--cgroupns=private", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"})
|
||||||
|
}
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(BeZero())
|
||||||
|
output := session.OutputToString()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
if CGROUPSV2 {
|
||||||
|
Expect(output).To(Equal("max"))
|
||||||
|
} else {
|
||||||
|
crazyHighNumber, err := strconv.ParseInt(output, 10, 64)
|
||||||
|
Expect(err).To(BeZero())
|
||||||
|
Expect(crazyHighNumber).To(BeNumerically(">", 936854771712))
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user