]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use persistentalloc instead of SysAlloc in FixAlloc
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 10 Jun 2013 05:20:27 +0000 (09:20 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 10 Jun 2013 05:20:27 +0000 (09:20 +0400)
Also reduce FixAlloc allocation granulatiry from 128k to 16k,
small programs do not need that much memory for MCache's and MSpan's.

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/10140044

src/pkg/runtime/malloc.goc
src/pkg/runtime/malloc.h
src/pkg/runtime/mfixalloc.c
src/pkg/runtime/mheap.c

index 7b5b5980e36b9a6eec86c2f1728e74c7bf36cbd4..4d900d63b95c3660990423108789f3b365d89b5c 100644 (file)
@@ -407,7 +407,7 @@ runtime·mallocinit(void)
        runtime·mheap.arena_end = runtime·mheap.arena_start + arena_size;
 
        // Initialize the rest of the allocator.        
-       runtime·MHeap_Init(&runtime·mheap, runtime·SysAlloc);
+       runtime·MHeap_Init(&runtime·mheap);
        m->mcache = runtime·allocmcache();
 
        // See if it works.
index 41604501f0bc1f301afb4024b350c12f9f2d9d15..94907b1b0e309cf81a65dccdbf1267c995c16371 100644 (file)
@@ -108,7 +108,7 @@ enum
        // Tunable constants.
        MaxSmallSize = 32<<10,
 
-       FixAllocChunk = 128<<10,        // Chunk size for FixAlloc
+       FixAllocChunk = 16<<10,         // Chunk size for FixAlloc
        MaxMHeapList = 1<<(20 - PageShift),     // Maximum page length for fixed-size list in MHeap.
        HeapAllocChunk = 1<<20,         // Chunk size for heap growth
 
@@ -188,7 +188,6 @@ void*       runtime·SysReserve(void *v, uintptr nbytes);
 struct FixAlloc
 {
        uintptr size;
-       void *(*alloc)(uintptr);
        void (*first)(void *arg, byte *p);      // called first time p is returned
        void *arg;
        MLink *list;
@@ -198,7 +197,7 @@ struct FixAlloc
        uintptr sys;    // bytes obtained from system
 };
 
-void   runtime·FixAlloc_Init(FixAlloc *f, uintptr size, void *(*alloc)(uintptr), void (*first)(void*, byte*), void *arg);
+void   runtime·FixAlloc_Init(FixAlloc *f, uintptr size, void (*first)(void*, byte*), void *arg);
 void*  runtime·FixAlloc_Alloc(FixAlloc *f);
 void   runtime·FixAlloc_Free(FixAlloc *f, void *p);
 
@@ -432,7 +431,7 @@ struct MHeap
 };
 extern MHeap runtime·mheap;
 
-void   runtime·MHeap_Init(MHeap *h, void *(*allocator)(uintptr));
+void   runtime·MHeap_Init(MHeap *h);
 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);
index c7dab8aea802202af1eb82942380f768952727ea..9541511644157c9a8cafc22c98b4a571ddc18ed6 100644 (file)
 // Initialize f to allocate objects of the given size,
 // using the allocator to obtain chunks of memory.
 void
-runtime·FixAlloc_Init(FixAlloc *f, uintptr size, void *(*alloc)(uintptr), void (*first)(void*, byte*), void *arg)
+runtime·FixAlloc_Init(FixAlloc *f, uintptr size, void (*first)(void*, byte*), void *arg)
 {
        f->size = size;
-       f->alloc = alloc;
        f->first = first;
        f->arg = arg;
        f->list = nil;
@@ -44,9 +43,7 @@ runtime·FixAlloc_Alloc(FixAlloc *f)
        }
        if(f->nchunk < f->size) {
                f->sys += FixAllocChunk;
-               f->chunk = f->alloc(FixAllocChunk);
-               if(f->chunk == nil)
-                       runtime·throw("out of memory (FixAlloc)");
+               f->chunk = runtime·persistentalloc(FixAllocChunk, 0);
                f->nchunk = FixAllocChunk;
        }
        v = f->chunk;
index 11d78203de258d92f0d5733567af91c588b65758..f988fe3f263ee837b06ed18c7a1231eebc9ed92c 100644 (file)
@@ -51,12 +51,12 @@ RecordSpan(void *vh, byte *p)
 
 // Initialize the heap; fetch memory using alloc.
 void
-runtime·MHeap_Init(MHeap *h, void *(*alloc)(uintptr))
+runtime·MHeap_Init(MHeap *h)
 {
        uint32 i;
 
-       runtime·FixAlloc_Init(&h->spanalloc, sizeof(MSpan), alloc, RecordSpan, h);
-       runtime·FixAlloc_Init(&h->cachealloc, sizeof(MCache), alloc, nil, nil);
+       runtime·FixAlloc_Init(&h->spanalloc, sizeof(MSpan), RecordSpan, h);
+       runtime·FixAlloc_Init(&h->cachealloc, sizeof(MCache), nil, nil);
        // h->mapcache needs no init
        for(i=0; i<nelem(h->free); i++)
                runtime·MSpanList_Init(&h->free[i]);