mirror of
https://github.com/golang/go
synced 2024-09-29 22:24:33 -06:00
runtime: add physHugePageSize
This change adds the global physHugePageSize which is initialized in osinit(). physHugePageSize contains the system's transparent huge page (or superpage) size in bytes. For #30333. Change-Id: I2f0198c40729dbbe6e6f2676cef1d57dd107562c Reviewed-on: https://go-review.googlesource.com/c/go/+/170858 Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
8b2bd6f5ff
commit
1033065ee3
@ -324,6 +324,14 @@ const (
|
|||||||
// mallocinit.
|
// mallocinit.
|
||||||
var physPageSize uintptr
|
var physPageSize uintptr
|
||||||
|
|
||||||
|
// physHugePageSize is the size in bytes of the OS's default physical huge
|
||||||
|
// page size whose allocation is opaque to the application.
|
||||||
|
//
|
||||||
|
// If set, this must be set by the OS init code (typically in osinit) before
|
||||||
|
// mallocinit. However, setting it at all is optional, and leaving the default
|
||||||
|
// value is always safe (though potentially less efficient).
|
||||||
|
var physHugePageSize uintptr
|
||||||
|
|
||||||
// OS-defined helpers:
|
// OS-defined helpers:
|
||||||
//
|
//
|
||||||
// sysAlloc obtains a large chunk of zeroed memory from the
|
// sysAlloc obtains a large chunk of zeroed memory from the
|
||||||
|
@ -261,8 +261,31 @@ func sysauxv(auxv []uintptr) int {
|
|||||||
return i / 2
|
return i / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sysTHPSizePath = []byte("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size\x00")
|
||||||
|
|
||||||
|
func getHugePageSize() uintptr {
|
||||||
|
var numbuf [20]byte
|
||||||
|
fd := open(&sysTHPSizePath[0], 0 /* O_RDONLY */, 0)
|
||||||
|
if fd < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
n := read(fd, noescape(unsafe.Pointer(&numbuf[0])), int32(len(numbuf)))
|
||||||
|
if n <= 0 {
|
||||||
|
closefd(fd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
l := n - 1 // remove trailing newline
|
||||||
|
v, ok := atoi(slicebytetostringtmp(numbuf[:l]))
|
||||||
|
if !ok || v < 0 {
|
||||||
|
v = 0
|
||||||
|
}
|
||||||
|
closefd(fd)
|
||||||
|
return uintptr(v)
|
||||||
|
}
|
||||||
|
|
||||||
func osinit() {
|
func osinit() {
|
||||||
ncpu = getproccount()
|
ncpu = getproccount()
|
||||||
|
physHugePageSize = getHugePageSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
var urandom_dev = []byte("/dev/urandom\x00")
|
var urandom_dev = []byte("/dev/urandom\x00")
|
||||||
|
Loading…
Reference in New Issue
Block a user