From 4d13cdde56b557526de952cbccd4eeac1bb563bb Mon Sep 17 00:00:00 2001 From: Jayant Jain Date: Thu, 22 Apr 2021 12:57:25 +0000 Subject: [PATCH] additional memory reservation for gce cloud provider for low memory machines --- .../cloudprovider/gce/reserved.go | 7 +++++++ .../cloudprovider/gce/reserved_test.go | 20 +++++++++---------- .../cloudprovider/gce/templates_test.go | 4 ++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/gce/reserved.go b/cluster-autoscaler/cloudprovider/gce/reserved.go index d2f1ec5c5466..aa69bc84f1ca 100644 --- a/cluster-autoscaler/cloudprovider/gce/reserved.go +++ b/cluster-autoscaler/cloudprovider/gce/reserved.go @@ -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 @@ -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: diff --git a/cluster-autoscaler/cloudprovider/gce/reserved_test.go b/cluster-autoscaler/cloudprovider/gce/reserved_test.go index 7d481fe353ad..9c9039dd3861 100644 --- a/cluster-autoscaler/cloudprovider/gce/reserved_test.go +++ b/cluster-autoscaler/cloudprovider/gce/reserved_test.go @@ -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, }, { @@ -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, }, { diff --git a/cluster-autoscaler/cloudprovider/gce/templates_test.go b/cluster-autoscaler/cloudprovider/gce/templates_test.go index 8b8dceffdf89..9a27937f47ff 100644 --- a/cluster-autoscaler/cloudprovider/gce/templates_test.go +++ b/cluster-autoscaler/cloudprovider/gce/templates_test.go @@ -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,