From c1c851bbe806d8fb3f483a32e8dfac48522dfe21 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Wed, 2 May 2012 18:01:11 +0400 Subject: [PATCH] runtime: avoid unnecessary zeroization of huge memory blocks +move zeroization out of the heap mutex R=golang-dev, iant, rsc CC=golang-dev https://golang.org/cl/6094050 --- src/pkg/runtime/malloc.goc | 2 +- src/pkg/runtime/malloc.h | 2 +- src/pkg/runtime/mcentral.c | 2 +- src/pkg/runtime/mheap.c | 7 +++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index fbdd6bb021..4bea5e220c 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -60,7 +60,7 @@ runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed) npages = size >> PageShift; if((size & PageMask) != 0) npages++; - s = runtime·MHeap_Alloc(&runtime·mheap, npages, 0, 1); + s = runtime·MHeap_Alloc(&runtime·mheap, npages, 0, 1, zeroed); if(s == nil) runtime·throw("out of memory"); size = npages<sizeclass, &size, &npages, &n); - s = runtime·MHeap_Alloc(&runtime·mheap, npages, c->sizeclass, 0); + s = runtime·MHeap_Alloc(&runtime·mheap, npages, c->sizeclass, 0, 1); if(s == nil) { // TODO(rsc): Log out of memory runtime·lock(c); diff --git a/src/pkg/runtime/mheap.c b/src/pkg/runtime/mheap.c index 077217dc5d..a8a435b20e 100644 --- a/src/pkg/runtime/mheap.c +++ b/src/pkg/runtime/mheap.c @@ -66,7 +66,7 @@ runtime·MHeap_Init(MHeap *h, void *(*alloc)(uintptr)) // Allocate a new span of npage pages from the heap // and record its size class in the HeapMap and HeapMapCache. MSpan* -runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct) +runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct, int32 zeroed) { MSpan *s; @@ -81,6 +81,8 @@ runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct) } } runtime·unlock(h); + if(s != nil && *(uintptr*)(s->start<start<npages<start<start<npages<sizeclass = sizeclass;