gefs: fix dlist cache limit by maintaining fs->dlcount

This commit is contained in:
cinap_lenrek 2025-01-05 00:11:47 +00:00
parent 5a460a150b
commit 2a622dfcec
2 changed files with 22 additions and 9 deletions

View file

@ -159,6 +159,8 @@ initfs(vlong cachesz)
sysfatal("cache too big"); sysfatal("cache too big");
if((fs->bcache = mallocz(fs->cmax*sizeof(Bucket), 1)) == nil) if((fs->bcache = mallocz(fs->cmax*sizeof(Bucket), 1)) == nil)
sysfatal("malloc: %r"); sysfatal("malloc: %r");
fs->dlcount = 0;
fs->dlcmax = fs->cmax/10; fs->dlcmax = fs->cmax/10;
if(fs->dlcmax < 4) if(fs->dlcmax < 4)
fs->dlcmax = 4; fs->dlcmax = 4;

View file

@ -16,11 +16,11 @@ dlflush(Dlist *dl)
if(dl->ins == nil) if(dl->ins == nil)
return; return;
traceb("dlflush", dl->ins->bp); traceb("dlflush", dl->ins->bp);
enqueue(dl->ins);
dropblk(dl->ins);
dl->hd = dl->ins->bp; dl->hd = dl->ins->bp;
if(dl->tl.addr == dl->hd.addr) if(dl->tl.addr == dl->hd.addr)
dl->tl = dl->hd; dl->tl = dl->hd;
enqueue(dl->ins);
dropblk(dl->ins);
dl->ins = nil; dl->ins = nil;
/* special case: the snap dlist has gen -1, skip it */ /* special case: the snap dlist has gen -1, skip it */
if(dl->gen != -1){ if(dl->gen != -1){
@ -57,6 +57,7 @@ dlcachedel(Dlist *dl, int hdel)
dl->cprev->cnext = dl->cnext; dl->cprev->cnext = dl->cnext;
dl->cnext = nil; dl->cnext = nil;
dl->cprev = nil; dl->cprev = nil;
fs->dlcount--;
} }
static Dlist* static Dlist*
@ -130,11 +131,10 @@ putdl(Dlist *dl)
if(dl->gen == -1) if(dl->gen == -1)
return; return;
dlcachedel(dl, 0); dlcachedel(dl, 0);
while(fs->dltail != nil && fs->dlcount >= fs->dlcmax){ while(fs->dlcount >= fs->dlcmax && (dt = fs->dltail) != nil){
dt = fs->dltail;
dlflush(dt);
dlcachedel(dt, 1); dlcachedel(dt, 1);
dropblk(dt->ins); dlflush(dt);
assert(dt->ins == nil);
free(dt); free(dt);
} }
@ -145,6 +145,7 @@ putdl(Dlist *dl)
if(fs->dlhead != nil) if(fs->dlhead != nil)
fs->dlhead->cprev = dl; fs->dlhead->cprev = dl;
fs->dlhead = dl; fs->dlhead = dl;
fs->dlcount++;
} }
void void
@ -267,13 +268,17 @@ reclaimblocks(vlong gen, vlong succ, vlong prev)
if(!btnext(&s, &s.kv)) if(!btnext(&s, &s.kv))
break; break;
kv2dlist(&s.kv, &dl); kv2dlist(&s.kv, &dl);
if(waserror()){
btexit(&s);
nexterror();
}
if(succ != -1 && dl.bgen <= prev) if(succ != -1 && dl.bgen <= prev)
mergedl(succ, dl.gen, dl.bgen); mergedl(succ, dl.gen, dl.bgen);
else if(dl.bgen <= prev) else if(dl.bgen <= prev)
mergedl(prev, dl.gen, dl.bgen); mergedl(prev, dl.gen, dl.bgen);
else else
freedl(&dl, 1); freedl(&dl, 1);
poperror();
} }
btexit(&s); btexit(&s);
if(succ != -1){ if(succ != -1){
@ -285,8 +290,14 @@ reclaimblocks(vlong gen, vlong succ, vlong prev)
if(!btnext(&s, &s.kv)) if(!btnext(&s, &s.kv))
break; break;
kv2dlist(&s.kv, &dl); kv2dlist(&s.kv, &dl);
if(dl.bgen > prev) if(dl.bgen <= prev)
freedl(&dl, 1); continue;
if(waserror()){
btexit(&s);
nexterror();
}
freedl(&dl, 1);
poperror();
} }
btexit(&s); btexit(&s);
} }