From f9c5ef8d8f94b364c758930f64b9305c52200b5b Mon Sep 17 00:00:00 2001 From: Xiangdong Ji Date: Thu, 5 Dec 2019 03:22:34 +0000 Subject: [PATCH] runtime: fix threshold calculation of TestPhysicalMemoryUtilization Variable 'procs' used to calculate the threshold of overuse in TestPhysicalMemoryUtilization should be updated if GOMAXPROCS gets changed, otherwise the threshold could be a large number, making the test meaningless. Change-Id: I876cbf11457529f56bae77af1e35f4538a721f95 Reviewed-on: https://go-review.googlesource.com/c/go/+/210297 Run-TryBot: Michael Knyszek TryBot-Result: Gobot Gobot Reviewed-by: Michael Knyszek --- src/runtime/testdata/testprog/gc.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/runtime/testdata/testprog/gc.go b/src/runtime/testdata/testprog/gc.go index cc16413ef5..f691a1d127 100644 --- a/src/runtime/testdata/testprog/gc.go +++ b/src/runtime/testdata/testprog/gc.go @@ -150,16 +150,20 @@ func GCPhys() { // The page cache could hide 64 8-KiB pages from the scavenger today. maxPageCache = (8 << 10) * 64 + + // Reduce GOMAXPROCS down to 4 if it's greater. We need to bound the amount + // of memory held in the page cache because the scavenger can't reach it. + // The page cache will hold at most maxPageCache of memory per-P, so this + // bounds the amount of memory hidden from the scavenger to 4*maxPageCache + // at most. + maxProcs = 4 ) // Set GOGC so that this test operates under consistent assumptions. debug.SetGCPercent(100) - // Reduce GOMAXPROCS down to 4 if it's greater. We need to bound the amount - // of memory held in the page cache because the scavenger can't reach it. - // The page cache will hold at most maxPageCache of memory per-P, so this - // bounds the amount of memory hidden from the scavenger to 4*maxPageCache. procs := runtime.GOMAXPROCS(-1) - if procs > 4 { - defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4)) + if procs > maxProcs { + defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(maxProcs)) + procs = runtime.GOMAXPROCS(-1) } // Save objects which we want to survive, and condemn objects which we don't. // Note that we condemn objects in this way and release them all at once in -- 2.50.0