@@ -1873,8 +1873,9 @@ func (s *Sandbox) updateResources() error {
18731873 sandboxVCPUs += s .hypervisor .hypervisorConfig ().NumVCPUs
18741874
18751875 sandboxMemoryByte := s .calculateSandboxMemory ()
1876+
18761877 // Add default / rsvd memory for sandbox.
1877- sandboxMemoryByte += int64 (s .hypervisor .hypervisorConfig ().MemorySize ) << utils .MibToBytesShift
1878+ sandboxMemoryByte += uint64 (s .hypervisor .hypervisorConfig ().MemorySize ) << utils .MibToBytesShift
18781879
18791880 // Update VCPUs
18801881 s .Logger ().WithField ("cpus-sandbox" , sandboxVCPUs ).Debugf ("Request to hypervisor to update vCPUs" )
@@ -1894,7 +1895,9 @@ func (s *Sandbox) updateResources() error {
18941895
18951896 // Update Memory
18961897 s .Logger ().WithField ("memory-sandbox-size-byte" , sandboxMemoryByte ).Debugf ("Request to hypervisor to update memory" )
1897- newMemory , updatedMemoryDevice , err := s .hypervisor .resizeMemory (uint32 (sandboxMemoryByte >> utils .MibToBytesShift ), s .state .GuestMemoryBlockSizeMB , s .state .GuestMemoryHotplugProbe )
1898+ newMemoryMB := uint32 (sandboxMemoryByte >> utils .MibToBytesShift )
1899+
1900+ newMemory , updatedMemoryDevice , err := s .hypervisor .resizeMemory (newMemoryMB , s .state .GuestMemoryBlockSizeMB , s .state .GuestMemoryHotplugProbe )
18981901 if err != nil {
18991902 return err
19001903 }
@@ -1912,19 +1915,27 @@ func (s *Sandbox) updateResources() error {
19121915 return nil
19131916}
19141917
1915- func (s * Sandbox ) calculateSandboxMemory () int64 {
1916- memorySandbox := int64 (0 )
1918+ func (s * Sandbox ) calculateSandboxMemory () uint64 {
1919+ memorySandbox := uint64 (0 )
19171920 for _ , c := range s .config .Containers {
19181921 // Do not hot add again non-running containers resources
19191922 if cont , ok := s .containers [c .ID ]; ok && cont .state .State == types .StateStopped {
19201923 s .Logger ().WithField ("container-id" , c .ID ).Debug ("Do not taking into account memory resources of not running containers" )
19211924 continue
19221925 }
19231926
1924- if m := c .Resources .Memory ; m != nil && m .Limit != nil {
1925- memorySandbox += * m .Limit
1927+ if m := c .Resources .Memory ; m != nil && m .Limit != nil && * m .Limit > 0 {
1928+ memorySandbox += uint64 (* m .Limit )
1929+ s .Logger ().WithField ("memory limit" , memorySandbox ).Info ("Memory Sandbox + Memory Limit " )
1930+ }
1931+
1932+ //Add hugepages memory
1933+ //HugepageLimit is uint64 - https://github.com/opencontainers/runtime-spec/blob/master/specs-go/config.go#L242
1934+ for _ , l := range c .Resources .HugepageLimits {
1935+ memorySandbox += uint64 (l .Limit )
19261936 }
19271937 }
1938+
19281939 return memorySandbox
19291940}
19301941
0 commit comments