]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: simplify code
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 6 Aug 2014 14:36:48 +0000 (18:36 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 6 Aug 2014 14:36:48 +0000 (18:36 +0400)
Full spans can't be passed to UncacheSpan since we get rid of free.

LGTM=rsc
R=golang-codereviews
CC=golang-codereviews, khr, rsc
https://golang.org/cl/119490044

src/pkg/runtime/malloc.h
src/pkg/runtime/mcache.c
src/pkg/runtime/mcentral.c

index 810d4ac4023700bce2ea48d2ddbe14a2b8bcb958..1e26509bd9570119bc723e4ae4d3ffded1d8dc66 100644 (file)
@@ -508,7 +508,6 @@ void        runtime·MHeap_Free(MHeap *h, MSpan *s, int32 acct);
 void   runtime·MHeap_FreeStack(MHeap *h, MSpan *s);
 MSpan* runtime·MHeap_Lookup(MHeap *h, void *v);
 MSpan* runtime·MHeap_LookupMaybe(MHeap *h, void *v);
-void   runtime·MGetSizeClassInfo(int32 sizeclass, uintptr *size, int32 *npages, int32 *nobj);
 void*  runtime·MHeap_SysAlloc(MHeap *h, uintptr n);
 void   runtime·MHeap_MapBits(MHeap *h);
 void   runtime·MHeap_MapSpans(MHeap *h);
index ef31e76a36d98c9f53d968ca7040bc3bb935a85d..665173bff54b0488b1d0aa83e5e2ab3a9199c384 100644 (file)
@@ -82,7 +82,7 @@ runtime·MCache_Refill(MCache *c, int32 sizeclass)
        if(s->freelist != nil)
                runtime·throw("refill on a nonempty span");
        if(s != &emptymspan)
-               runtime·MCentral_UncacheSpan(&runtime·mheap.central[sizeclass], s);
+               s->incache = false;
 
        // Get a new cached span from the central lists.
        s = runtime·MCentral_CacheSpan(&runtime·mheap.central[sizeclass]);
index a39af41a244472048203eeb5826d5796d9379030..5699d11ee6bd702ffe7f0c70f2d1e207a6a8b923 100644 (file)
@@ -19,7 +19,6 @@
 #include "malloc.h"
 
 static bool MCentral_Grow(MCentral *c);
-static void MCentral_ReturnToHeap(MCentral *c, MSpan *s);
 
 // Initialize a single central free list.
 void
@@ -110,12 +109,9 @@ runtime·MCentral_UncacheSpan(MCentral *c, MSpan *s)
 
        s->incache = false;
 
-       if(s->ref == 0) {
-               // Free back to heap.  Unlikely, but possible.
-               MCentral_ReturnToHeap(c, s); // unlocks c
-               return;
-       }
-       
+       if(s->ref == 0)
+               runtime·throw("uncaching full span");
+
        cap = (s->npages << PageShift) / s->elemsize;
        n = cap - s->ref;
        if(n > 0) {
@@ -159,36 +155,29 @@ runtime·MCentral_FreeSpan(MCentral *c, MSpan *s, int32 n, MLink *start, MLink *
        }
 
        // s is completely freed, return it to the heap.
-       MCentral_ReturnToHeap(c, s); // unlocks c
+       runtime·MSpanList_Remove(s);
+       s->needzero = 1;
+       s->freelist = nil;
+       runtime·unlock(c);
+       runtime·unmarkspan((byte*)(s->start<<PageShift), s->npages<<PageShift);
+       runtime·MHeap_Free(&runtime·mheap, s, 0);
        return true;
 }
 
-void
-runtime·MGetSizeClassInfo(int32 sizeclass, uintptr *sizep, int32 *npagesp, int32 *nobj)
-{
-       int32 size;
-       int32 npages;
-
-       npages = runtime·class_to_allocnpages[sizeclass];
-       size = runtime·class_to_size[sizeclass];
-       *npagesp = npages;
-       *sizep = size;
-       *nobj = (npages << PageShift) / size;
-}
-
 // Fetch a new span from the heap and
 // carve into objects for the free list.
 static bool
 MCentral_Grow(MCentral *c)
 {
-       int32 i, n, npages;
-       uintptr size;
+       uintptr size, npages, cap, i, n;
        MLink **tailp, *v;
        byte *p;
        MSpan *s;
 
        runtime·unlock(c);
-       runtime·MGetSizeClassInfo(c->sizeclass, &size, &npages, &n);
+       npages = runtime·class_to_allocnpages[c->sizeclass];
+       size = runtime·class_to_size[c->sizeclass];
+       n = (npages << PageShift) / size;
        s = runtime·MHeap_Alloc(&runtime·mheap, npages, c->sizeclass, 0, 1);
        if(s == nil) {
                // TODO(rsc): Log out of memory
@@ -213,17 +202,3 @@ MCentral_Grow(MCentral *c)
        runtime·MSpanList_Insert(&c->nonempty, s);
        return true;
 }
-
-// Return s to the heap.  s must be unused (s->ref == 0).  Unlocks c.
-static void
-MCentral_ReturnToHeap(MCentral *c, MSpan *s)
-{
-       runtime·MSpanList_Remove(s);
-       s->needzero = 1;
-       s->freelist = nil;
-       if(s->ref != 0)
-               runtime·throw("ref wrong");
-       runtime·unlock(c);
-       runtime·unmarkspan((byte*)(s->start<<PageShift), s->npages<<PageShift);
-       runtime·MHeap_Free(&runtime·mheap, s, 0);
-}