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
|
@ -14,6 +14,7 @@ type Cgroup struct {
|
||||||
|
|
||||||
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)
|
||||||
|
MemoryReservation int64 `json:"memory_reservation,omitempty"` // Memory reservation or soft_limit (in bytes)
|
||||||
MemorySwap int64 `json:"memory_swap,omitempty"` // Total memory usage (memory + swap); set `-1' to disable swap
|
MemorySwap int64 `json:"memory_swap,omitempty"` // Total memory usage (memory + swap); set `-1' to disable swap
|
||||||
CpuShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight vs. other containers)
|
CpuShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight vs. other containers)
|
||||||
CpuQuota int64 `json:"cpu_quota,omitempty"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
|
CpuQuota int64 `json:"cpu_quota,omitempty"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
|
||||||
|
|
|
@ -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…
Reference in a new issue