Skip to content

let runc disable swap in cgroup v2#2370

Merged
mrunalp merged 1 commit into
opencontainers:masterfrom
lifubang:swap0
May 4, 2020
Merged

let runc disable swap in cgroup v2#2370
mrunalp merged 1 commit into
opencontainers:masterfrom
lifubang:swap0

Conversation

@lifubang
Copy link
Copy Markdown
Member

@lifubang lifubang commented May 1, 2020

fix #2369

I think we should let cgroup fs/systemd driver can use 0 to disable memory swap in cgroup v2.

Signed-off-by: lifubang lifubang@acmcoder.com

@lifubang lifubang force-pushed the swap0 branch 2 times, most recently from 1f6b8a5 to b857d40 Compare May 1, 2020 23:47
Comment thread libcontainer/cgroups/fs2/memory.go Outdated
}
if val := numToStr(swap); val != "" {
// When we set `swap`, we should let us set `memory.swap.max` to 0
if swap == 0 && cgroup.Resources.MemorySwap > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the comment to something like

// memory and memorySwap set to the same value -- disable swap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and rewrite the whole block to avoid mentioning fscommon.WriteFile(dirPath, "memory.swap.max" twice.

For example

swapStr := numToStr(swap)
if swapStr == "" && swap == 0 && cgroup.Resources.MemorySwap > 0 {
  // 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
}

Comment thread libcontainer/cgroups/systemd/v2.go Outdated
}
if swap > 0 {
// When we set `swap`, we should let us set `MemorySwapMax` to 0
if (c.Resources.MemorySwap > 0 && swap >= 0) || swap == -1 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do

if (c.Resources.MemorySwap != 0) { // limit is setswap, err := cgroups.ConvertMemorySwapToCgroupV2Value(c.Resources.MemorySwap, c.Resources.Memory)
	if err != nil {
		return nil, err
	}
  properties = append(properties,
			newProp("MemorySwapMax", uint64(swap)))
	}
}

@kolyshkin
Copy link
Copy Markdown
Contributor

The commit should also include

-                return 0, errors.New("memory+swap limit should be > memory limit")
+                return 0, errors.New("memory+swap limit should be >= memory limit")

@kolyshkin
Copy link
Copy Markdown
Contributor

and if you can copy-paste the description from #2369 into the commit message, so it would be possible to find out what's going out by just reading git log, without going to github, that'd be great!

@kolyshkin kolyshkin changed the title let runc can disable memory swap in cgroup v2 let runc disable swap in cgroup v2 May 2, 2020
In cgroup v2, when memory and memorySwap set to the same value which is greater than zero,
runc should write zero in `memory.swap.max` to disable swap.

Signed-off-by: lifubang <lifubang@acmcoder.com>
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin
Copy link
Copy Markdown
Contributor

kolyshkin commented May 4, 2020

LGTM, pullapprove ;)

Approved with PullApprove

@kolyshkin
Copy link
Copy Markdown
Contributor

@AkihiroSuda @mrunalp PTAL

@mrunalp
Copy link
Copy Markdown
Contributor

mrunalp commented May 4, 2020

LGTM

Approved with PullApprove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cgroup2: can't set memory.swap.max to 0

3 participants