From 276a52de55fb48c4e56a778f1f7cac9292d8fad7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 18 Jul 2016 21:40:02 -0400 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/malloc.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/runtime/malloc.go') 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 -- cgit v1.3-5-g9baa