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"
|
2017-09-22 09:52:41 -04:00
|
|
|
specs "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
|
|
|
}
|
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
|
|
|
}
|