-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgroupv2: don't enable threaded mode by default #2390
Conversation
@AkihiroSuda PTAL |
I'm not sure I understand why we're putting cgroupv2 into threaded mode -- @AkihiroSuda is this to work around some odd permission issue (and why does it fix an |
libcontainer/cgroups/fs2/create.go
Outdated
// Otherwise ENOTSUP may happen. | ||
cgType := filepath.Join(current, "cgroup.type") | ||
_ = ioutil.WriteFile(cgType, []byte("threaded"), 0644) | ||
if rootless { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cgType := filepath.Join(current, "cgroup.type")
cgTypeB, _ := ioutil.ReadFile(cgType)
if strings.TrimSpace(string(cgTypeB)) == "domain invalid" {
_ = ioutil.WriteFile(cgType, []byte("threaded"), 0644)
}
@cyphar $ sudo podman run -it --rm --privileged --runtime=crun alpine
/ # cd /sys/fs/cgroup/
/sys/fs/cgroup # cat cgroup.controllers
cpuset cpu io memory pids
/sys/fs/cgroup # cat cgroup.subtree_control
/sys/fs/cgroup # echo +cpu > cgroup.subtree_control
/sys/fs/cgroup # mkdir foo
/sys/fs/cgroup # cat foo/cgroup.type
domain invalid |
Okay, but "domain invalid" means that the cgroup is in an invalid state (meaning that one of the cgroup rules has been violated -- most likely the no-internal-processes rule). Putting a cgroup into threaded mode doesn't fix that -- it switches it into an alternative mode which only allows controllers which are thread-aware to be enabled (such as cpu). This is why we can't enable the memory controller -- it isn't thread-aware. IMHO, a more complete solution would be to figure out how to deal with the parent cgroup having child processes (which is a bit dodgy if we're going to move other programs on the system between cgroups) or to simply give an error if we hit |
Personally, I prefer this one. @AkihiroSuda WDYT? Because in man7 cgroups:
|
SGTM, but when no domain controller is enabled, we can write "threaded" without retuning error |
fd7d8a4
to
eea6058
Compare
106fdd8
to
7ca4d5a
Compare
libcontainer/cgroups/fs2/create.go
Outdated
if strings.TrimSpace(string(cgType)) == "domain invalid" { | ||
cgTypeParentFile := filepath.Join(current, "../cgroup.type") | ||
cgTypeParent, _ := ioutil.ReadFile(cgTypeParentFile) | ||
if bytes.HasPrefix(cgTypeParent, []byte("domain")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC we don't need to check parent, we just need to check whether the current config contains domain controller
1e97975
to
757bb65
Compare
Line 103 in 1d14356
I think rootless doesn't need threaded mode in default?I don't know whether my opinion is right or not. @AkihiroSuda |
Let's check invalid cgroup.type and set threaded conditionally |
757bb65
to
e0c9737
Compare
tests/rootless.sh
Outdated
echo threaded > "$CGROUP_MOUNT/$CGROUP_PATH/cgroup.type" | ||
if grep -qw invalid "$CGROUP_MOUNT/$CGROUP_PATH/cgroup.type"; then | ||
echo threaded > "$CGROUP_MOUNT/$CGROUP_PATH/cgroup.type" | ||
fi | ||
# Make sure cgroup.type doesn't contain "invalid". Otherwise write ops will fail with ENOTSUP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop L106-L110 now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lifubang ^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been removed before LGTM.
I think we should keep these comments to let other people know why we need to write threaded to cgroups.type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the echo threaded >
still needed? Seems a bit odd to run the entire test suite under threaded
.
e0c9737
to
2aefa92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few minor fixes, otherwise good
2aefa92
to
d6a76d9
Compare
@kolyshkin LGTY? |
Because in threaded mode, we can't enable the memory controller -- it isn't thread-aware. Signed-off-by: lifubang <[email protected]>
d6a76d9
to
fe0669b
Compare
@AkihiroSuda @kolyshkin PTAL |
After this commit: 60c647e
Runc enable
threaded
mode in cgroup v2 by default.If the cgroupPath is set to a absolute path like
/docker/********
, the memory subsystem can't be used by this mode.So, I think we should use
domain
mode by default.Signed-off-by: lifubang [email protected]