Skip to content

Commit

Permalink
Fix lxcfs cpuinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bduffany committed Feb 17, 2025
1 parent dec92d0 commit 04bba50
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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) {
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

0 comments on commit 04bba50

Please sign in to comment.