Description
// ToResources converts the oci LinuxResources struct into a
// v2 Resources type for use with this package.
//
// converting cgroups configuration from v1 to v2
// ref: https://github.com/containers/crun/blob/master/crun.1.md#cgroup-v2
func ToResources (spec * specs.LinuxResources ) * Resources {
var resources Resources
if cpu := spec .CPU ; cpu != nil {
resources .CPU = & CPU {
Cpus : cpu .Cpus ,
Mems : cpu .Mems ,
}
if shares := cpu .Shares ; shares != nil {
convertedWeight := 1 + ((* shares - 2 )* 9999 )/ 262142
resources .CPU .Weight = & convertedWeight
}
if period := cpu .Period ; period != nil {
resources .CPU .Max = NewCPUMax (cpu .Quota , period )
}
}
if mem := spec .Memory ; mem != nil {
resources .Memory = & Memory {}
if swap := mem .Swap ; swap != nil {
resources .Memory .Swap = swap
}
if l := mem .Limit ; l != nil {
resources .Memory .Max = l
}
if l := mem .Reservation ; l != nil {
resources .Memory .Low = l
}
}
if hugetlbs := spec .HugepageLimits ; hugetlbs != nil {
Reactions are currently unavailable
You can’t perform that action at this time.
cgroups/cgroup2/utils.go
Lines 155 to 187 in a0ae1c2