2016-03-18 18:50:19 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-02-18 06:04:37 +00:00
|
|
|
"time"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-03-18 18:50:19 +00:00
|
|
|
"github.com/docker/docker/libcontainerd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func toContainerdResources(resources container.Resources) libcontainerd.Resources {
|
|
|
|
var r libcontainerd.Resources
|
2016-06-09 21:56:14 +00:00
|
|
|
r.BlkioWeight = uint64(resources.BlkioWeight)
|
|
|
|
r.CpuShares = uint64(resources.CPUShares)
|
2017-02-18 06:04:37 +00: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 18:50:19 +00:00
|
|
|
r.CpusetCpus = resources.CpusetCpus
|
|
|
|
r.CpusetMems = resources.CpusetMems
|
2016-06-09 21:56:14 +00:00
|
|
|
r.MemoryLimit = uint64(resources.Memory)
|
2016-03-18 18:50:19 +00:00
|
|
|
if resources.MemorySwap > 0 {
|
2016-06-09 21:56:14 +00:00
|
|
|
r.MemorySwap = uint64(resources.MemorySwap)
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
2016-06-09 21:56:14 +00:00
|
|
|
r.MemoryReservation = uint64(resources.MemoryReservation)
|
|
|
|
r.KernelMemoryLimit = uint64(resources.KernelMemory)
|
2016-03-18 18:50:19 +00:00
|
|
|
return r
|
|
|
|
}
|