Skip to content
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

Fix systemd full path #221

Merged
merged 1 commit into from
Feb 21, 2022
Merged

Conversation

sparrc
Copy link
Contributor

@sparrc sparrc commented Feb 17, 2022

This PR fixes systemd managers to consider the special "-" character when creating a cgroup slice with the systemd cgroup driver.

Before this change, a simple program like below would fail because the manager was not correctly setting up the Manager.path variable.

package main

import (
	"log"

	v2 "github.com/containerd/cgroups/v2"
)

func main() {
	res := v2.Resources{}
	m, err := v2.NewSystemd("/", "my-foo-group.slice", -1, &res)
	if err != nil {
		log.Fatalf("%s", err)
	}

	controllers, err := m.Controllers()
	if err != nil {
		log.Fatalf("%s", err)
	}

	log.Printf("%v", controllers)
}

Before this change, this program would fail with the following error message:

# go run ./cmd/testload/main.go
2022/02/17 18:18:41 open /sys/fs/cgroup/my-foo-group.slice/cgroup.controllers: no such file or directory
exit status 1

The issue here is that m.Controllers() is looking in the wrong path. This slice does actually exist, but at a different path:

# find /sys/fs/cgroup/ -type d | grep "my-foo-group"
/sys/fs/cgroup/my.slice/my-foo.slice/my-foo-group.slice

After this change, NewSystemd (and LoadSystemd) will correctly set the path variable and the m.Controllers() function works correctly:

# go run ./cmd/testload/main.go
2022/02/17 18:22:17 [io memory pids]

@estesp
Copy link
Member

estesp commented Feb 17, 2022

Seems like we have a new intermittent issue with either tests hanging or something with CI cleanup on the vagrant-executed v2 suite. It's happening on a few other PRs as well.

Comment on lines +704 to +709
// getSystemdFullPath returns the full systemd path when creating a systemd slice group.
// the reason this is necessary is because the "-" character has a special meaning in
// systemd slice. For example, when creating a slice called "my-group-112233.slice",
// systemd will create a hierarchy like this:
// /sys/fs/cgroup/my.slice/my-group.slice/my-group-112233.slice
func getSystemdFullPath(slice, group string) string {
Copy link
Member

Choose a reason for hiding this comment

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

Do you know the corresponding code in systemd? Is it documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try to find documentation from systemd itself and look thru the code. What I have so far is just observation that this is what the resulting cgroup path created by NewSystemd is, and this doc from redhat, which states:

Service, scope, and slice units directly map to objects in the cgroup tree. When these units are activated, they map directly to cgroup paths built from the unit names. For example, the ex.service residing in the test-waldo.slice is mapped to the cgroup test.slice/test-waldo.slice/ex.service/.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, the docker run command also appears to understand this "-" notation when specified by the --cgroup-parent flag, though I suppose similar to here it's because the parsing is passed off to systemd itself.

% docker run -d --rm --name test2 --cgroup-parent "my-foo-group.slice" debian:stable-slim sleep 1000
ae96786b7f24e7d469be36c44cdb48bf913b33dc10ed3095c6249b380b1a5699

% find /sys/fs/cgroup | grep my-foo-group | grep ae96786b7f24e7
/sys/fs/cgroup/my.slice/my-foo.slice/my-foo-group.slice/docker-ae96786b7f24e7d469be36c44cdb48bf913b33dc10ed3095c6249b380b1a5699.scope
/sys/fs/cgroup/my.slice/my-foo.slice/my-foo-group.slice/docker-ae96786b7f24e7d469be36c44cdb48bf913b33dc10ed3095c6249b380b1a5699.scope/cgroup.events
/sys/fs/cgroup/my.slice/my-foo.slice/my-foo-group.slice/docker-ae96786b7f24e7d469be36c44cdb48bf913b33dc10ed3095c6249b380b1a5699.scope/memory.events

...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the systemd.slice man page does have some (albeit sparse) information about this: https://www.freedesktop.org/software/systemd/man/systemd.slice.html

@estesp
Copy link
Member

estesp commented Feb 18, 2022

Can you try rebasing this patch on current HEAD and see if CI will pass? Thanks!

Signed-off-by: Cameron Sparr <sparrc@users.noreply.github.com>
@sparrc
Copy link
Contributor Author

sparrc commented Feb 18, 2022

Can you try rebasing this patch on current HEAD and see if CI will pass? Thanks!

done, looks like it worked 👍

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

@estesp estesp merged commit e710ed6 into containerd:main Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants