1
0
mirror of https://github.com/golang/go synced 2024-11-17 19:15:21 -07:00

runtime: adjust TestPhysicalMemoryUtilization to handle large page sizes

Currently TestPhysicalMemoryUtilization can fail on systems with large
physical page sizes like 64 KiB because all the of the holes to be
scavenged are not aligned to the page size. The holes themselves are 64
KiB so this is actually quite likely.

Bump the size of the allocations for systems with larger physical page
sizes, and add additional slack to the threshold for unaligned pieces of
the holes that may be unaligned.

Fixes #49411.

Change-Id: Iafb35b8761dc9cdc53d3745c4771b1a64c5c97b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/363415
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Michael Anthony Knyszek 2021-11-11 17:31:36 +00:00 committed by Michael Knyszek
parent 3e94140465
commit 46b2fc05a2

View File

@ -140,13 +140,26 @@ func GCPhys() {
// returned to the OS. // returned to the OS.
const ( const (
// The total amount of memory we're willing to allocate.
allocTotal = 32 << 20 allocTotal = 32 << 20
allocChunk = 64 << 10
allocs = allocTotal / allocChunk
// The page cache could hide 64 8-KiB pages from the scavenger today. // The page cache could hide 64 8-KiB pages from the scavenger today.
maxPageCache = (8 << 10) * 64 maxPageCache = (8 << 10) * 64
) )
// How big the allocations are needs to depend on the page size.
// If the page size is too big and the allocations are too small,
// they might not be aligned to the physical page size, so the scavenger
// will gloss over them.
pageSize := os.Getpagesize()
var allocChunk int
if pageSize <= 8<<10 {
allocChunk = 64 << 10
} else {
allocChunk = 512 << 10
}
allocs := allocTotal / allocChunk
// Set GC percent just so this test is a little more consistent in the // Set GC percent just so this test is a little more consistent in the
// face of varying environments. // face of varying environments.
debug.SetGCPercent(100) debug.SetGCPercent(100)
@ -197,7 +210,7 @@ func GCPhys() {
// //
// heapBacked also subtracts out maxPageCache bytes of memory because // heapBacked also subtracts out maxPageCache bytes of memory because
// this is memory that may be hidden from the scavenger per-P. Since // this is memory that may be hidden from the scavenger per-P. Since
// GOMAXPROCS=1 here, that's fine. // GOMAXPROCS=1 here, subtracting it out once is fine.
var stats runtime.MemStats var stats runtime.MemStats
runtime.ReadMemStats(&stats) runtime.ReadMemStats(&stats)
heapBacked := stats.HeapSys - stats.HeapReleased - maxPageCache heapBacked := stats.HeapSys - stats.HeapReleased - maxPageCache
@ -212,7 +225,12 @@ func GCPhys() {
overuse := (float64(heapBacked) - float64(stats.HeapAlloc)) / float64(stats.HeapAlloc) overuse := (float64(heapBacked) - float64(stats.HeapAlloc)) / float64(stats.HeapAlloc)
// Check against our overuse threshold, which is what the scavenger always reserves // Check against our overuse threshold, which is what the scavenger always reserves
// to encourage allocation of memory that doesn't need to be faulted in. // to encourage allocation of memory that doesn't need to be faulted in.
const threshold = 0.1 //
// Add additional slack in case the page size is large and the scavenger
// can't reach that memory because it doesn't constitute a complete aligned
// physical page. Assume the worst case: a full physical page out of each
// allocation.
threshold := 0.1 + float64(pageSize)/float64(allocChunk)
if overuse <= threshold { if overuse <= threshold {
fmt.Println("OK") fmt.Println("OK")
return return