Skip to content

Commit 779c45a

Browse files
committed
runtime: improved scheduler
Distribute runnable queues, memory cache and cache of dead G's per processor. Faster non-blocking syscall enter/exit. More conservative worker thread blocking/unblocking. R=dave, bradfitz, remyoudompheng, rsc CC=golang-dev https://golang.org/cl/7314062
1 parent d17506e commit 779c45a

File tree

3 files changed

+993
-826
lines changed

3 files changed

+993
-826
lines changed

src/pkg/runtime/mgc0.c

+9-14
Original file line numberDiff line numberDiff line change
@@ -1633,20 +1633,12 @@ runtime·gchelper(void)
16331633
// extra memory used).
16341634
static int32 gcpercent = GcpercentUnknown;
16351635

1636-
static void
1637-
stealcache(void)
1638-
{
1639-
M *mp;
1640-
1641-
for(mp=runtime·allm; mp; mp=mp->alllink)
1642-
runtime·MCache_ReleaseAll(mp->mcache);
1643-
}
1644-
16451636
static void
16461637
cachestats(GCStats *stats)
16471638
{
16481639
M *mp;
16491640
MCache *c;
1641+
P *p, **pp;
16501642
int32 i;
16511643
uint64 stacks_inuse;
16521644
uint64 *src, *dst;
@@ -1655,8 +1647,6 @@ cachestats(GCStats *stats)
16551647
runtime·memclr((byte*)stats, sizeof(*stats));
16561648
stacks_inuse = 0;
16571649
for(mp=runtime·allm; mp; mp=mp->alllink) {
1658-
c = mp->mcache;
1659-
runtime·purgecachedstats(c);
16601650
stacks_inuse += mp->stackinuse*FixedStack;
16611651
if(stats) {
16621652
src = (uint64*)&mp->gcstats;
@@ -1665,6 +1655,12 @@ cachestats(GCStats *stats)
16651655
dst[i] += src[i];
16661656
runtime·memclr((byte*)&mp->gcstats, sizeof(mp->gcstats));
16671657
}
1658+
}
1659+
for(pp=runtime·allp; p=*pp; pp++) {
1660+
c = p->mcache;
1661+
if(c==nil)
1662+
continue;
1663+
runtime·purgecachedstats(c);
16681664
for(i=0; i<nelem(c->local_by_size); i++) {
16691665
mstats.by_size[i].nmalloc += c->local_by_size[i].nmalloc;
16701666
c->local_by_size[i].nmalloc = 0;
@@ -1819,12 +1815,11 @@ gc(struct gc_args *args)
18191815
runtime·parfordo(work.sweepfor);
18201816
t3 = runtime·nanotime();
18211817

1822-
stealcache();
1823-
cachestats(&stats);
1824-
18251818
if(work.nproc > 1)
18261819
runtime·notesleep(&work.alldone);
18271820

1821+
cachestats(&stats);
1822+
18281823
stats.nprocyield += work.sweepfor->nprocyield;
18291824
stats.nosyield += work.sweepfor->nosyield;
18301825
stats.nsleep += work.sweepfor->nsleep;

0 commit comments

Comments
 (0)