Commit 8a724175 by Ian Lance Taylor

runtime: Ignore stack sizes when deciding when to GC.

Also allocate heap bitmaps bit in page size units and clear
context when putting G structures on free list.

From-SVN: r186607
parent 8198dc13
...@@ -72,7 +72,7 @@ runtime_mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed) ...@@ -72,7 +72,7 @@ runtime_mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
npages = size >> PageShift; npages = size >> PageShift;
if((size & PageMask) != 0) if((size & PageMask) != 0)
npages++; npages++;
s = runtime_MHeap_Alloc(&runtime_mheap, npages, 0, !(flag & FlagNoGC)); s = runtime_MHeap_Alloc(&runtime_mheap, npages, 0, 1);
if(s == nil) if(s == nil)
runtime_throw("out of memory"); runtime_throw("out of memory");
size = npages<<PageShift; size = npages<<PageShift;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// Garbage collector. // Garbage collector.
#include <unistd.h>
#include "runtime.h" #include "runtime.h"
#include "arch.h" #include "arch.h"
#include "malloc.h" #include "malloc.h"
...@@ -918,7 +920,7 @@ cachestats(void) ...@@ -918,7 +920,7 @@ cachestats(void)
uint64 stacks_sys; uint64 stacks_sys;
stacks_inuse = 0; stacks_inuse = 0;
stacks_sys = 0; stacks_sys = runtime_stacks_sys;
for(m=runtime_allm; m; m=m->alllink) { for(m=runtime_allm; m; m=m->alllink) {
runtime_purgecachedstats(m); runtime_purgecachedstats(m);
// stacks_inuse += m->stackalloc->inuse; // stacks_inuse += m->stackalloc->inuse;
...@@ -1020,7 +1022,7 @@ runtime_gc(int32 force) ...@@ -1020,7 +1022,7 @@ runtime_gc(int32 force)
stealcache(); stealcache();
cachestats(); cachestats();
mstats.next_gc = mstats.heap_alloc+mstats.heap_alloc*gcpercent/100; mstats.next_gc = mstats.heap_alloc+(mstats.heap_alloc-runtime_stacks_sys)*gcpercent/100;
m->gcing = 0; m->gcing = 0;
m->locks++; // disable gc during the mallocs in newproc m->locks++; // disable gc during the mallocs in newproc
...@@ -1329,6 +1331,8 @@ runtime_setblockspecial(void *v, bool s) ...@@ -1329,6 +1331,8 @@ runtime_setblockspecial(void *v, bool s)
void void
runtime_MHeap_MapBits(MHeap *h) runtime_MHeap_MapBits(MHeap *h)
{ {
size_t page_size;
// Caller has added extra mappings to the arena. // Caller has added extra mappings to the arena.
// Add extra mappings of bitmap words as needed. // Add extra mappings of bitmap words as needed.
// We allocate extra bitmap pieces in chunks of bitmapChunk. // We allocate extra bitmap pieces in chunks of bitmapChunk.
...@@ -1342,6 +1346,9 @@ runtime_MHeap_MapBits(MHeap *h) ...@@ -1342,6 +1346,9 @@ runtime_MHeap_MapBits(MHeap *h)
if(h->bitmap_mapped >= n) if(h->bitmap_mapped >= n)
return; return;
page_size = getpagesize();
n = (n+page_size-1) & ~(page_size-1);
runtime_SysMap(h->arena_start - n, n - h->bitmap_mapped); runtime_SysMap(h->arena_start - n, n - h->bitmap_mapped);
h->bitmap_mapped = n; h->bitmap_mapped = n;
} }
...@@ -46,6 +46,8 @@ extern void __splitstack_block_signals_context (void *context[10], int *, ...@@ -46,6 +46,8 @@ extern void __splitstack_block_signals_context (void *context[10], int *,
# define StackMin 2 * 1024 * 1024 # define StackMin 2 * 1024 * 1024
#endif #endif
uintptr runtime_stacks_sys;
static void schedule(G*); static void schedule(G*);
typedef struct Sched Sched; typedef struct Sched Sched;
...@@ -1091,6 +1093,7 @@ schedule(G *gp) ...@@ -1091,6 +1093,7 @@ schedule(G *gp)
m->lockedg = nil; m->lockedg = nil;
} }
gp->idlem = nil; gp->idlem = nil;
runtime_memclr(&gp->context, sizeof gp->context);
gfput(gp); gfput(gp);
if(--runtime_sched.gcount == 0) if(--runtime_sched.gcount == 0)
runtime_exit(0); runtime_exit(0);
...@@ -1288,6 +1291,7 @@ runtime_malg(int32 stacksize, byte** ret_stack, size_t* ret_stacksize) ...@@ -1288,6 +1291,7 @@ runtime_malg(int32 stacksize, byte** ret_stack, size_t* ret_stacksize)
*ret_stacksize = stacksize; *ret_stacksize = stacksize;
newg->gcinitial_sp = *ret_stack; newg->gcinitial_sp = *ret_stack;
newg->gcstack_size = stacksize; newg->gcstack_size = stacksize;
runtime_xadd(&runtime_stacks_sys, stacksize);
#endif #endif
} }
return newg; return newg;
......
...@@ -463,3 +463,8 @@ struct root_list { ...@@ -463,3 +463,8 @@ struct root_list {
}; };
void __go_register_gc_roots(struct root_list*); void __go_register_gc_roots(struct root_list*);
// Size of stack space allocated using Go's allocator.
// This will be 0 when using split stacks, as in that case
// the stacks are allocated by the splitstack library.
extern uintptr runtime_stacks_sys;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment