github.com/skanehira/moby@v17.12.1-ce-rc2+incompatible/daemon/update_linux.go (about)

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