aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mem_linux.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2019-07-16 20:36:33 +0000
committerAustin Clements <austin@google.com>2019-07-30 18:44:52 +0000
commita41ebe6e259af020d4ce7029544439b39d07936b (patch)
treefe706075c4932e316580356f9260348b4afdb4dc /src/runtime/mem_linux.go
parentfbb819ebc443518e9caea3c1b0d0f9e0efec2262 (diff)
downloadgo-a41ebe6e259af020d4ce7029544439b39d07936b.tar.gz
go-a41ebe6e259af020d4ce7029544439b39d07936b.zip
runtime: add physHugePageShift
This change adds physHugePageShift which is defined such that 1 << physHugePageShift == physHugePageSize. The purpose of this variable is to avoid doing expensive divisions in key functions, such as (*mspan).hugePages. This change also does a sweep of any place we might do a division or mod operation with physHugePageSize and turns it into bit shifts and other bitwise operations. Finally, this change adds a check to mallocinit which ensures that physHugePageSize is always a power of two. osinit might choose to ignore non-powers-of-two for the value and replace it with zero, but mallocinit will fail if it's not a power of two (or zero). It also derives physHugePageShift from physHugePageSize. This change helps improve the performance of most applications because of how often (*mspan).hugePages is called. Updates #32828. Change-Id: I1a6db113d52d563f59ae8fd4f0e130858859e68f Reviewed-on: https://go-review.googlesource.com/c/go/+/186598 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mem_linux.go')
-rw-r--r--src/runtime/mem_linux.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/mem_linux.go b/src/runtime/mem_linux.go
index cda2c78eaf..524915fb31 100644
--- a/src/runtime/mem_linux.go
+++ b/src/runtime/mem_linux.go
@@ -68,11 +68,11 @@ func sysUnused(v unsafe.Pointer, n uintptr) {
// flag on the huge pages containing v and v+n-1, and
// only if those aren't aligned.
var head, tail uintptr
- if uintptr(v)%physHugePageSize != 0 {
+ if uintptr(v)&(physHugePageSize-1) != 0 {
// Compute huge page containing v.
head = uintptr(v) &^ (physHugePageSize - 1)
}
- if (uintptr(v)+n)%physHugePageSize != 0 {
+ if (uintptr(v)+n)&(physHugePageSize-1) != 0 {
// Compute huge page containing v+n-1.
tail = (uintptr(v) + n - 1) &^ (physHugePageSize - 1)
}