@@ -25,7 +25,7 @@ uses the v1 implementation of cgroups.
2525
2626``` go
2727shares := uint64 (100 )
28- control , err := cgroups .New (cgroups. V1 , cgroups .StaticPath (" /test" ), &specs.LinuxResources {
28+ control , err := cgroup1 .New (cgroup1. Default , cgroup1 .StaticPath (" /test" ), &specs.LinuxResources {
2929 CPU : &specs.LinuxCPU {
3030 Shares: &shares,
3131 },
@@ -37,7 +37,7 @@ defer control.Delete()
3737
3838
3939``` go
40- control , err := cgroups .New (cgroups .Systemd , cgroups .Slice (" system.slice" , " runc-test" ), &specs.LinuxResources {
40+ control , err := cgroup1 .New (cgroup1 .Systemd , cgroup1 .Slice (" system.slice" , " runc-test" ), &specs.LinuxResources {
4141 CPU : &specs.CPU {
4242 Shares: &shares,
4343 },
@@ -48,13 +48,13 @@ control, err := cgroups.New(cgroups.Systemd, cgroups.Slice("system.slice", "runc
4848### Load an existing cgroup
4949
5050``` go
51- control, err = cgroups .Load (cgroups. V1 , cgroups.StaticPath (" /test" ))
51+ control, err = cgroup1 .Load (cgroup1. Default , cgroups.StaticPath (" /test" ))
5252```
5353
5454### Add a process to the cgroup
5555
5656``` go
57- if err := control.Add (cgroups .Process {Pid:1234 }); err != nil {
57+ if err := control.Add (cgroup1 .Process {Pid:1234 }); err != nil {
5858}
5959```
6060
@@ -84,7 +84,7 @@ if err := control.Thaw(); err != nil {
8484### List all processes in the cgroup or recursively
8585
8686``` go
87- processes , err := control.Processes (cgroups .Devices , recursive)
87+ processes , err := control.Processes (cgroup1 .Devices , recursive)
8888```
8989
9090### Get Stats on the cgroup
@@ -95,7 +95,7 @@ stats, err := control.Stat()
9595
9696By adding ` cgroups.IgnoreNotExist ` all non-existent files will be ignored, e.g. swap memory stats without swap enabled
9797``` go
98- stats , err := control.Stat (cgroups .IgnoreNotExist )
98+ stats , err := control.Stat (cgroup1 .IgnoreNotExist )
9999```
100100
101101### Move process across cgroups
@@ -117,19 +117,19 @@ subCgroup, err := control.New("child", resources)
117117This allows you to get notified by an eventfd for v1 memory cgroups events.
118118
119119``` go
120- event := cgroups .MemoryThresholdEvent (50 * 1024 * 1024 , false )
120+ event := cgroup1 .MemoryThresholdEvent (50 * 1024 * 1024 , false )
121121efd , err := control.RegisterMemoryEvent (event)
122122```
123123
124124``` go
125- event := cgroups .MemoryPressureEvent (cgroups .MediumPressure , cgroups .DefaultMode )
125+ event := cgroup1 .MemoryPressureEvent (cgroup1 .MediumPressure , cgroup1 .DefaultMode )
126126efd , err := control.RegisterMemoryEvent (event)
127127```
128128
129129``` go
130130efd , err := control.OOMEventFD ()
131131// or by using RegisterMemoryEvent
132- event := cgroups .OOMEvent ()
132+ event := cgroup1 .OOMEvent ()
133133efd , err := control.RegisterMemoryEvent (event)
134134```
135135
@@ -153,14 +153,14 @@ so the resulting slice would be located here on disk:
153153
154154``` go
155155import (
156- cgroupsv2 " github.com/containerd/cgroups/v2"
156+ " github.com/containerd/cgroups/v2/cgroup2 "
157157 specs " github.com/opencontainers/runtime-spec/specs-go"
158158)
159159
160- res := cgroupsv2 .Resources {}
160+ res := cgroup2 .Resources {}
161161// dummy PID of -1 is used for creating a "general slice" to be used as a parent cgroup.
162162// see https://github.com/containerd/cgroups/blob/1df78138f1e1e6ee593db155c6b369466f577651/v2/manager.go#L732-L735
163- m , err := cgroupsv2 .NewSystemd (" /" , " my-cgroup-abc.slice" , -1 , &res)
163+ m , err := cgroup2 .NewSystemd (" /" , " my-cgroup-abc.slice" , -1 , &res)
164164if err != nil {
165165 return err
166166}
@@ -169,7 +169,7 @@ if err != nil {
169169### Load an existing cgroup
170170
171171``` go
172- m , err := cgroupsv2 .LoadSystemd (" /" , " my-cgroup-abc.slice" )
172+ m , err := cgroup2 .LoadSystemd (" /" , " my-cgroup-abc.slice" )
173173if err != nil {
174174 return err
175175}
@@ -178,7 +178,7 @@ if err != nil {
178178### Delete a cgroup
179179
180180``` go
181- m , err := cgroupsv2 .LoadSystemd (" /" , " my-cgroup-abc.slice" )
181+ m , err := cgroup2 .LoadSystemd (" /" , " my-cgroup-abc.slice" )
182182if err != nil {
183183 return err
184184}
0 commit comments