ref: 20955da8f1e6cf60c5755c850e4e453c29a43b23
parent: ffa663fec1eec67cf8f81fe2882e7393076ff235
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 22 12:36:07 EST 2022
blk: shard block locks by block address to reduce contention
--- a/blk.c
+++ b/blk.c
@@ -695,7 +695,6 @@
assert(b->type == Tsuper);
p = b->data;
- setflag(b, Bdirty);
memcpy(p, "gefs0001", 8); p += 8;
PBIT32(p, Blksz); p += 4;
PBIT32(p, Bufspc); p += 4;
@@ -753,20 +752,22 @@
Blk*
getblk(Bptr bp, int flg)
{
- Blk *b;
uvlong h;
+ Blk *b;
+ int i;
if((b = lookupblk(bp.addr)) != nil)
return cacheblk(b);
- qlock(&fs->blklk);
+ i = ihash(bp.addr) % nelem(fs->blklk);
+ qlock(&fs->blklk[i]);
if((b = lookupblk(bp.addr)) != nil){
cacheblk(b);
- qunlock(&fs->blklk);
+ qunlock(&fs->blklk[i]);
return b;
}
if((b = readblk(bp.addr, flg)) == nil){
- qunlock(&fs->blklk);
+ qunlock(&fs->blklk[i]);
return nil;
}else
setmalloctag(b, getcallerpc(&bp));
@@ -773,7 +774,7 @@
h = blkhash(b);
if((flg&GBnochk) == 0 && h != bp.hash){
fprint(2, "corrupt block %B: %llx != %llx\n", bp, blkhash(b), bp.hash);
- qunlock(&fs->blklk);
+ qunlock(&fs->blklk[i]);
abort();
return nil;
}
@@ -780,7 +781,7 @@
b->bp.hash = h;
b->bp.gen = bp.gen;
cacheblk(b);
- qunlock(&fs->blklk);
+ qunlock(&fs->blklk[i]);
return b;
}
--- a/dat.h
+++ b/dat.h
@@ -451,7 +451,7 @@
Dent *dtab[Ndtab];
/* slow block io */
- QLock blklk;
+ QLock blklk[32];
/* protected by lrulk */
Lock lrulk;