diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2019-06-28 16:44:07 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2019-11-04 23:41:34 +0000 |
commit | 383b447e0da5bd1fcdc2439230b5a1d3e3402117 (patch) | |
tree | c1dafd5c18d1d2ddc09d51dc6892087e3f506411 /src/runtime/mem_linux.go | |
parent | 2566e21f243387156e8e7f2acad0ce14d9712bbc (diff) | |
download | go-383b447e0da5bd1fcdc2439230b5a1d3e3402117.tar.gz go-383b447e0da5bd1fcdc2439230b5a1d3e3402117.zip |
runtime: clean up power-of-two rounding code with align functions
This change renames the "round" function to the more appropriately named
"alignUp" which rounds an integer up to the next multiple of a power of
two.
This change also adds the alignDown function, which is almost like
alignUp but rounds down to the previous multiple of a power of two.
With these two functions, we also go and replace manual rounding code
with it where we can.
Change-Id: Ie1487366280484dcb2662972b01b4f7135f72fec
Reviewed-on: https://go-review.googlesource.com/c/go/+/190618
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/mem_linux.go')
-rw-r--r-- | src/runtime/mem_linux.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/runtime/mem_linux.go b/src/runtime/mem_linux.go index 524915fb31..59b0bca970 100644 --- a/src/runtime/mem_linux.go +++ b/src/runtime/mem_linux.go @@ -70,11 +70,11 @@ func sysUnused(v unsafe.Pointer, n uintptr) { var head, tail uintptr if uintptr(v)&(physHugePageSize-1) != 0 { // Compute huge page containing v. - head = uintptr(v) &^ (physHugePageSize - 1) + head = alignDown(uintptr(v), physHugePageSize) } if (uintptr(v)+n)&(physHugePageSize-1) != 0 { // Compute huge page containing v+n-1. - tail = (uintptr(v) + n - 1) &^ (physHugePageSize - 1) + tail = alignDown(uintptr(v)+n-1, physHugePageSize) } // Note that madvise will return EINVAL if the flag is @@ -131,9 +131,9 @@ func sysUsed(v unsafe.Pointer, n uintptr) { func sysHugePage(v unsafe.Pointer, n uintptr) { if physHugePageSize != 0 { // Round v up to a huge page boundary. - beg := (uintptr(v) + (physHugePageSize - 1)) &^ (physHugePageSize - 1) + beg := alignUp(uintptr(v), physHugePageSize) // Round v+n down to a huge page boundary. - end := (uintptr(v) + n) &^ (physHugePageSize - 1) + end := alignDown(uintptr(v)+n, physHugePageSize) if beg < end { madvise(unsafe.Pointer(beg), end-beg, _MADV_HUGEPAGE) |