Skip to content

Commit 41afa94

Browse files
committed
Fix swap memory
1 parent 88b4c48 commit 41afa94

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

libcontainer/cgroups/fs/memory.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,17 @@ func setKernelMemory(path string, kernelMemoryLimit int64) error {
9898
func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
9999
// When memory and swap memory are both set, we need to handle the cases
100100
// for updating container.
101-
if cgroup.Resources.Memory != 0 && cgroup.Resources.MemorySwap > 0 {
101+
102+
if cgroup.Resources.Memory == -1 {
103+
if err := writeFile(path, "memory.memsw.limit_in_bytes", strconv.FormatInt(-1, 10)); err != nil {
104+
return err
105+
}
106+
if err := writeFile(path, "memory.limit_in_bytes", strconv.FormatInt(cgroup.Resources.Memory, 10)); err != nil {
107+
return err
108+
}
109+
}
110+
111+
if cgroup.Resources.Memory > 0 && cgroup.Resources.MemorySwap > 0 {
102112
memoryUsage, err := getMemoryData(path, "")
103113
if err != nil {
104114
return err
@@ -123,7 +133,7 @@ func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
123133
}
124134
}
125135
} else {
126-
if cgroup.Resources.Memory != 0 {
136+
if cgroup.Resources.Memory > 0 {
127137
if err := writeFile(path, "memory.limit_in_bytes", strconv.FormatInt(cgroup.Resources.Memory, 10)); err != nil {
128138
return err
129139
}

0 commit comments

Comments
 (0)