mirror of
https://github.com/golang/go
synced 2024-11-21 18:54:43 -07:00
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
This commit is contained in:
parent
0d55d9832f
commit
c1c851bbe8
@ -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<<PageShift;
|
||||
|
@ -380,7 +380,7 @@ struct MHeap
|
||||
extern MHeap runtime·mheap;
|
||||
|
||||
void runtime·MHeap_Init(MHeap *h, void *(*allocator)(uintptr));
|
||||
MSpan* runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct);
|
||||
MSpan* runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct, int32 zeroed);
|
||||
void runtime·MHeap_Free(MHeap *h, MSpan *s, int32 acct);
|
||||
MSpan* runtime·MHeap_Lookup(MHeap *h, void *v);
|
||||
MSpan* runtime·MHeap_LookupMaybe(MHeap *h, void *v);
|
||||
|
@ -207,7 +207,7 @@ MCentral_Grow(MCentral *c)
|
||||
|
||||
runtime·unlock(c);
|
||||
runtime·MGetSizeClassInfo(c->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);
|
||||
|
@ -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<<PageShift) != 0 && zeroed)
|
||||
runtime·memclr((byte*)(s->start<<PageShift), s->npages<<PageShift);
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -138,9 +140,6 @@ HaveSpan:
|
||||
MHeap_FreeLocked(h, t);
|
||||
}
|
||||
|
||||
if(*(uintptr*)(s->start<<PageShift) != 0)
|
||||
runtime·memclr((byte*)(s->start<<PageShift), s->npages<<PageShift);
|
||||
|
||||
// Record span info, because gc needs to be
|
||||
// able to map interior pointer to containing span.
|
||||
s->sizeclass = sizeclass;
|
||||
|
Loading…
Reference in New Issue
Block a user