Skip to content

Commit

Permalink
Fixup memcg check for cgroupv2 & don't use memcgSwap if memcg is unav…
Browse files Browse the repository at this point in the history
…ailable

Fixes kubernetes#10935
  • Loading branch information
ojab committed Mar 27, 2021
1 parent 02bd568 commit a3b12cd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func HasMemoryCgroup() bool {
if runtime.GOOS == "linux" {
var memory string
if cgroup2, err := IsCgroup2UnifiedMode(); err == nil && cgroup2 {
memory = "/sys/fs/cgroup/memory/memsw.limit_in_bytes"
memory = "/sys/fs/cgroup/memory/memory.high"
}
if _, err := os.Stat(memory); os.IsNotExist(err) {
klog.Warning("Your kernel does not support memory limit capabilities or the cgroup is not mounted.")
Expand All @@ -124,6 +124,10 @@ func HasMemoryCgroup() bool {
}

func hasMemorySwapCgroup() bool {
if !HasMemoryCgroup() {
return false
}

memcgSwap := true
if runtime.GOOS == "linux" {
var memoryswap string
Expand Down Expand Up @@ -193,14 +197,14 @@ func CreateContainerNode(p CreateParams) error {
// podman mounts var/lib with no-exec by default https://github.com/containers/libpod/issues/5103
runArgs = append(runArgs, "--volume", fmt.Sprintf("%s:/var:exec", p.Name))

if memcgSwap {
runArgs = append(runArgs, fmt.Sprintf("--memory-swap=%s", p.Memory))
}

if memcg {
runArgs = append(runArgs, fmt.Sprintf("--memory=%s", p.Memory))
}

if memcgSwap {
runArgs = append(runArgs, fmt.Sprintf("--memory-swap=%s", p.Memory))
}

virtualization = "podman" // VIRTUALIZATION_PODMAN
}
if p.OCIBinary == Docker {
Expand Down

0 comments on commit a3b12cd

Please sign in to comment.