2016-03-18 14:50:19 -04:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-02-18 01:04:37 -05:00
|
|
|
"time"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-03-18 14:50:19 -04:00
|
|
|
"github.com/docker/docker/libcontainerd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func toContainerdResources(resources container.Resources) libcontainerd.Resources {
|
|
|
|
var r libcontainerd.Resources
|
2016-06-09 17:56:14 -04:00
|
|
|
r.BlkioWeight = uint64(resources.BlkioWeight)
|
|
|
|
r.CpuShares = uint64(resources.CPUShares)
|
2017-02-18 01:04:37 -05:00
|
|
|
if resources.NanoCPUs != 0 {
|
|
|
|
r.CpuPeriod = uint64(100 * time.Millisecond / time.Microsecond)
|
|
|
|
r.CpuQuota = uint64(resources.NanoCPUs) * r.CpuPeriod / 1e9
|
|
|
|
} else {
|
|
|
|
r.CpuPeriod = uint64(resources.CPUPeriod)
|
|
|
|
r.CpuQuota = uint64(resources.CPUQuota)
|
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
r.CpusetCpus = resources.CpusetCpus
|
|
|
|
r.CpusetMems = resources.CpusetMems
|
2016-06-09 17:56:14 -04:00
|
|
|
r.MemoryLimit = uint64(resources.Memory)
|
2016-03-18 14:50:19 -04:00
|
|
|
if resources.MemorySwap > 0 {
|
2016-06-09 17:56:14 -04:00
|
|
|
r.MemorySwap = uint64(resources.MemorySwap)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2016-06-09 17:56:14 -04:00
|
|
|
r.MemoryReservation = uint64(resources.MemoryReservation)
|
|
|
|
r.KernelMemoryLimit = uint64(resources.KernelMemory)
|
2016-03-18 14:50:19 -04:00
|
|
|
return r
|
|
|
|
}
|