2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
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"
|
2018-05-19 07:38:54 -04:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
func toContainerdResources(resources container.Resources) *libcontainerd.Resources {
|
2016-03-18 14:50:19 -04:00
|
|
|
var r libcontainerd.Resources
|
2017-09-22 09:52:41 -04:00
|
|
|
|
|
|
|
r.BlockIO = &specs.LinuxBlockIO{
|
|
|
|
Weight: &resources.BlkioWeight,
|
|
|
|
}
|
|
|
|
|
|
|
|
shares := uint64(resources.CPUShares)
|
|
|
|
r.CPU = &specs.LinuxCPU{
|
|
|
|
Shares: &shares,
|
|
|
|
Cpus: resources.CpusetCpus,
|
|
|
|
Mems: resources.CpusetMems,
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
period uint64
|
|
|
|
quota int64
|
|
|
|
)
|
2017-02-18 01:04:37 -05:00
|
|
|
if resources.NanoCPUs != 0 {
|
2017-09-22 09:52:41 -04:00
|
|
|
period = uint64(100 * time.Millisecond / time.Microsecond)
|
|
|
|
quota = resources.NanoCPUs * int64(period) / 1e9
|
2017-02-18 01:04:37 -05:00
|
|
|
}
|
2018-01-16 11:35:04 -05:00
|
|
|
if quota == 0 && resources.CPUQuota != 0 {
|
|
|
|
quota = resources.CPUQuota
|
|
|
|
}
|
|
|
|
if period == 0 && resources.CPUPeriod != 0 {
|
|
|
|
period = uint64(resources.CPUPeriod)
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
r.CPU.Period = &period
|
|
|
|
r.CPU.Quota = "a
|
|
|
|
|
|
|
|
r.Memory = &specs.LinuxMemory{
|
|
|
|
Limit: &resources.Memory,
|
|
|
|
Reservation: &resources.MemoryReservation,
|
|
|
|
Kernel: &resources.KernelMemory,
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
if resources.MemorySwap > 0 {
|
2017-09-22 09:52:41 -04:00
|
|
|
r.Memory.Swap = &resources.MemorySwap
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2017-09-22 09:52:41 -04:00
|
|
|
|
|
|
|
return &r
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|