MCPcopy Create free account
hub / github.com/containerd/cgroups / NewSystemd

Function NewSystemd

cgroup2/manager.go:944–1043  ·  view source on GitHub ↗
(slice, group string, pid int, resources *Resources)

Source from the content-addressed store, hash-verified

942}
943
944func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, error) {
945 if slice == "" {
946 slice = defaultSlice
947 }
948 ctx := context.TODO()
949 path := getSystemdFullPath(slice, group)
950 conn, err := systemdDbus.NewWithContext(ctx)
951 if err != nil {
952 return &Manager{}, err
953 }
954 defer conn.Close()
955
956 properties := []systemdDbus.Property{
957 systemdDbus.PropDescription("cgroup " + group),
958 newSystemdProperty("DefaultDependencies", false),
959 newSystemdProperty("MemoryAccounting", true),
960 newSystemdProperty("CPUAccounting", true),
961 newSystemdProperty("IOAccounting", true),
962 }
963
964 // if we create a slice, the parent is defined via a Wants=
965 if strings.HasSuffix(group, ".slice") {
966 properties = append(properties, systemdDbus.PropWants(defaultSlice))
967 } else {
968 // otherwise, we use Slice=
969 properties = append(properties, systemdDbus.PropSlice(defaultSlice))
970 }
971
972 // only add pid if its valid, -1 is used w/ general slice creation.
973 if pid != -1 {
974 properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
975 }
976
977 if resources.Memory != nil && resources.Memory.Min != nil && *resources.Memory.Min != 0 {
978 properties = append(properties,
979 newSystemdProperty("MemoryMin", uint64(*resources.Memory.Min)))
980 }
981
982 if resources.Memory != nil && resources.Memory.Max != nil && *resources.Memory.Max != 0 {
983 properties = append(properties,
984 newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))
985 }
986
987 if resources.CPU != nil && resources.CPU.Weight != nil && *resources.CPU.Weight != 0 {
988 properties = append(properties,
989 newSystemdProperty("CPUWeight", *resources.CPU.Weight))
990 }
991
992 if resources.CPU != nil && resources.CPU.Max != "" {
993 quota, period, err := resources.CPU.Max.extractQuotaAndPeriod()
994 if err != nil {
995 return &Manager{}, err
996 }
997
998 if period != 0 {
999 if sdVer := systemdVersion(conn); sdVer >= cpuQuotaPeriodUSecSupportedVersion {
1000 properties = append(properties, newSystemdProperty("CPUQuotaPeriodUSec", period))
1001 } else {

Calls 5

getSystemdFullPathFunction · 0.85
newSystemdPropertyFunction · 0.85
systemdVersionFunction · 0.85
startUnitFunction · 0.85
extractQuotaAndPeriodMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…