]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid unnecessary zeroization of huge memory blocks
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 2 May 2012 14:01:11 +0000 (18:01 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 2 May 2012 14:01:11 +0000 (18:01 +0400)
+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
src/pkg/runtime/malloc.h
src/pkg/runtime/mcentral.c
src/pkg/runtime/mheap.c

index fbdd6bb021ff2e9e1afa01f5c550ca2da424177a..4bea5e220c46e90f889eb405075823d750ac5cd1 100644 (file)
@@ -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;
index 66919c911e8965ec2b400fe69b021da5dc2553c3..081ebd1394edef186bc8da6ccb145ca0cb1cedd1 100644 (file)
@@ -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);
index 6fc95aec7bb6841ef2994bcc4f89aab7aedd9f20..558b35b0e1d1e255091bb18342c6ed53fffc0bdb 100644 (file)
@@ -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);
index 077217dc5daafe2e4f932d715e9cdbb9faa91142..a8a435b20e97e456dbd5ac08a316f343a0dd3618 100644 (file)
@@ -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;