commit ac5a97e6b3b136c1ab669ae19a813a81cce673eb from: Russ Cox date: Fri Jul 04 02:44:24 2008 UTC venti: reduce locking contention in buildindex commit - cd87898f5db211b3485d8cad2c00ea356ca96361 commit + ac5a97e6b3b136c1ab669ae19a813a81cce673eb blob - 1db36bd92b7af2b42d6c26b24e5b452fdd14dd14 blob + ce146f6db223f58ceb38ac4a5032ee952635a9cf --- src/cmd/venti/srv/bloom.c +++ src/cmd/venti/srv/bloom.c @@ -225,6 +225,22 @@ markbloomfilter(Bloom *b, u8int *score) rlock(&b->lk); qlock(&b->mod); _markbloomfilter(b, score); + qunlock(&b->mod); + runlock(&b->lk); +} + +void +markbloomfiltern(Bloom *b, u8int score[][20], int n) +{ + int i; + + if(b == nil || b->data == nil) + return; + + rlock(&b->lk); + qlock(&b->mod); + for(i=0; imod); runlock(&b->lk); } blob - 4b7b9bdda196839762a5f66e5f38b03df006cd74 blob + ce5103a7e4020271d8610fb5568e22f367f61f51 --- src/cmd/venti/srv/buildindex.c +++ src/cmd/venti/srv/buildindex.c @@ -11,6 +11,20 @@ enum MaxBufSize = 4*1024*1024, }; +typedef struct IEntryBuf IEntryBuf; +struct IEntryBuf +{ + IEntry ie[100]; + int nie; +}; + +typedef struct ScoreBuf ScoreBuf; +struct ScoreBuf +{ + uchar score[100][VtScoreSize]; + int nscore; +}; + int dumb; int errors; char **isect; @@ -117,10 +131,10 @@ threadmain(int argc, char *argv[]) /* start index procs */ fprint(2, "%T read index\n"); - isectdonechan = chancreate(sizeof(void*), 0); + isectdonechan = chancreate(sizeof(void*), 1); for(i=0; insects; i++){ if(shouldprocess(ix->sects[i])){ - ix->sects[i]->writechan = chancreate(sizeof(IEntry), 0); + ix->sects[i]->writechan = chancreate(sizeof(IEntryBuf), 1); vtproc(isectproc, ix->sects[i]); } } @@ -208,12 +222,17 @@ arenapartproc(void *v) ClumpInfo *ci, *cis; IEntry ie; Part *p; + IEntryBuf *buf, *b; + uchar *score; + ScoreBuf sb; p = v; threadsetname("arenaproc %s", p->name); + buf = MKNZ(IEntryBuf, ix->nsects); nskip = 0; tot = 0; + sb.nscore = 0; cis = MKN(ClumpInfo, ClumpChunks); for(i=0; inarenas; i++){ a = ix->arenas[i]; @@ -252,10 +271,23 @@ arenapartproc(void *v) tot++; x = indexsect(ix, ie.score); assert(0 <= x && x < ix->nsects); - if(ix->sects[x]->writechan) - send(ix->sects[x]->writechan, &ie); - if(ix->bloom) - markbloomfilter(ix->bloom, ie.score); + if(ix->sects[x]->writechan) { + b = &buf[x]; + b->ie[b->nie] = ie; + b->nie++; + if(b->nie == nelem(b->ie)) { + send(ix->sects[x]->writechan, b); + b->nie = 0; + } + } + if(ix->bloom) { + score = sb.score[sb.nscore++]; + scorecp(score, ie.score); + if(sb.nscore == nelem(sb.score)) { + markbloomfiltern(ix->bloom, sb.score, sb.nscore); + sb.nscore = 0; + } + } } } } @@ -264,6 +296,14 @@ arenapartproc(void *v) } add(&arenaentries, tot); add(&skipentries, nskip); + + for(i=0; insects; i++) + if(ix->sects[i]->writechan && buf[i].nie > 0) + send(ix->sects[i]->writechan, &buf[i]); + free(buf); + free(cis); + if(ix->bloom && sb.nscore > 0) + markbloomfiltern(ix->bloom, sb.score, sb.nscore); sendp(arenadonechan, p); } @@ -743,6 +783,7 @@ isectproc(void *v) uchar *data, *p; Buf *buf; IEntry ie; + IEntryBuf ieb; IPool *ipool; ISect *is; Minibuf *mbuf, *mb; @@ -837,14 +878,17 @@ isectproc(void *v) assert(p == data+nbuf*bufsize); n = 0; - while(recv(is->writechan, &ie) == 1){ - if(ie.ia.addr == 0) + while(recv(is->writechan, &ieb) == 1){ + if(ieb.nie == 0) break; - buck = score2bucket(is, ie.score); - i = buck/bufbuckets; - assert(i < nbuf); - bwrite(&buf[i], &ie); - n++; + for(j=0; j