ref: 018c4e07e8d3d32db3325ce331bc34b29d451670
parent: 1ba67b57e8e863229f5eb19fceba5f7f7c224cf5
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Nov 3 17:39:28 EDT 2023
fs: clean up old freelists after compression
--- a/fs.c
+++ b/fs.c
@@ -2202,27 +2202,50 @@
{
char *e, buf[Offksz];
Mount *mnt;
+ Bptr bp, nb;
+ Arena *a;
+ Amsg *am;
vlong off;
- Amsg *a;
+ Blk *b;
Msg m;
int i;
while(1){
- a = chrecv(fs->admchan);
- switch(a->op){
+ am = chrecv(fs->admchan);
+ switch(am->op){
case AOsync:
- qlock(&fs->mutlk);
for(i = 0; i < fs->narena; i++){
+ a = &fs->arenas[i];
+ qlock(a);
+ if(a->nlog < a->reserve/(10*Blksz)){
+ qunlock(a);
+ continue;
+ }
+ bp = a->loghd;
epochstart(id);
- qlock(&fs->arenas[i]);
- if(fs->arenas[i].nlog > fs->arenas[i].reserve/(10*Blksz))
- if(compresslog(&fs->arenas[i]) == -1)
- fprint(2, "compress log: %r");
- qunlock(&fs->arenas[i]);
+ if(compresslog(a) == -1)
+ fprint(2, "compress log: %r");
+ qunlock(a);
epochend(id);
epochclean();
+
+ while(bp.addr != -1){
+ epochstart(id);
+ if((b = getblk(bp, 0)) == nil){
+ fprint(2, "could not load %B\n", bp);
+ fs->broken = 1;
+ break;
+ }
+ nb = b->logp;
+ freeblk(nil, b, b->bp);
+ dropblk(b);
+ epochend(id);
+ epochclean();
+ }
}
- if(a->halt)
+
+ qlock(&fs->mutlk);
+ if(am->halt)
ainc(&fs->rdonly);
epochstart(id);
for(mnt = fs->mounts; mnt != nil; mnt = mnt->next)
@@ -2234,12 +2257,12 @@
case AOsnap:
qlock(&fs->mutlk);
epochstart(id);
- snapfs(a);
+ snapfs(am);
epochend(id);
qunlock(&fs->mutlk);
break;
case AOclear:
- for(off = a->off; off < a->length; off += Blksz){
+ for(off = am->off; off < am->length; off += Blksz){
qlock(&fs->mutlk);
epochstart(id);
m.k = buf;
@@ -2246,11 +2269,11 @@
m.nk = sizeof(buf);
m.op = Oclearb;
m.k[0] = Kdat;
- PACK64(m.k+1, a->qpath);
+ PACK64(m.k+1, am->qpath);
PACK64(m.k+9, off);
m.v = nil;
m.nv = 0;
- if((e = upsert(a->mnt, &m, 1)) != nil){
+ if((e = upsert(am->mnt, &m, 1)) != nil){
fprint(2, "sweep: %s\n", e);
fs->broken++;
}
@@ -2258,14 +2281,14 @@
qunlock(&fs->mutlk);
epochclean();
}
- if(a->dent != nil){
- wunlock(a->dent);
- clunkdent(a->dent);
+ if(am->dent != nil){
+ wunlock(am->dent);
+ clunkdent(am->dent);
}
- clunkmount(a->mnt);
+ clunkmount(am->mnt);
break;
}
- free(a);
+ free(am);
}
}
@@ -2275,7 +2298,7 @@
Amsg *a;
while(1){
- sleep(500);
+ sleep(5000);
a = mallocz(sizeof(Amsg), 1);
if(a == nil){
fprint(2, "alloc sync msg: %r\n");