skip reduceAllocatableMemoryUsage if cgroup v2 is enabled

This commit is contained in:
Paco Xu 2021-12-16 11:44:59 +08:00
parent 522c1be4c1
commit f0e7025371
2 changed files with 11 additions and 8 deletions

View File

@ -510,7 +510,7 @@ func runEvictionTest(f *framework.Framework, pressureTimeout time.Duration, expe
ginkgo.Context("", func() {
ginkgo.BeforeEach(func() {
// reduce memory usage in the allocatable cgroup to ensure we do not have MemoryPressure
reduceAllocatableMemoryUsage()
reduceAllocatableMemoryUsageIfCgroupv1()
// Nodes do not immediately report local storage capacity
// Sleep so that pods requesting local storage do not fail to schedule
time.Sleep(30 * time.Second)
@ -603,7 +603,7 @@ func runEvictionTest(f *framework.Framework, pressureTimeout time.Duration, expe
return nil
}, pressureDisappearTimeout, evictionPollInterval).Should(gomega.BeNil())
reduceAllocatableMemoryUsage()
reduceAllocatableMemoryUsageIfCgroupv1()
ginkgo.By("making sure we have all the required images for testing")
prePullImagesIfNeccecary()

View File

@ -468,13 +468,16 @@ func toCgroupFsName(cgroupName cm.CgroupName) string {
return cgroupName.ToCgroupfs()
}
// reduceAllocatableMemoryUsage uses memory.force_empty (https://lwn.net/Articles/432224/)
// reduceAllocatableMemoryUsageIfCgroupv1 uses memory.force_empty (https://lwn.net/Articles/432224/)
// to make the kernel reclaim memory in the allocatable cgroup
// the time to reduce pressure may be unbounded, but usually finishes within a second
func reduceAllocatableMemoryUsage() {
cmd := fmt.Sprintf("echo 0 > /sys/fs/cgroup/memory/%s/memory.force_empty", toCgroupFsName(cm.NewCgroupName(cm.RootCgroupName, defaultNodeAllocatableCgroup)))
_, err := exec.Command("sudo", "sh", "-c", cmd).CombinedOutput()
framework.ExpectNoError(err)
// the time to reduce pressure may be unbounded, but usually finishes within a second.
// memory.force_empty is no supported in cgroupv2.
func reduceAllocatableMemoryUsageIfCgroupv1() {
if !IsCgroup2UnifiedMode() {
cmd := fmt.Sprintf("echo 0 > /sys/fs/cgroup/memory/%s/memory.force_empty", toCgroupFsName(cm.NewCgroupName(cm.RootCgroupName, defaultNodeAllocatableCgroup)))
_, err := exec.Command("sudo", "sh", "-c", cmd).CombinedOutput()
framework.ExpectNoError(err)
}
}
// Equivalent of featuregatetesting.SetFeatureGateDuringTest