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 lxcfs cpuinfo #8419

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions enterprise/server/cmd/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func setupCgroups() (string, error) {
}
log.Infof("Set up task cgroup at %s", taskCgroupPath)

// Enable the same controllers for the child cgroups that were enabled
// for the starting cgroup.
if err := cgroup.DelegateControllers(filepath.Join(cgroup.RootPath, startingCgroup)); err != nil {
return "", fmt.Errorf("inherit subtree control: %w", err)
}

taskCgroupRelpath := filepath.Join(startingCgroup, taskCgroupName)
return taskCgroupRelpath, nil
}
Expand Down
24 changes: 19 additions & 5 deletions enterprise/server/remote_execution/cgroup/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Setup(ctx context.Context, path string, s *scpb.CgroupSettings, blockDevice
if len(m) == 0 {
return nil
}
enabledControllers, err := ParentEnabledControllers(path)
enabledControllers, err := EnabledControllers(path)
if err != nil {
return fmt.Errorf("read enabled controllers: %w", err)
}
Expand All @@ -99,10 +99,10 @@ func Setup(ctx context.Context, path string, s *scpb.CgroupSettings, blockDevice
return nil
}

// ParentEnabledControllers returns the cgroup controllers that are enabled for
// the parent cgroup of a given cgroup.
func ParentEnabledControllers(path string) (map[string]bool, error) {
b, err := os.ReadFile(filepath.Join(path, "..", "cgroup.subtree_control"))
// EnabledControllers returns the controllers enabled for the cgroup at the
// given absolute path.
func EnabledControllers(path string) (map[string]bool, error) {
Comment on lines +102 to +104
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is not strictly needed but I realized this function name and documentation are misleading. ../cgroup.subtree_control returns the set of cgroup controllers that are enabled for children of the parent cgroup, not the controllers enabled for the parent cgroup itself. So it should really be called "EnabledControllers" not "ParentEnabledControllers." Also it's probably clearer to read ./cgroup.controllers rather than ../cgroup.subtree_control, even though (iiuc) they should always return the same set of controllers.

b, err := os.ReadFile(filepath.Join(path, "cgroup.controllers"))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -133,6 +133,20 @@ func WriteSubtreeControl(path string, settings map[string]bool) error {
return os.WriteFile(filepath.Join(path, "cgroup.subtree_control"), b, 0)
}

// DelegateControllers reads the currently enabled controllers for the given
// cgroup absolute path and makes those controllers available to child cgroups
// by writing to the "cgroup.subtree_control" file.
func DelegateControllers(path string) error {
controllers, err := EnabledControllers(path)
if err != nil {
return fmt.Errorf("read enabled controllers for %q: %w", path, err)
}
if err := WriteSubtreeControl(path, controllers); err != nil {
return fmt.Errorf("write cgroup.subtree_control for %q: %w", path, err)
}
return nil
}

func settingsMap(s *scpb.CgroupSettings, blockDevice *block_io.Device) (map[string]string, error) {
m := map[string]string{}
if s == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,10 @@ func (c *ociContainer) setupCgroup(ctx context.Context) error {
if err := os.MkdirAll(path, 0755); err != nil {
return fmt.Errorf("create cgroup: %w", err)
}
// Before setting up the container cgroup we need to enable subtree
// controllers on the parent cgroup. For now we inherit the enabled
// controllers from the parent of the parent.
parentPath := filepath.Dir(path)
controllers, err := cgroup.ParentEnabledControllers(parentPath)
if err != nil {
return fmt.Errorf("read enabled controllers for parent of %q: %w", parentPath, err)
}
if err := cgroup.WriteSubtreeControl(parentPath, controllers); err != nil {
return fmt.Errorf("write cgroup.subtree_control for %q: %w", parentPath, err)
// Propagate enabled controllers to the child cgroup before performing
// cgroup setup.
if err := cgroup.DelegateControllers(filepath.Dir(path)); err != nil {
return fmt.Errorf("delegate controllers: %w", err)
}
if err := cgroup.Setup(ctx, path, c.cgroupSettings, c.blockDevice); err != nil {
return fmt.Errorf("configure cgroup: %w", err)
Expand Down