Separating cgroup Memory and MemoryReservation.
This will allow for these to be set independently. Keep the current Docker behavior where Memory and MemoryReservation are set to the value of Memory. Docker-DCO-1.1-Signed-off-by: Victor Marmol <vmarmol@google.com> (github: vmarmol)
This commit is contained in:
parent
7ff609f95d
commit
bcfc527abb
3 changed files with 18 additions and 10 deletions
|
@ -12,13 +12,14 @@ type Cgroup struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Parent string `json:"parent,omitempty"`
|
Parent string `json:"parent,omitempty"`
|
||||||
|
|
||||||
DeviceAccess bool `json:"device_access,omitempty"` // name of parent cgroup or slice
|
DeviceAccess bool `json:"device_access,omitempty"` // name of parent cgroup or slice
|
||||||
Memory int64 `json:"memory,omitempty"` // Memory limit (in bytes)
|
Memory int64 `json:"memory,omitempty"` // Memory limit (in bytes)
|
||||||
MemorySwap int64 `json:"memory_swap,omitempty"` // Total memory usage (memory + swap); set `-1' to disable swap
|
MemoryReservation int64 `json:"memory_reservation,omitempty"` // Memory reservation or soft_limit (in bytes)
|
||||||
CpuShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight vs. other containers)
|
MemorySwap int64 `json:"memory_swap,omitempty"` // Total memory usage (memory + swap); set `-1' to disable swap
|
||||||
CpuQuota int64 `json:"cpu_quota,omitempty"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
|
CpuShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight vs. other containers)
|
||||||
CpuPeriod int64 `json:"cpu_period,omitempty"` // CPU period to be used for hardcapping (in usecs). 0 to use system default.
|
CpuQuota int64 `json:"cpu_quota,omitempty"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
|
||||||
CpusetCpus string `json:"cpuset_cpus,omitempty"` // CPU to use
|
CpuPeriod int64 `json:"cpu_period,omitempty"` // CPU period to be used for hardcapping (in usecs). 0 to use system default.
|
||||||
|
CpusetCpus string `json:"cpuset_cpus,omitempty"` // CPU to use
|
||||||
|
|
||||||
UnitProperties [][2]string `json:"unit_properties,omitempty"` // systemd unit properties
|
UnitProperties [][2]string `json:"unit_properties,omitempty"` // systemd unit properties
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ type memoryGroup struct {
|
||||||
func (s *memoryGroup) Set(d *data) error {
|
func (s *memoryGroup) Set(d *data) error {
|
||||||
dir, err := d.join("memory")
|
dir, err := d.join("memory")
|
||||||
// only return an error for memory if it was not specified
|
// only return an error for memory if it was not specified
|
||||||
if err != nil && (d.c.Memory != 0 || d.c.MemorySwap != 0) {
|
if err != nil && (d.c.Memory != 0 || d.c.MemoryReservation != 0 || d.c.MemorySwap != 0) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -22,12 +22,15 @@ func (s *memoryGroup) Set(d *data) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if d.c.Memory != 0 || d.c.MemorySwap != 0 {
|
// Only set values if some config was specified.
|
||||||
|
if d.c.Memory != 0 || d.c.MemoryReservation != 0 || d.c.MemorySwap != 0 {
|
||||||
if d.c.Memory != 0 {
|
if d.c.Memory != 0 {
|
||||||
if err := writeFile(dir, "memory.limit_in_bytes", strconv.FormatInt(d.c.Memory, 10)); err != nil {
|
if err := writeFile(dir, "memory.limit_in_bytes", strconv.FormatInt(d.c.Memory, 10)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := writeFile(dir, "memory.soft_limit_in_bytes", strconv.FormatInt(d.c.Memory, 10)); err != nil {
|
}
|
||||||
|
if d.c.MemoryReservation != 0 {
|
||||||
|
if err := writeFile(dir, "memory.soft_limit_in_bytes", strconv.FormatInt(d.c.MemoryReservation, 10)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,10 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
systemd1.Property{"MemoryLimit", dbus.MakeVariant(uint64(c.Memory))})
|
systemd1.Property{"MemoryLimit", dbus.MakeVariant(uint64(c.Memory))})
|
||||||
}
|
}
|
||||||
|
if c.MemoryReservation != 0 {
|
||||||
|
properties = append(properties,
|
||||||
|
systemd1.Property{"MemorySoftLimit", dbus.MakeVariant(uint64(c.MemoryReservation))})
|
||||||
|
}
|
||||||
// TODO: MemorySwap not available in systemd
|
// TODO: MemorySwap not available in systemd
|
||||||
|
|
||||||
if c.CpuShares != 0 {
|
if c.CpuShares != 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue