From: Dmitriy Vyukov Date: Wed, 2 May 2012 14:01:11 +0000 (+0400) Subject: runtime: avoid unnecessary zeroization of huge memory blocks X-Git-Tag: go1.1rc2~3265 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c1c851bbe806d8fb3f483a32e8dfac48522dfe21;p=gostls13.git 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 --- 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;