From 373e1e94d8bf4985bb1e0452d95ed500106dc631 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Mon, 10 Feb 2014 20:24:47 +0400 Subject: [PATCH] =?utf8?q?runtime:=20fix=20crash=20during=20cpu=20profilin?= =?utf8?q?g=20mp->mcache=20can=20be=20concurrently=20modified=20by=20runti?= =?utf8?q?me=C2=B7helpgc.=20In=20such=20case=20sigprof=20can=20remember=20?= =?utf8?q?mcache=3Dnil,=20then=20helpgc=20sets=20it=20to=20non-nil,=20then?= =?utf8?q?=20sigprof=20restores=20it=20back=20to=20nil,=20GC=20crashes=20w?= =?utf8?q?ith=20nil=20mcache.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit R=rsc CC=golang-codereviews https://golang.org/cl/58860044 --- src/pkg/runtime/proc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 52aee39ca3..c771d5f916 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -2115,7 +2115,6 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp) { int32 n; bool traceback; - MCache *mcache; // Do not use global m in this function, use mp instead. // On windows one m is sending reports about all the g's, so m means a wrong thing. byte m; @@ -2127,8 +2126,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp) return; // Profiling runs concurrently with GC, so it must not allocate. - mcache = mp->mcache; - mp->mcache = nil; + mp->mallocing++; // Define that a "user g" is a user-created goroutine, and a "system g" // is one that is m->g0 or m->gsignal. We've only made sure that we @@ -2216,7 +2214,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp) runtime·lock(&prof); if(prof.fn == nil) { runtime·unlock(&prof); - mp->mcache = mcache; + mp->mallocing--; return; } n = 0; @@ -2229,7 +2227,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp) } prof.fn(prof.pcbuf, n); runtime·unlock(&prof); - mp->mcache = mcache; + mp->mallocing--; } // Arrange to call fn with a traceback hz times a second. -- 2.48.1