diff options
| author | qiulaidongfeng <2645477756@qq.com> | 2023-10-10 12:43:40 +0000 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2023-10-24 20:28:25 +0000 |
| commit | b5f87b5407916c4049a3158cc944cebfd7a883a9 (patch) | |
| tree | 64b4a4c47ee017cad96b8b908ba368ee966ecdf1 /src/runtime/mpallocbits.go | |
| parent | 9ab5121691ee0c4f32bf8d8c3c10c0e85a89ceb5 (diff) | |
| download | go-b5f87b5407916c4049a3158cc944cebfd7a883a9.tar.xz | |
runtime: use max/min func
Change-Id: I3f0b7209621b39cee69566a5cc95e4343b4f1f20
GitHub-Last-Rev: af9dbbe69ad74e8c210254dafa260a886b690853
GitHub-Pull-Request: golang/go#63321
Reviewed-on: https://go-review.googlesource.com/c/go/+/531916
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/mpallocbits.go')
| -rw-r--r-- | src/runtime/mpallocbits.go | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/runtime/mpallocbits.go b/src/runtime/mpallocbits.go index 2f35ce007c..6b5f15dbd8 100644 --- a/src/runtime/mpallocbits.go +++ b/src/runtime/mpallocbits.go @@ -134,7 +134,7 @@ type pallocBits pageBits // summarize returns a packed summary of the bitmap in pallocBits. func (b *pallocBits) summarize() pallocSum { - var start, max, cur uint + var start, most, cur uint const notSetYet = ^uint(0) // sentinel for start value start = notSetYet for i := 0; i < len(b); i++ { @@ -151,9 +151,7 @@ func (b *pallocBits) summarize() pallocSum { if start == notSetYet { start = cur } - if cur > max { - max = cur - } + most = max(most, cur) // Final region that might span to next uint64 cur = l } @@ -162,12 +160,11 @@ func (b *pallocBits) summarize() pallocSum { const n = uint(64 * len(b)) return packPallocSum(n, n, n) } - if cur > max { - max = cur - } - if max >= 64-2 { + most = max(most, cur) + + if most >= 64-2 { // There is no way an internal run of zeros could beat max. - return packPallocSum(start, max, cur) + return packPallocSum(start, most, cur) } // Now look inside each uint64 for runs of zeros. // All uint64s must be nonzero, or we would have aborted above. @@ -188,7 +185,7 @@ outer: // Strategy: shrink all runs of zeros by max. If any runs of zero // remain, then we've identified a larger maximum zero run. - p := max // number of zeros we still need to shrink by. + p := most // number of zeros we still need to shrink by. k := uint(1) // current minimum length of runs of ones in x. for { // Shrink all runs of zeros by p places (except the top zeros). @@ -217,14 +214,14 @@ outer: x >>= j & 63 // remove trailing ones j = uint(sys.TrailingZeros64(x)) // count contiguous trailing zeros x >>= j & 63 // remove zeros - max += j // we have a new maximum! + most += j // we have a new maximum! if x&(x+1) == 0 { // no more zeros (except at the top). continue outer } p = j // remove j more zeros from each zero run. } } - return packPallocSum(start, max, cur) + return packPallocSum(start, most, cur) } // find searches for npages contiguous free pages in pallocBits and returns |
