mirror of
https://github.com/golang/go
synced 2024-11-13 17:30:24 -07:00
runtime: inline MCache_Alloc() into mallocgc()
benchmark old ns/op new ns/op delta BenchmarkMalloc8 68 62 -8.63% BenchmarkMalloc16 75 69 -7.94% BenchmarkMallocTypeInfo8 102 98 -3.73% BenchmarkMallocTypeInfo16 108 103 -4.63% R=golang-dev, dave, khr CC=golang-dev https://golang.org/cl/9790043
This commit is contained in:
parent
47e0a3d7b1
commit
5166013f75
@ -31,9 +31,10 @@ runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
|
|||||||
int32 sizeclass;
|
int32 sizeclass;
|
||||||
intgo rate;
|
intgo rate;
|
||||||
MCache *c;
|
MCache *c;
|
||||||
|
MCacheList *l;
|
||||||
uintptr npages;
|
uintptr npages;
|
||||||
MSpan *s;
|
MSpan *s;
|
||||||
void *v;
|
MLink *v;
|
||||||
|
|
||||||
if(runtime·gcwaiting && g != m->g0 && m->locks == 0 && dogc)
|
if(runtime·gcwaiting && g != m->g0 && m->locks == 0 && dogc)
|
||||||
runtime·gosched();
|
runtime·gosched();
|
||||||
@ -56,9 +57,20 @@ runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
|
|||||||
else
|
else
|
||||||
sizeclass = runtime·size_to_class128[(size-1024+127) >> 7];
|
sizeclass = runtime·size_to_class128[(size-1024+127) >> 7];
|
||||||
size = runtime·class_to_size[sizeclass];
|
size = runtime·class_to_size[sizeclass];
|
||||||
v = runtime·MCache_Alloc(c, sizeclass, size, zeroed);
|
l = &c->list[sizeclass];
|
||||||
if(v == nil)
|
if(l->list == nil)
|
||||||
runtime·throw("out of memory");
|
runtime·MCache_Refill(c, sizeclass);
|
||||||
|
v = l->list;
|
||||||
|
l->list = v->next;
|
||||||
|
l->nlist--;
|
||||||
|
if(zeroed) {
|
||||||
|
v->next = nil;
|
||||||
|
// block is zeroed iff second word is zero ...
|
||||||
|
if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0)
|
||||||
|
runtime·memclr((byte*)v, size);
|
||||||
|
}
|
||||||
|
c->local_cachealloc += size;
|
||||||
|
c->local_objects++;
|
||||||
c->local_alloc += size;
|
c->local_alloc += size;
|
||||||
c->local_total_alloc += size;
|
c->local_total_alloc += size;
|
||||||
c->local_by_size[sizeclass].nmalloc++;
|
c->local_by_size[sizeclass].nmalloc++;
|
||||||
|
@ -305,7 +305,7 @@ struct MCache
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void* runtime·MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed);
|
void runtime·MCache_Refill(MCache *c, int32 sizeclass);
|
||||||
void runtime·MCache_Free(MCache *c, void *p, int32 sizeclass, uintptr size);
|
void runtime·MCache_Free(MCache *c, void *p, int32 sizeclass, uintptr size);
|
||||||
void runtime·MCache_ReleaseAll(MCache *c);
|
void runtime·MCache_ReleaseAll(MCache *c);
|
||||||
|
|
||||||
|
@ -10,35 +10,18 @@
|
|||||||
#include "arch_GOARCH.h"
|
#include "arch_GOARCH.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
void*
|
void
|
||||||
runtime·MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed)
|
runtime·MCache_Refill(MCache *c, int32 sizeclass)
|
||||||
{
|
{
|
||||||
MCacheList *l;
|
MCacheList *l;
|
||||||
MLink *v;
|
|
||||||
|
|
||||||
// Allocate from list.
|
// Replenish using central lists.
|
||||||
l = &c->list[sizeclass];
|
l = &c->list[sizeclass];
|
||||||
if(l->list == nil) {
|
if(l->list)
|
||||||
// Replenish using central lists.
|
runtime·throw("MCache_Refill: the list is not empty");
|
||||||
l->nlist = runtime·MCentral_AllocList(&runtime·mheap->central[sizeclass], &l->list);
|
l->nlist = runtime·MCentral_AllocList(&runtime·mheap->central[sizeclass], &l->list);
|
||||||
if(l->list == nil)
|
if(l->list == nil)
|
||||||
runtime·throw("out of memory");
|
runtime·throw("out of memory");
|
||||||
}
|
|
||||||
v = l->list;
|
|
||||||
l->list = v->next;
|
|
||||||
l->nlist--;
|
|
||||||
|
|
||||||
// v is zeroed except for the link pointer
|
|
||||||
// that we used above; zero that.
|
|
||||||
v->next = nil;
|
|
||||||
if(zeroed) {
|
|
||||||
// block is zeroed iff second word is zero ...
|
|
||||||
if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0)
|
|
||||||
runtime·memclr((byte*)v, size);
|
|
||||||
}
|
|
||||||
c->local_cachealloc += size;
|
|
||||||
c->local_objects++;
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take n elements off l and return them to the central free list.
|
// Take n elements off l and return them to the central free list.
|
||||||
|
Loading…
Reference in New Issue
Block a user