]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't hard-code physical page size
authorAustin Clements <austin@google.com>
Mon, 18 Jul 2016 16:24:02 +0000 (12:24 -0400)
committerAustin Clements <austin@google.com>
Tue, 6 Sep 2016 21:05:53 +0000 (21:05 +0000)
Now that the runtime fetches the true physical page size from the OS,
make the physical page size used by heap growth a variable instead of
a constant. This isn't used in any performance-critical paths, so it
shouldn't be an issue.

sys.PhysPageSize is also renamed to sys.DefaultPhysPageSize to make it
clear that it's not necessarily the true page size. There are no uses
of this constant any more, but we'll keep it around for now.

Updates #12480 and #10180.

Change-Id: I6c23b9df860db309c38c8287a703c53817754f03
Reviewed-on: https://go-review.googlesource.com/25022
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
14 files changed:
src/runtime/internal/sys/arch_386.go
src/runtime/internal/sys/arch_amd64.go
src/runtime/internal/sys/arch_amd64p32.go
src/runtime/internal/sys/arch_arm.go
src/runtime/internal/sys/arch_arm64.go
src/runtime/internal/sys/arch_mips64.go
src/runtime/internal/sys/arch_mips64le.go
src/runtime/internal/sys/arch_ppc64.go
src/runtime/internal/sys/arch_ppc64le.go
src/runtime/internal/sys/arch_s390x.go
src/runtime/malloc.go
src/runtime/mbitmap.go
src/runtime/mem_linux.go
src/runtime/mheap.go

index 48c42f75845e7f30707f8df4533e230ddde2a494..61d6722cca5a0bc5ab54b1faa2977c01e5450312 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = I386
-       BigEndian     = 0
-       CacheLineSize = 64
-       PhysPageSize  = GoosNacl*65536 + (1-GoosNacl)*4096 // 4k normally; 64k on NaCl
-       PCQuantum     = 1
-       Int64Align    = 4
-       HugePageSize  = 1 << 21
-       MinFrameSize  = 0
+       ArchFamily          = I386
+       BigEndian           = 0
+       CacheLineSize       = 64
+       DefaultPhysPageSize = GoosNacl*65536 + (1-GoosNacl)*4096 // 4k normally; 64k on NaCl
+       PCQuantum           = 1
+       Int64Align          = 4
+       HugePageSize        = 1 << 21
+       MinFrameSize        = 0
 )
 
 type Uintreg uint32
index 1bbdb99e0720042040d8275ff212e2b4af516d06..1f2114a736b7027ea570b7f6500da55a2f434b44 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = AMD64
-       BigEndian     = 0
-       CacheLineSize = 64
-       PhysPageSize  = 4096
-       PCQuantum     = 1
-       Int64Align    = 8
-       HugePageSize  = 1 << 21
-       MinFrameSize  = 0
+       ArchFamily          = AMD64
+       BigEndian           = 0
+       CacheLineSize       = 64
+       DefaultPhysPageSize = 4096
+       PCQuantum           = 1
+       Int64Align          = 8
+       HugePageSize        = 1 << 21
+       MinFrameSize        = 0
 )
 
 type Uintreg uint64
index b7011a4ff2d6cd5d813ee2aa19af6003bf3f9a30..07798557de6bfce45fc12eae421216907e79d6f9 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = AMD64
-       BigEndian     = 0
-       CacheLineSize = 64
-       PhysPageSize  = 65536*GoosNacl + 4096*(1-GoosNacl)
-       PCQuantum     = 1
-       Int64Align    = 8
-       HugePageSize  = 1 << 21
-       MinFrameSize  = 0
+       ArchFamily          = AMD64
+       BigEndian           = 0
+       CacheLineSize       = 64
+       DefaultPhysPageSize = 65536*GoosNacl + 4096*(1-GoosNacl)
+       PCQuantum           = 1
+       Int64Align          = 8
+       HugePageSize        = 1 << 21
+       MinFrameSize        = 0
 )
 
 type Uintreg uint64
index 880494a0eb99eb2fbccecd000ab73a1e53e8602b..899010bfa12e63e33fc8da1aac1d3857bf1f015c 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = ARM
-       BigEndian     = 0
-       CacheLineSize = 32
-       PhysPageSize  = 65536
-       PCQuantum     = 4
-       Int64Align    = 4
-       HugePageSize  = 0
-       MinFrameSize  = 4
+       ArchFamily          = ARM
+       BigEndian           = 0
+       CacheLineSize       = 32
+       DefaultPhysPageSize = 65536
+       PCQuantum           = 4
+       Int64Align          = 4
+       HugePageSize        = 0
+       MinFrameSize        = 4
 )
 
 type Uintreg uint32
index aaaa4b0947c8045f7e2c822eea82c1f1e1a8fa1c..2d57ddae191c635aa7cbd58b19fd768298a19551 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = ARM64
-       BigEndian     = 0
-       CacheLineSize = 32
-       PhysPageSize  = 65536
-       PCQuantum     = 4
-       Int64Align    = 8
-       HugePageSize  = 0
-       MinFrameSize  = 8
+       ArchFamily          = ARM64
+       BigEndian           = 0
+       CacheLineSize       = 32
+       DefaultPhysPageSize = 65536
+       PCQuantum           = 4
+       Int64Align          = 8
+       HugePageSize        = 0
+       MinFrameSize        = 8
 )
 
 type Uintreg uint64
index d5672599d2a6957e9cd6d3f6d8758f2225152093..0f6de74e6ff25a09fdf65e3eaa2a3d5d43a6ca8d 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = MIPS64
-       BigEndian     = 1
-       CacheLineSize = 32
-       PhysPageSize  = 16384
-       PCQuantum     = 4
-       Int64Align    = 8
-       HugePageSize  = 0
-       MinFrameSize  = 8
+       ArchFamily          = MIPS64
+       BigEndian           = 1
+       CacheLineSize       = 32
+       DefaultPhysPageSize = 16384
+       PCQuantum           = 4
+       Int64Align          = 8
+       HugePageSize        = 0
+       MinFrameSize        = 8
 )
 
 type Uintreg uint64
index f8cdf2b2d2fd74c4c69d08f44f8f84d9cab563e4..4ced35bfde3928b643f9e78225343061703bec98 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = MIPS64
-       BigEndian     = 0
-       CacheLineSize = 32
-       PhysPageSize  = 16384
-       PCQuantum     = 4
-       Int64Align    = 8
-       HugePageSize  = 0
-       MinFrameSize  = 8
+       ArchFamily          = MIPS64
+       BigEndian           = 0
+       CacheLineSize       = 32
+       DefaultPhysPageSize = 16384
+       PCQuantum           = 4
+       Int64Align          = 8
+       HugePageSize        = 0
+       MinFrameSize        = 8
 )
 
 type Uintreg uint64
index f908ce21739b131d6d57de3b7bd5754f255854cb..80595ee1954f0466bdd7d06e3266c4e9287644ff 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = PPC64
-       BigEndian     = 1
-       CacheLineSize = 128
-       PhysPageSize  = 65536
-       PCQuantum     = 4
-       Int64Align    = 8
-       HugePageSize  = 0
-       MinFrameSize  = 32
+       ArchFamily          = PPC64
+       BigEndian           = 1
+       CacheLineSize       = 128
+       DefaultPhysPageSize = 65536
+       PCQuantum           = 4
+       Int64Align          = 8
+       HugePageSize        = 0
+       MinFrameSize        = 32
 )
 
 type Uintreg uint64
index 3d95f9e96cef6125c71bb1f07a86e43be1e22972..f68e77705509cb06eb39281924e1b28796ca99e8 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = PPC64
-       BigEndian     = 0
-       CacheLineSize = 128
-       PhysPageSize  = 65536
-       PCQuantum     = 4
-       Int64Align    = 8
-       HugePageSize  = 0
-       MinFrameSize  = 32
+       ArchFamily          = PPC64
+       BigEndian           = 0
+       CacheLineSize       = 128
+       DefaultPhysPageSize = 65536
+       PCQuantum           = 4
+       Int64Align          = 8
+       HugePageSize        = 0
+       MinFrameSize        = 32
 )
 
 type Uintreg uint64
index ca1cb8646e4c3a734a05dde6f30e3e40620cd051..4ec4bf8fec4ea9f5e05ac1cc1a5f974b44918aa1 100644 (file)
@@ -5,14 +5,14 @@
 package sys
 
 const (
-       ArchFamily    = S390X
-       BigEndian     = 1
-       CacheLineSize = 256
-       PhysPageSize  = 4096
-       PCQuantum     = 2
-       Int64Align    = 8
-       HugePageSize  = 0
-       MinFrameSize  = 8
+       ArchFamily          = S390X
+       BigEndian           = 1
+       CacheLineSize       = 256
+       DefaultPhysPageSize = 4096
+       PCQuantum           = 2
+       Int64Align          = 8
+       HugePageSize        = 0
+       MinFrameSize        = 8
 )
 
 type Uintreg uint64
index 931af2ac93ad9384d34c917588a7739cf512254c..514c0dfada16e96af1701e55058d7697fdc3f843 100644 (file)
@@ -230,13 +230,13 @@ func mallocinit() {
                // The OS init code failed to fetch the physical page size.
                throw("failed to get system page size")
        }
-       if sys.PhysPageSize < physPageSize {
-               print("runtime: kernel page size (", physPageSize, ") is larger than runtime page size (", sys.PhysPageSize, ")\n")
-               throw("bad kernel page size")
+       if physPageSize < minPhysPageSize {
+               print("system page size (", physPageSize, ") is smaller than minimum page size (", minPhysPageSize, ")\n")
+               throw("bad system page size")
        }
-       if sys.PhysPageSize%physPageSize != 0 {
-               print("runtime: runtime page size (", sys.PhysPageSize, ") is not a multiple of kernel page size (", physPageSize, ")\n")
-               throw("bad kernel page size")
+       if physPageSize&(physPageSize-1) != 0 {
+               print("system page size (", physPageSize, ") must be a power of 2\n")
+               throw("bad system page size")
        }
 
        var p, bitmapSize, spansSize, pSize, limit uintptr
index d05a072705d0543557830b6e79066a47680dd8fd..f5b10f35451720c787403ddbe21e692eb024d87a 100644 (file)
@@ -151,7 +151,7 @@ func (h *mheap) mapBits(arena_used uintptr) {
 
        n := (arena_used - mheap_.arena_start) / heapBitmapScale
        n = round(n, bitmapChunk)
-       n = round(n, sys.PhysPageSize)
+       n = round(n, physPageSize)
        if h.bitmap_mapped >= n {
                return
        }
index cd0bf263285532cdcff62227d4bdd8d5035d5729..094658de5169ad1a674611de0ff172a86501c018 100644 (file)
@@ -22,17 +22,14 @@ const (
 var addrspace_vec [1]byte
 
 func addrspace_free(v unsafe.Pointer, n uintptr) bool {
-       // Step by the minimum possible physical page size. This is
-       // safe even if we have the wrong physical page size; mincore
-       // will just return EINVAL for unaligned addresses.
-       for off := uintptr(0); off < n; off += minPhysPageSize {
+       for off := uintptr(0); off < n; off += physPageSize {
                // Use a length of 1 byte, which the kernel will round
                // up to one physical page regardless of the true
                // physical page size.
                errval := mincore(unsafe.Pointer(uintptr(v)+off), 1, &addrspace_vec[0])
                if errval == -_EINVAL {
                        // Address is not a multiple of the physical
-                       // page size. That's fine.
+                       // page size. Shouldn't happen, but just ignore it.
                        continue
                }
                // ENOMEM means unmapped, which is what we want.
@@ -138,7 +135,7 @@ func sysUnused(v unsafe.Pointer, n uintptr) {
                }
        }
 
-       if uintptr(v)&(sys.PhysPageSize-1) != 0 || n&(sys.PhysPageSize-1) != 0 {
+       if uintptr(v)&(physPageSize-1) != 0 || n&(physPageSize-1) != 0 {
                // madvise will round this to any physical page
                // *covered* by this range, so an unaligned madvise
                // will release more memory than intended.
index 8db2fcc2888bdb04df7a5abde072404be8d7c4eb..dfb484c06e6119fc1417b6d4811acf1c238bee49 100644 (file)
@@ -401,7 +401,7 @@ func (h *mheap) mapSpans(arena_used uintptr) {
        n := arena_used
        n -= h.arena_start
        n = n / _PageSize * sys.PtrSize
-       n = round(n, sys.PhysPageSize)
+       n = round(n, physPageSize)
        if h.spans_mapped >= n {
                return
        }
@@ -909,14 +909,14 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr {
                if (now-uint64(s.unusedsince)) > limit && s.npreleased != s.npages {
                        start := s.base()
                        end := start + s.npages<<_PageShift
-                       if sys.PhysPageSize > _PageSize {
+                       if physPageSize > _PageSize {
                                // We can only release pages in
-                               // PhysPageSize blocks, so round start
+                               // physPageSize blocks, so round start
                                // and end in. (Otherwise, madvise
                                // will round them *out* and release
                                // more memory than we want.)
-                               start = (start + sys.PhysPageSize - 1) &^ (sys.PhysPageSize - 1)
-                               end &^= sys.PhysPageSize - 1
+                               start = (start + physPageSize - 1) &^ (physPageSize - 1)
+                               end &^= physPageSize - 1
                                if end <= start {
                                        // start and end don't span a
                                        // whole physical page.
@@ -926,7 +926,7 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr {
                        len := end - start
 
                        released := len - (s.npreleased << _PageShift)
-                       if sys.PhysPageSize > _PageSize && released == 0 {
+                       if physPageSize > _PageSize && released == 0 {
                                continue
                        }
                        memstats.heap_released += uint64(released)