Skip to content

Commit

Permalink
Merge pull request #4028 from jayantjain93/low-memory-offset
Browse files Browse the repository at this point in the history
additional memory reservation for gce cloud provider for low memory m...
  • Loading branch information
k8s-ci-robot authored Apr 22, 2021
2 parents 3bfbc18 + 4d13cdd commit 8dc1afb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions cluster-autoscaler/cloudprovider/gce/reserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const (
// ubuntuSpecificOffset is a constant value that is additionally added to Ubuntu
// based distributions as reserved memory
ubuntuSpecificOffset = 4 * MiB
// lowMemoryOffset is an additional offset added for lower memory sized machines
lowMemoryOffset = 8 * MiB
// lowMemoryThreshold is the threshold to apply lowMemoryOffset
lowMemoryThreshold = 8 * GiB
)

// EvictionHard is the struct used to keep parsed values for eviction
Expand Down Expand Up @@ -97,6 +101,9 @@ func CalculateKernelReserved(physicalMemory int64, os OperatingSystem, osDistrib
reserved += int64(math.Min(correctionConstant*float64(physicalMemory), maximumCorrectionValue))
reserved += ubuntuSpecificOffset
}
if physicalMemory <= lowMemoryThreshold {
reserved += lowMemoryOffset
}

return reserved
case OperatingSystemWindows:
Expand Down
20 changes: 10 additions & 10 deletions cluster-autoscaler/cloudprovider/gce/reserved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ func TestCalculateKernelReservedLinux(t *testing.T) {
testCases := []testCase{
{
physicalMemory: 256 * MiB,
reservedMemory: 4*MiB + kernelReservedMemory,
reservedMemory: 4*MiB + kernelReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionCOS,
},
{
physicalMemory: 2 * GiB,
reservedMemory: 32*MiB + kernelReservedMemory,
reservedMemory: 32*MiB + kernelReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionCOS,
},
{
physicalMemory: 3 * GiB,
reservedMemory: 48*MiB + kernelReservedMemory,
reservedMemory: 48*MiB + kernelReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionCOS,
},
{
physicalMemory: 3.25 * GiB,
reservedMemory: 52*MiB + kernelReservedMemory + swiotlbReservedMemory,
reservedMemory: 52*MiB + kernelReservedMemory + swiotlbReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionCOS,
},
{
physicalMemory: 4 * GiB,
reservedMemory: 64*MiB + kernelReservedMemory + swiotlbReservedMemory,
reservedMemory: 64*MiB + kernelReservedMemory + swiotlbReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionCOS,
},
{
Expand All @@ -63,27 +63,27 @@ func TestCalculateKernelReservedLinux(t *testing.T) {
},
{
physicalMemory: 256 * MiB,
reservedMemory: 4*MiB + kernelReservedMemory,
reservedMemory: 4*MiB + kernelReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionUbuntu,
},
{
physicalMemory: 2 * GiB,
reservedMemory: 32*MiB + kernelReservedMemory,
reservedMemory: 32*MiB + kernelReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionUbuntu,
},
{
physicalMemory: 3 * GiB,
reservedMemory: 48*MiB + kernelReservedMemory,
reservedMemory: 48*MiB + kernelReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionUbuntu,
},
{
physicalMemory: 3.25 * GiB,
reservedMemory: 52*MiB + kernelReservedMemory + swiotlbReservedMemory,
reservedMemory: 52*MiB + kernelReservedMemory + swiotlbReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionUbuntu,
},
{
physicalMemory: 4 * GiB,
reservedMemory: 64*MiB + kernelReservedMemory + swiotlbReservedMemory,
reservedMemory: 64*MiB + kernelReservedMemory + swiotlbReservedMemory + lowMemoryOffset,
osDistribution: OperatingSystemDistributionUbuntu,
},
{
Expand Down
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/gce/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ func TestBuildCapacityMemory(t *testing.T) {
physicalCpu: 1,
physicalMemory: 2 * units.GiB,
os: OperatingSystemLinux,
expectedCapacityMemory: 2*units.GiB - 32*units.MiB - kernelReservedMemory - int64(math.Min(correctionConstant*float64(2*units.GiB), maximumCorrectionValue)),
expectedCapacityMemory: 2*units.GiB - 32*units.MiB - kernelReservedMemory - int64(math.Min(correctionConstant*float64(2*units.GiB), maximumCorrectionValue)) - lowMemoryOffset,
},
{
physicalCpu: 2,
physicalMemory: 4 * units.GiB,
os: OperatingSystemLinux,
expectedCapacityMemory: 4*units.GiB - 64*units.MiB - kernelReservedMemory - swiotlbReservedMemory - int64(math.Min(correctionConstant*float64(4*units.GiB), maximumCorrectionValue)),
expectedCapacityMemory: 4*units.GiB - 64*units.MiB - kernelReservedMemory - swiotlbReservedMemory - int64(math.Min(correctionConstant*float64(4*units.GiB), maximumCorrectionValue)) - lowMemoryOffset,
},
{
physicalCpu: 32,
Expand Down

0 comments on commit 8dc1afb

Please sign in to comment.