aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mpagecache.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2020-08-21 11:59:55 -0400
committerMichael Pratt <mpratt@google.com>2020-10-30 20:21:14 +0000
commit9393b5bae5944acebed3ab6f995926b7de3ce429 (patch)
treef2b29ca5cbc839f575cc0011b425a3231895016f /src/runtime/mpagecache.go
parent6abbfc17c255c07134a69c3ca305231db80530ec (diff)
downloadgo-9393b5bae5944acebed3ab6f995926b7de3ce429.tar.xz
runtime: add heap lock assertions
Some functions that required holding the heap lock _or_ world stop have been simplified to simply requiring the heap lock. This is conceptually simpler and taking the heap lock during world stop is guaranteed to not contend. This was only done on functions already called on the systemstack to avoid too many extra systemstack calls in GC. Updates #40677 Change-Id: I15aa1dadcdd1a81aac3d2a9ecad6e7d0377befdc Reviewed-on: https://go-review.googlesource.com/c/go/+/250262 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/mpagecache.go')
-rw-r--r--src/runtime/mpagecache.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/runtime/mpagecache.go b/src/runtime/mpagecache.go
index 5f76501a1c..4b5c66d8d6 100644
--- a/src/runtime/mpagecache.go
+++ b/src/runtime/mpagecache.go
@@ -71,8 +71,14 @@ func (c *pageCache) allocN(npages uintptr) (uintptr, uintptr) {
// into s. Then, it clears the cache, such that empty returns
// true.
//
-// p.mheapLock must be held or the world must be stopped.
+// p.mheapLock must be held.
+//
+// Must run on the system stack because p.mheapLock must be held.
+//
+//go:systemstack
func (c *pageCache) flush(p *pageAlloc) {
+ assertLockHeld(p.mheapLock)
+
if c.empty() {
return
}
@@ -103,7 +109,13 @@ func (c *pageCache) flush(p *pageAlloc) {
// chunk.
//
// p.mheapLock must be held.
+//
+// Must run on the system stack because p.mheapLock must be held.
+//
+//go:systemstack
func (p *pageAlloc) allocToCache() pageCache {
+ assertLockHeld(p.mheapLock)
+
// 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(p.searchAddr.addr()) >= p.end {