From d57c889ae8bdfdddbfb242f90b90f649988a720e Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 7 Jun 2015 22:59:29 -0400 Subject: 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 Reviewed-by: Austin Clements --- src/runtime/mbitmap.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/runtime/mbitmap.go') 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 { -- cgit v1.3-5-g9baa