aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mbitmap.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-06-07 22:59:29 -0400
committerAustin Clements <austin@google.com>2015-06-11 18:15:21 +0000
commitd57c889ae8bdfdddbfb242f90b90f649988a720e (patch)
tree97d84c2c17ff8e3171783859a0b99de56967b820 /src/runtime/mbitmap.go
parenta788c913fa667a723ca55539b41fee30291ed92e (diff)
downloadgo-d57c889ae8bdfdddbfb242f90b90f649988a720e.tar.xz
runtime: wait to update arena_used until after mapping bitmap
This avoids a race with gcmarkwb_m that was leading to faults. Fixes #10212. Change-Id: I6fcf8d09f2692227063ce29152cb57366ea22487 Reviewed-on: https://go-review.googlesource.com/10816 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mbitmap.go')
-rw-r--r--src/runtime/mbitmap.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go
index a1d5d8fc81..c97bf0a450 100644
--- a/src/runtime/mbitmap.go
+++ b/src/runtime/mbitmap.go
@@ -118,15 +118,20 @@ func subtract1(p *byte) *byte {
// mHeap_MapBits is called each time arena_used is extended.
// It maps any additional bitmap memory needed for the new arena memory.
+// It must be called with the expected new value of arena_used,
+// *before* h.arena_used has been updated.
+// Waiting to update arena_used until after the memory has been mapped
+// avoids faults when other threads try access the bitmap immediately
+// after observing the change to arena_used.
//
//go:nowritebarrier
-func mHeap_MapBits(h *mheap) {
+func mHeap_MapBits(h *mheap, arena_used uintptr) {
// Caller has added extra mappings to the arena.
// Add extra mappings of bitmap words as needed.
// We allocate extra bitmap pieces in chunks of bitmapChunk.
const bitmapChunk = 8192
- n := (mheap_.arena_used - mheap_.arena_start) / heapBitmapScale
+ n := (arena_used - mheap_.arena_start) / heapBitmapScale
n = round(n, bitmapChunk)
n = round(n, _PhysPageSize)
if h.bitmap_mapped >= n {