Unify behavior for memory cgroup
We have a rule that for optional cgroups, don't fail if some of them are not mounted, but we want it fail hard when a user specifies an option and we are unable to fulfill the request. Memory cgroup should also follow this rule. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
3be7f87b1b
commit
194e0e4db6
|
@ -19,15 +19,20 @@ type MemoryGroup struct {
|
||||||
|
|
||||||
func (s *MemoryGroup) Apply(d *data) (err error) {
|
func (s *MemoryGroup) Apply(d *data) (err error) {
|
||||||
path, err := d.path("memory")
|
path, err := d.path("memory")
|
||||||
if err != nil {
|
if err != nil && !cgroups.IsNotFound(err) {
|
||||||
if cgroups.IsNotFound(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if memoryAssigned(d.c) {
|
||||||
|
if path != "" {
|
||||||
if err := os.MkdirAll(path, 0755); err != nil {
|
if err := os.MkdirAll(path, 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.Set(path, d.c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,13 +40,10 @@ func (s *MemoryGroup) Apply(d *data) (err error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := s.Set(path, d.c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to join memory cgroup after set memory limits, because
|
// We need to join memory cgroup after set memory limits, because
|
||||||
// kmem.limit_in_bytes can only be set when the cgroup is empty.
|
// kmem.limit_in_bytes can only be set when the cgroup is empty.
|
||||||
if _, err = d.join("memory"); err != nil {
|
_, err = d.join("memory")
|
||||||
|
if err != nil && !cgroups.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +134,15 @@ func (s *MemoryGroup) GetStats(path string, stats *cgroups.Stats) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func memoryAssigned(cgroup *configs.Cgroup) bool {
|
||||||
|
return cgroup.Memory != 0 ||
|
||||||
|
cgroup.MemoryReservation != 0 ||
|
||||||
|
cgroup.MemorySwap > 0 ||
|
||||||
|
cgroup.KernelMemory > 0 ||
|
||||||
|
cgroup.OomKillDisable ||
|
||||||
|
cgroup.MemorySwappiness != -1
|
||||||
|
}
|
||||||
|
|
||||||
func getMemoryData(path, name string) (cgroups.MemoryData, error) {
|
func getMemoryData(path, name string) (cgroups.MemoryData, error) {
|
||||||
memoryData := cgroups.MemoryData{}
|
memoryData := cgroups.MemoryData{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue