diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2020-04-28 21:30:57 +0000 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2020-05-08 16:32:03 +0000 |
| commit | ea5f9b666ccf7affca596be3ab0dc523ca4444fb (patch) | |
| tree | 5fa08a27635a5d1a65384d071c16229c4fd200c8 /src/runtime/mpagecache.go | |
| parent | d69509ff995bf3b92246365980e3d27eaf720e6a (diff) | |
| download | go-ea5f9b666ccf7affca596be3ab0dc523ca4444fb.tar.xz | |
runtime: use offAddr in more parts of the runtime
This change uses the new offAddr type in more parts of the runtime where
we've been implicitly switching from the default address space to a
contiguous view. The purpose of offAddr is to represent addresses in the
contiguous view of the address space, and to make direct computations
between real addresses and offset addresses impossible. This change thus
improves readability in the runtime.
Updates #35788.
Change-Id: I4e1c5fed3ed68aa12f49a42b82eb3f46aba82fc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/230718
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mpagecache.go')
| -rw-r--r-- | src/runtime/mpagecache.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/runtime/mpagecache.go b/src/runtime/mpagecache.go index fae54d7cdd..683a997136 100644 --- a/src/runtime/mpagecache.go +++ b/src/runtime/mpagecache.go @@ -91,8 +91,8 @@ func (c *pageCache) flush(s *pageAlloc) { } // Since this is a lot like a free, we need to make sure // we update the searchAddr just like free does. - if s.compareSearchAddrTo(c.base) < 0 { - s.searchAddr = c.base + if b := (offAddr{c.base}); b.lessThan(s.searchAddr) { + s.searchAddr = b } s.update(c.base, pageCachePages, false, false) *c = pageCache{} @@ -106,15 +106,15 @@ func (c *pageCache) flush(s *pageAlloc) { func (s *pageAlloc) allocToCache() pageCache { // If the searchAddr refers to a region which has a higher address than // any known chunk, then we know we're out of memory. - if chunkIndex(s.searchAddr) >= s.end { + if chunkIndex(s.searchAddr.addr()) >= s.end { return pageCache{} } c := pageCache{} - ci := chunkIndex(s.searchAddr) // chunk index + ci := chunkIndex(s.searchAddr.addr()) // chunk index if s.summary[len(s.summary)-1][ci] != 0 { // Fast path: there's free pages at or near the searchAddr address. chunk := s.chunkOf(ci) - j, _ := chunk.find(1, chunkPageIndex(s.searchAddr)) + j, _ := chunk.find(1, chunkPageIndex(s.searchAddr.addr())) if j == ^uint(0) { throw("bad summary data") } @@ -156,6 +156,6 @@ func (s *pageAlloc) allocToCache() pageCache { // However, s.searchAddr is not allowed to point into unmapped heap memory // unless it is maxSearchAddr, so make it the last page as opposed to // the page after. - s.searchAddr = c.base + pageSize*(pageCachePages-1) + s.searchAddr = offAddr{c.base + pageSize*(pageCachePages-1)} return c } |
