mirror of
https://github.com/golang/go
synced 2024-10-03 06:21:21 -06:00
runtime: don't touch pages of memory unnecessarily.
cuts working size for hello world from 6 MB to 1.2 MB. still some work to be done, but diminishing returns. R=r https://golang.org/cl/165080
This commit is contained in:
parent
33649bd278
commit
0d3301a557
@ -113,8 +113,9 @@ struct MLink
|
|||||||
MLink *next;
|
MLink *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
// SysAlloc obtains a large chunk of memory from the operating system,
|
// SysAlloc obtains a large chunk of zeroed memory from the
|
||||||
// typically on the order of a hundred kilobytes or a megabyte.
|
// operating system, typically on the order of a hundred kilobytes
|
||||||
|
// or a megabyte.
|
||||||
//
|
//
|
||||||
// SysUnused notifies the operating system that the contents
|
// SysUnused notifies the operating system that the contents
|
||||||
// of the memory region are no longer needed and can be reused
|
// of the memory region are no longer needed and can be reused
|
||||||
@ -312,4 +313,3 @@ enum
|
|||||||
RefSome, // some references
|
RefSome, // some references
|
||||||
RefNoPointers = 0x80000000U, // flag - no pointers here
|
RefNoPointers = 0x80000000U, // flag - no pointers here
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ MCentral_AllocList(MCentral *c, int32 n, MLink **pfirst)
|
|||||||
MLink *first, *last, *v;
|
MLink *first, *last, *v;
|
||||||
int32 i;
|
int32 i;
|
||||||
|
|
||||||
|
|
||||||
lock(c);
|
lock(c);
|
||||||
// Replenish central list if empty.
|
// Replenish central list if empty.
|
||||||
if(MSpanList_IsEmpty(&c->nonempty)) {
|
if(MSpanList_IsEmpty(&c->nonempty)) {
|
||||||
|
@ -91,8 +91,11 @@ mark(void)
|
|||||||
{
|
{
|
||||||
G *gp;
|
G *gp;
|
||||||
|
|
||||||
// mark data+bss
|
// mark data+bss.
|
||||||
scanblock(0, data, end - data);
|
// skip mheap itself, which has no interesting pointers
|
||||||
|
// and is mostly zeroed and would not otherwise be paged in.
|
||||||
|
scanblock(0, data, (byte*)&mheap - data);
|
||||||
|
scanblock(0, (byte*)(&mheap+1), end - (byte*)(&mheap+1));
|
||||||
|
|
||||||
// mark stacks
|
// mark stacks
|
||||||
for(gp=allg; gp!=nil; gp=gp->alllink) {
|
for(gp=allg; gp!=nil; gp=gp->alllink) {
|
||||||
|
@ -194,7 +194,6 @@ MHeap_Grow(MHeap *h, uintptr npage)
|
|||||||
// NOTE(rsc): In tcmalloc, if we've accumulated enough
|
// NOTE(rsc): In tcmalloc, if we've accumulated enough
|
||||||
// system allocations, the heap map gets entirely allocated
|
// system allocations, the heap map gets entirely allocated
|
||||||
// in 32-bit mode. (In 64-bit mode that's not practical.)
|
// in 32-bit mode. (In 64-bit mode that's not practical.)
|
||||||
|
|
||||||
if(!MHeapMap_Preallocate(&h->map, ((uintptr)v>>PageShift) - 1, (ask>>PageShift) + 2)) {
|
if(!MHeapMap_Preallocate(&h->map, ((uintptr)v>>PageShift) - 1, (ask>>PageShift) + 2)) {
|
||||||
SysFree(v, ask);
|
SysFree(v, ask);
|
||||||
return false;
|
return false;
|
||||||
|
@ -84,7 +84,6 @@ MHeapMap_Preallocate(MHeapMap *m, PageID k, uintptr len)
|
|||||||
p2 = m->allocator(sizeof *p2);
|
p2 = m->allocator(sizeof *p2);
|
||||||
if(p2 == nil)
|
if(p2 == nil)
|
||||||
return false;
|
return false;
|
||||||
runtime_memclr((byte*)p2, sizeof *p2);
|
|
||||||
m->p[i1] = p2;
|
m->p[i1] = p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,6 @@ MHeapMap_Preallocate(MHeapMap *m, PageID k, uintptr len)
|
|||||||
p2 = m->allocator(sizeof *p2);
|
p2 = m->allocator(sizeof *p2);
|
||||||
if(p2 == nil)
|
if(p2 == nil)
|
||||||
return false;
|
return false;
|
||||||
runtime_memclr((byte*)p2, sizeof *p2);
|
|
||||||
m->p[i1] = p2;
|
m->p[i1] = p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +104,6 @@ MHeapMap_Preallocate(MHeapMap *m, PageID k, uintptr len)
|
|||||||
p3 = m->allocator(sizeof *p3);
|
p3 = m->allocator(sizeof *p3);
|
||||||
if(p3 == nil)
|
if(p3 == nil)
|
||||||
return false;
|
return false;
|
||||||
runtime_memclr((byte*)p3, sizeof *p3);
|
|
||||||
p2->p[i2] = p3;
|
p2->p[i2] = p3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +102,10 @@ schedinit(void)
|
|||||||
mallocinit();
|
mallocinit();
|
||||||
goargs();
|
goargs();
|
||||||
|
|
||||||
|
// For debugging:
|
||||||
// Allocate internal symbol table representation now,
|
// Allocate internal symbol table representation now,
|
||||||
// so that we don't need to call malloc when we crash.
|
// so that we don't need to call malloc when we crash.
|
||||||
findfunc(0);
|
// findfunc(0);
|
||||||
|
|
||||||
sched.gomaxprocs = 1;
|
sched.gomaxprocs = 1;
|
||||||
p = getenv("GOMAXPROCS");
|
p = getenv("GOMAXPROCS");
|
||||||
|
@ -24,40 +24,6 @@
|
|||||||
#define SYMDATA ((byte*)(0x99LL<<24) + 8)
|
#define SYMDATA ((byte*)(0x99LL<<24) + 8)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Return a pointer to a byte array containing the symbol table segment.
|
|
||||||
void
|
|
||||||
runtime·symdat(Slice *symtab, Slice *pclntab)
|
|
||||||
{
|
|
||||||
Slice *a;
|
|
||||||
int32 *v;
|
|
||||||
|
|
||||||
// TODO(rsc): Remove once TODO at top of file is done.
|
|
||||||
if(goos != nil && strcmp((uint8*)goos, (uint8*)"nacl") == 0) {
|
|
||||||
symtab = mal(sizeof *a);
|
|
||||||
pclntab = mal(sizeof *a);
|
|
||||||
FLUSH(&symtab);
|
|
||||||
FLUSH(&pclntab);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v = SYMCOUNTS;
|
|
||||||
|
|
||||||
a = mal(sizeof *a);
|
|
||||||
a->len = v[0];
|
|
||||||
a->cap = a->len;
|
|
||||||
a->array = SYMDATA;
|
|
||||||
symtab = a;
|
|
||||||
FLUSH(&symtab);
|
|
||||||
|
|
||||||
a = mal(sizeof *a);
|
|
||||||
a->len = v[1];
|
|
||||||
a->cap = a->len;
|
|
||||||
a->array = SYMDATA + v[0];
|
|
||||||
pclntab = a;
|
|
||||||
FLUSH(&pclntab);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct Sym Sym;
|
typedef struct Sym Sym;
|
||||||
struct Sym
|
struct Sym
|
||||||
{
|
{
|
||||||
@ -122,6 +88,8 @@ static int32 nfunc;
|
|||||||
static byte **fname;
|
static byte **fname;
|
||||||
static int32 nfname;
|
static int32 nfname;
|
||||||
|
|
||||||
|
static Lock funclock;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dofunc(Sym *sym)
|
dofunc(Sym *sym)
|
||||||
{
|
{
|
||||||
@ -379,8 +347,11 @@ findfunc(uintptr addr)
|
|||||||
Func *f;
|
Func *f;
|
||||||
int32 nf, n;
|
int32 nf, n;
|
||||||
|
|
||||||
|
lock(&funclock);
|
||||||
if(func == nil)
|
if(func == nil)
|
||||||
buildfuncs();
|
buildfuncs();
|
||||||
|
unlock(&funclock);
|
||||||
|
|
||||||
if(nfunc == 0)
|
if(nfunc == 0)
|
||||||
return nil;
|
return nil;
|
||||||
if(addr < func[0].entry || addr >= func[nfunc].entry)
|
if(addr < func[0].entry || addr >= func[nfunc].entry)
|
||||||
|
Loading…
Reference in New Issue
Block a user