]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: zero 2-word memory blocks in-place
authorDmitriy Vyukov <dvyukov@google.com>
Tue, 21 Jan 2014 06:53:51 +0000 (10:53 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Tue, 21 Jan 2014 06:53:51 +0000 (10:53 +0400)
Currently for 2-word blocks we set the flag to clear the flag. Makes no sense.
In particular on 32-bits we call memclr always.

R=golang-codereviews, dave, iant
CC=golang-codereviews, khr, rsc
https://golang.org/cl/41170044

src/pkg/runtime/malloc.goc
src/pkg/runtime/mgc0.c

index f83e498293f24b91ae2a3be3a6e6c45f977c0b2e..739c61e4f49b93e9cbf57d26e9e774cbdb2d085d 100644 (file)
@@ -75,7 +75,7 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag)
                if(!(flag & FlagNoZero)) {
                        v->next = nil;
                        // block is zeroed iff second word is zero ...
-                       if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0)
+                       if(size > 2*sizeof(uintptr) && ((uintptr*)v)[1] != 0)
                                runtime·memclr((byte*)v, size);
                }
                c->local_cachealloc += size;
@@ -205,8 +205,10 @@ runtime·free(void *v)
                c->local_largefree += size;
        } else {
                // Small object.
-               if(size > sizeof(uintptr))
+               if(size > 2*sizeof(uintptr))
                        ((uintptr*)v)[1] = (uintptr)0xfeedfeedfeedfeedll;       // mark as "needs to be zeroed"
+               else if(size > sizeof(uintptr))
+                       ((uintptr*)v)[1] = 0;
                // Must mark v freed before calling MCache_Free:
                // it might coalesce v and other blocks into a bigger span
                // and change the bitmap further.
index 393de7a8363c07498261c56c1774b2e0c781dc6f..6a1d625a75a1a2e8f7663a102b7334c8626a9ac2 100644 (file)
@@ -1867,9 +1867,11 @@ sweepspan(ParFor *desc, uint32 idx)
                                *(byte*)type_data = 0;
                                break;
                        }
-                       if(size > sizeof(uintptr))
+                       if(size > 2*sizeof(uintptr))
                                ((uintptr*)p)[1] = (uintptr)0xdeaddeaddeaddeadll;       // mark as "needs to be zeroed"
-                       
+                       else if(size > sizeof(uintptr))
+                               ((uintptr*)p)[1] = 0;
+
                        end->next = (MLink*)p;
                        end = (MLink*)p;
                        nfree++;