Skip to content

Commit

Permalink
virtcontainers: don't consider non-running container resources
Browse files Browse the repository at this point in the history
Don't hot add again non-running container resources to avoid having extra
and useless resources

fixes kata-containers#2186

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Nov 25, 2019
1 parent 43f0513 commit b7731e9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,12 @@ func (s *Sandbox) updateResources() error {
func (s *Sandbox) calculateSandboxMemory() int64 {
memorySandbox := int64(0)
for _, c := range s.config.Containers {
// Do not hot add again non-running containers resources
if cont, ok := s.containers[c.ID]; ok && cont.state.State == types.StateStopped {
s.Logger().WithField("container-id", c.ID).Debug("Do not taking into account memory resources of not running containers")
continue
}

if m := c.Resources.Memory; m != nil && m.Limit != nil {
memorySandbox += *m.Limit
}
Expand All @@ -1972,6 +1978,12 @@ func (s *Sandbox) calculateSandboxCPUs() uint32 {
mCPU := uint32(0)

for _, c := range s.config.Containers {
// Do not hot add again non-running containers resources
if cont, ok := s.containers[c.ID]; ok && cont.state.State == types.StateStopped {
s.Logger().WithField("container-id", c.ID).Debug("Do not taking into account CPU resources of not running containers")
continue
}

if cpu := c.Resources.CPU; cpu != nil {
if cpu.Period != nil && cpu.Quota != nil {
mCPU += utils.CalculateMilliCPUs(*cpu.Quota, *cpu.Period)
Expand Down

0 comments on commit b7731e9

Please sign in to comment.