]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix threshold calculation of TestPhysicalMemoryUtilization
authorXiangdong Ji <xiangdong.ji@arm.com>
Thu, 5 Dec 2019 03:22:34 +0000 (03:22 +0000)
committerMichael Knyszek <mknyszek@google.com>
Thu, 26 Mar 2020 14:23:17 +0000 (14:23 +0000)
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 <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/testdata/testprog/gc.go

index cc16413ef5ceca85fc2e150836814d9d8f808114..f691a1d127ece2b1fa664e853610e04b9a73b6dc 100644 (file)
@@ -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