github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/update_linux.go (about) 1 package daemon // import "github.com/demonoid81/moby/daemon" 2 3 import ( 4 "time" 5 6 "github.com/demonoid81/moby/api/types/container" 7 libcontainerdtypes "github.com/demonoid81/moby/libcontainerd/types" 8 specs "github.com/opencontainers/runtime-spec/specs-go" 9 ) 10 11 func toContainerdResources(resources container.Resources) *libcontainerdtypes.Resources { 12 var r libcontainerdtypes.Resources 13 14 r.BlockIO = &specs.LinuxBlockIO{ 15 Weight: &resources.BlkioWeight, 16 } 17 18 shares := uint64(resources.CPUShares) 19 r.CPU = &specs.LinuxCPU{ 20 Shares: &shares, 21 Cpus: resources.CpusetCpus, 22 Mems: resources.CpusetMems, 23 } 24 25 var ( 26 period uint64 27 quota int64 28 ) 29 if resources.NanoCPUs != 0 { 30 period = uint64(100 * time.Millisecond / time.Microsecond) 31 quota = resources.NanoCPUs * int64(period) / 1e9 32 } 33 if quota == 0 && resources.CPUQuota != 0 { 34 quota = resources.CPUQuota 35 } 36 if period == 0 && resources.CPUPeriod != 0 { 37 period = uint64(resources.CPUPeriod) 38 } 39 40 r.CPU.Period = &period 41 r.CPU.Quota = "a 42 43 r.Memory = &specs.LinuxMemory{ 44 Limit: &resources.Memory, 45 Reservation: &resources.MemoryReservation, 46 Kernel: &resources.KernelMemory, 47 } 48 49 if resources.MemorySwap > 0 { 50 r.Memory.Swap = &resources.MemorySwap 51 } 52 53 r.Pids = getPidsLimit(resources) 54 return &r 55 }