aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2016-07-18 21:40:02 -0400
committerAustin Clements <austin@google.com>2016-09-06 21:05:50 +0000
commit276a52de55fb48c4e56a778f1f7cac9292d8fad7 (patch)
tree7ead3e72e915bad7bcead853af4ba10b237188fe /src/runtime/malloc.go
parentd7de8b6d231289b7a6b205508c6f02a5a475cc84 (diff)
downloadgo-276a52de55fb48c4e56a778f1f7cac9292d8fad7.tar.xz
runtime: fetch physical page size from the OS
Currently the physical page size assumed by the runtime is hard-coded. On Linux the runtime at least fetches the OS page size during init and sanity checks against the hard-coded value, but they may still differ. On other OSes we wouldn't even notice. Add support on all OSes to fetch the actual OS physical page size during runtime init and lift the sanity check of PhysPageSize from the Linux init code to general malloc init. Currently this is the only use of the retrieved page size, but we'll add more shortly. Updates #12480 and #10180. Change-Id: I065f2834bc97c71d3208edc17fd990ec9058b6da Reviewed-on: https://go-review.googlesource.com/25050 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/malloc.go')
-rw-r--r--src/runtime/malloc.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 4f0a2cee22..931af2ac93 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -172,6 +172,14 @@ const (
const _MaxArena32 = 1<<32 - 1
+// physPageSize is the size in bytes of the OS's physical pages.
+// Mapping and unmapping operations must be done at multiples of
+// physPageSize.
+//
+// This must be set by the OS init code (typically in osinit) before
+// mallocinit.
+var physPageSize uintptr
+
// OS-defined helpers:
//
// sysAlloc obtains a large chunk of zeroed memory from the
@@ -217,6 +225,20 @@ func mallocinit() {
throw("bad TinySizeClass")
}
+ // Check physPageSize.
+ if physPageSize == 0 {
+ // 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 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")
+ }
+
var p, bitmapSize, spansSize, pSize, limit uintptr
var reserved bool