Merge pull request #2370 from lifubang/swap0
let runc disable swap in cgroup v2
This commit is contained in:
commit
a57358e016
|
@ -45,10 +45,13 @@ func setMemory(dirPath string, cgroup *configs.Cgroup) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if val := numToStr(swap); val != "" {
|
swapStr := numToStr(swap)
|
||||||
if err := fscommon.WriteFile(dirPath, "memory.swap.max", val); err != nil {
|
if swapStr == "" && swap == 0 && cgroup.Resources.MemorySwap > 0 {
|
||||||
return err
|
// memory and memorySwap set to the same value -- disable swap
|
||||||
}
|
swapStr = "0"
|
||||||
|
}
|
||||||
|
if err := fscommon.WriteFile(dirPath, "memory.swap.max", swapStr); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := numToStr(cgroup.Resources.Memory); val != "" {
|
if val := numToStr(cgroup.Resources.Memory); val != "" {
|
||||||
|
|
|
@ -39,12 +39,12 @@ func genV2ResourcesProperties(c *configs.Cgroup) ([]systemdDbus.Property, error)
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
newProp("MemoryMax", uint64(c.Resources.Memory)))
|
newProp("MemoryMax", uint64(c.Resources.Memory)))
|
||||||
}
|
}
|
||||||
|
// swap is set
|
||||||
swap, err := cgroups.ConvertMemorySwapToCgroupV2Value(c.Resources.MemorySwap, c.Resources.Memory)
|
if c.Resources.MemorySwap != 0 {
|
||||||
if err != nil {
|
swap, err := cgroups.ConvertMemorySwapToCgroupV2Value(c.Resources.MemorySwap, c.Resources.Memory)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
if swap > 0 {
|
}
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
newProp("MemorySwapMax", uint64(swap)))
|
newProp("MemorySwapMax", uint64(swap)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -639,7 +639,7 @@ func ConvertMemorySwapToCgroupV2Value(memorySwap, memory int64) (int64, error) {
|
||||||
return 0, fmt.Errorf("invalid memory value: %d", memory)
|
return 0, fmt.Errorf("invalid memory value: %d", memory)
|
||||||
}
|
}
|
||||||
if memorySwap < memory {
|
if memorySwap < memory {
|
||||||
return 0, errors.New("memory+swap limit should be > memory limit")
|
return 0, errors.New("memory+swap limit should be >= memory limit")
|
||||||
}
|
}
|
||||||
|
|
||||||
return memorySwap - memory, nil
|
return memorySwap - memory, nil
|
||||||
|
|
Loading…
Reference in New Issue