]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: change maxSearchAddr into a helper function
authorMatthew Dempsky <mdempsky@google.com>
Mon, 28 Mar 2022 16:30:41 +0000 (09:30 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 11 May 2022 03:28:01 +0000 (03:28 +0000)
This avoids a dependency on the compiler statically initializing
maxSearchAddr, which is necessary so we can disable the (overly
aggressive and spec non-conforming) optimizations in cmd/compile and
gccgo.

Updates #51913.

Change-Id: I424e62c81c722bb179ed8d2d8e188274a1aeb7b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/396194
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/mpagealloc.go
src/runtime/mpagecache.go

index c85da15ff2cdfc4ecf2d8ae95911f2c616568ede..5de25cfe00ac46ff83dd5ec4c68f3de09d51e766 100644 (file)
@@ -83,11 +83,16 @@ const (
        pallocChunksL1Shift = pallocChunksL2Bits
 )
 
-// Maximum searchAddr value, which indicates that the heap has no free space.
+// maxSearchAddr returns the maximum searchAddr value, which indicates
+// that the heap has no free space.
 //
-// We alias maxOffAddr just to make it clear that this is the maximum address
+// This function exists just to make it clear that this is the maximum address
 // for the page allocator's search space. See maxOffAddr for details.
-var maxSearchAddr = maxOffAddr
+//
+// It's a function (rather than a variable) because it needs to be
+// usable before package runtime's dynamic initialization is complete.
+// See #51913 for details.
+func maxSearchAddr() offAddr { return maxOffAddr }
 
 // Global chunk index.
 //
@@ -319,7 +324,7 @@ func (p *pageAlloc) init(mheapLock *mutex, sysStat *sysMemStat) {
        p.sysInit()
 
        // Start with the searchAddr in a state indicating there's no free memory.
-       p.searchAddr = maxSearchAddr
+       p.searchAddr = maxSearchAddr()
 
        // Set the mheapLock.
        p.mheapLock = mheapLock
@@ -745,7 +750,7 @@ nextLevel:
                }
                if l == 0 {
                        // We're at level zero, so that means we've exhausted our search.
-                       return 0, maxSearchAddr
+                       return 0, maxSearchAddr()
                }
 
                // We're not at level zero, and we exhausted the level we were looking in.
@@ -839,7 +844,7 @@ func (p *pageAlloc) alloc(npages uintptr) (addr uintptr, scav uintptr) {
                        // exhausted. Otherwise, the heap still might have free
                        // space in it, just not enough contiguous space to
                        // accommodate npages.
-                       p.searchAddr = maxSearchAddr
+                       p.searchAddr = maxSearchAddr()
                }
                return 0, 0
        }
index 7206e2dbdb763a0df7278660d2ef3ec6dcae6273..5bad4f789a11982659da1d894509f312859f8faa 100644 (file)
@@ -143,7 +143,7 @@ func (p *pageAlloc) allocToCache() pageCache {
                if addr == 0 {
                        // We failed to find adequate free space, so mark the searchAddr as OoM
                        // and return an empty pageCache.
-                       p.searchAddr = maxSearchAddr
+                       p.searchAddr = maxSearchAddr()
                        return pageCache{}
                }
                ci := chunkIndex(addr)