Skip to content

Commit

Permalink
Add cgroup type for cgroup v2
Browse files Browse the repository at this point in the history
Add domain threaded and domain invalid cgroup type for cgroup v2.

Signed-off-by: yaoyinnan <[email protected]>
  • Loading branch information
yaoyinnan committed Jan 27, 2024
1 parent d131035 commit bdc9913
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cgroup2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ func setResources(path string, resources *Resources) error {
type CgroupType string

const (
Domain CgroupType = "domain"
Threaded CgroupType = "threaded"
Domain CgroupType = "domain"
DomainThreaded CgroupType = "domain threaded"
DomainInvalid CgroupType = "domain invalid"
Threaded CgroupType = "threaded"
)

func (c *Manager) GetType() (CgroupType, error) {
Expand Down
32 changes: 26 additions & 6 deletions cgroup2/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,40 @@ func TestCgroupType(t *testing.T) {
checkCgroupMode(t)
manager, err := NewManager(defaultCgroup2Path, "/test-type", ToResources(&specs.LinuxResources{}))
require.NoError(t, err)
t.Cleanup(func() {
_ = manager.Delete()
})
submanager, err := NewManager(defaultCgroup2Path, "/test-type/sub", ToResources(&specs.LinuxResources{}))
require.NoError(t, err)

// Check initial type is domain
cgType, err := manager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, Domain)

// Swap to threaded
require.NoError(t, manager.SetType(Threaded))
// Swap sub cgroup to threaded
require.NoError(t, submanager.SetType(Threaded))

cgType, err = manager.GetType()
// Check sub cgroup type is threaded
cgType, err = submanager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, Threaded)

// Check parent cgroup type is domain threaded
cgType, err = manager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, DomainThreaded)

subsubmanager, err := NewManager(defaultCgroup2Path, "/test-type/sub/sub", ToResources(&specs.LinuxResources{}))
require.NoError(t, err)

// Check sub cgroup type is domain invalid
cgType, err = submanager.GetType()
require.NoError(t, err)
require.Equal(t, cgType, DomainInvalid)

t.Cleanup(func() {
_ = subsubmanager.Delete()
_ = submanager.Delete()
_ = manager.Delete()
})
}

func TestCgroupv2PSIStats(t *testing.T) {
Expand Down

0 comments on commit bdc9913

Please sign in to comment.