• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H14-Jan-2021-126108

cmd/cgctl/H14-Jan-2021-221192

stats/v1/H14-Jan-2021-6,1635,996

v2/H14-Jan-2021-6,7505,938

.gitignoreH A D14-Jan-202132 32

LICENSEH A D14-Jan-202111.1 KiB202169

MakefileH A D14-Jan-2021755 257

Protobuild.tomlH A D14-Jan-20211.8 KiB4741

README.mdH A D14-Jan-20213.8 KiB150106

VagrantfileH A D14-Jan-20211.1 KiB4741

blkio.goH A D14-Jan-20218.1 KiB359302

blkio_test.goH A D14-Jan-20213 KiB10576

cgroup.goH A D14-Jan-202112 KiB553477

cgroup_test.goH A D14-Jan-20219.2 KiB438400

control.goH A D14-Jan-20213.3 KiB9339

cpu.goH A D14-Jan-20212.8 KiB12699

cpuacct.goH A D14-Jan-20212.8 KiB12496

cpuset.goH A D14-Jan-20213.8 KiB160125

devices.goH A D14-Jan-20212.1 KiB9365

errors.goH A D14-Jan-20211.5 KiB4824

freezer.goH A D14-Jan-20211.9 KiB8356

go.modH A D14-Jan-2021519 1916

go.sumH A D14-Jan-20213.9 KiB4544

hierarchy.goH A D14-Jan-2021722 212

hugetlb.goH A D14-Jan-20212.4 KiB11083

memory.goH A D14-Jan-202113.4 KiB481376

memory_test.goH A D14-Jan-20217.5 KiB293242

mock_test.goH A D14-Jan-20211.7 KiB7955

named.goH A D14-Jan-2021976 4018

named_test.goH A D14-Jan-20211 KiB3515

net_cls.goH A D14-Jan-20211.6 KiB6237

net_prio.goH A D14-Jan-20211.6 KiB6641

opts.goH A D14-Jan-20211.8 KiB6227

paths.goH A D14-Jan-20212.7 KiB10873

paths_test.goH A D14-Jan-20213.5 KiB144119

perf_event.goH A D14-Jan-2021985 3816

pids.goH A D14-Jan-20212.1 KiB8761

pids_test.goH A D14-Jan-20213.9 KiB174151

rdma.goH A D14-Jan-20213.6 KiB155114

state.goH A D14-Jan-2021841 299

subsystem.goH A D14-Jan-20212.4 KiB11784

systemd.goH A D14-Jan-20213.8 KiB156116

testutil_test.goH A D14-Jan-2021821 3111

ticks.goH A D14-Jan-2021887 274

utils.goH A D14-Jan-20218.7 KiB405333

v1.goH A D14-Jan-20211.8 KiB7450

README.md

1# cgroups
2
3[![Build Status](https://github.com/containerd/cgroups/workflows/CI/badge.svg)](https://github.com/containerd/cgroups/actions?query=workflow%3ACI)
4[![codecov](https://codecov.io/gh/containerd/cgroups/branch/master/graph/badge.svg)](https://codecov.io/gh/containerd/cgroups)
5[![GoDoc](https://godoc.org/github.com/containerd/cgroups?status.svg)](https://godoc.org/github.com/containerd/cgroups)
6[![Go Report Card](https://goreportcard.com/badge/github.com/containerd/cgroups)](https://goreportcard.com/report/github.com/containerd/cgroups)
7
8Go package for creating, managing, inspecting, and destroying cgroups.
9The resources format for settings on the cgroup uses the OCI runtime-spec found
10[here](https://github.com/opencontainers/runtime-spec).
11
12## Examples
13
14### Create a new cgroup
15
16This creates a new cgroup using a static path for all subsystems under `/test`.
17
18* /sys/fs/cgroup/cpu/test
19* /sys/fs/cgroup/memory/test
20* etc....
21
22It uses a single hierarchy and specifies cpu shares as a resource constraint and
23uses the v1 implementation of cgroups.
24
25
26```go
27shares := uint64(100)
28control, err := cgroups.New(cgroups.V1, cgroups.StaticPath("/test"), &specs.LinuxResources{
29    CPU: &specs.CPU{
30        Shares: &shares,
31    },
32})
33defer control.Delete()
34```
35
36### Create with systemd slice support
37
38
39```go
40control, err := cgroups.New(cgroups.Systemd, cgroups.Slice("system.slice", "runc-test"), &specs.LinuxResources{
41    CPU: &specs.CPU{
42        Shares: &shares,
43    },
44})
45
46```
47
48### Load an existing cgroup
49
50```go
51control, err = cgroups.Load(cgroups.V1, cgroups.StaticPath("/test"))
52```
53
54### Add a process to the cgroup
55
56```go
57if err := control.Add(cgroups.Process{Pid:1234}); err != nil {
58}
59```
60
61###  Update the cgroup
62
63To update the resources applied in the cgroup
64
65```go
66shares = uint64(200)
67if err := control.Update(&specs.LinuxResources{
68    CPU: &specs.LinuxCPU{
69        Shares: &shares,
70    },
71}); err != nil {
72}
73```
74
75### Freeze and Thaw the cgroup
76
77```go
78if err := control.Freeze(); err != nil {
79}
80if err := control.Thaw(); err != nil {
81}
82```
83
84### List all processes in the cgroup or recursively
85
86```go
87processes, err := control.Processes(cgroups.Devices, recursive)
88```
89
90### Get Stats on the cgroup
91
92```go
93stats, err := control.Stat()
94```
95
96By adding `cgroups.IgnoreNotExist` all non-existent files will be ignored, e.g. swap memory stats without swap enabled
97```go
98stats, err := control.Stat(cgroups.IgnoreNotExist)
99```
100
101### Move process across cgroups
102
103This allows you to take processes from one cgroup and move them to another.
104
105```go
106err := control.MoveTo(destination)
107```
108
109### Create subcgroup
110
111```go
112subCgroup, err := control.New("child", resources)
113```
114
115### Registering for memory events
116
117This allows you to get notified by an eventfd for v1 memory cgroups events.
118
119```go
120event := cgroups.MemoryThresholdEvent(50 * 1024 * 1024, false)
121efd, err := control.RegisterMemoryEvent(event)
122```
123
124```go
125event := cgroups.MemoryPressureEvent(cgroups.MediumPressure, cgroups.DefaultMode)
126efd, err := control.RegisterMemoryEvent(event)
127```
128
129```go
130efd, err := control.OOMEventFD()
131// or by using RegisterMemoryEvent
132event := cgroups.OOMEvent()
133efd, err := control.RegisterMemoryEvent(event)
134```
135
136### Attention
137
138All static path should not include `/sys/fs/cgroup/` prefix, it should start with your own cgroups name
139
140## Project details
141
142Cgroups is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE).
143As a containerd sub-project, you will find the:
144
145 * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md),
146 * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS),
147 * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md)
148
149information in our [`containerd/project`](https://github.com/containerd/project) repository.
150