ref: d2295eeff9be8b903484084f6663c659de584e5f
parent: 2f90299a01a9da436855041e69df7e15b83bb411
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Oct 5 13:40:24 EDT 2023
blk: free blocks by Bptr
--- a/blk.c
+++ b/blk.c
@@ -915,14 +915,13 @@
return;
b->lastdrop = getcallerpc(&b);
/*
- * While a freed block can get resurrected
- * before quiescence, it's unlikely -- so
- * it goes into the bottom of the LRU to
- * get selected early for reuse.
+ * freed blocks go to the LRU bottom
+ * for early reuse.
*/
- if(checkflag(b, Bfreed))
+ if(checkflag(b, Bfreed)){
+ cachedel(b->bp.addr);
lrubot(b);
- else
+ }else
lrutop(b);
}
@@ -942,7 +941,7 @@
}
void
-deferfree(Tree *t, Bptr bp, Blk *b)
+freeblk(Tree *t, Bptr bp)
{
Bfree *f;
ulong ge;
@@ -955,7 +954,6 @@
if((f = malloc(sizeof(Bfree))) == nil)
return;
f->bp = bp;
- f->b = b;
ge = agetl(&fs->epoch);
f->next = fs->limbo[ge];
@@ -963,21 +961,6 @@
}
void
-freebp(Tree *t, Bptr bp)
-{
- deferfree(t, bp, nil);
-}
-
-void
-freeblk(Tree *t, Blk *b)
-{
- holdblk(b);
- b->freed = getcallerpc(&t);
- setflag(b, Bfreed);
- deferfree(t, b->bp, b);
-}
-
-void
epochstart(int tid)
{
ulong ge;
@@ -1018,8 +1001,6 @@
lock(a);
blkdealloc_lk(a, p->bp.addr);
cachedel(p->bp.addr);
- if(p->b != nil)
- dropblk(p->b);
unlock(a);
free(p);
p = n;
@@ -1133,7 +1114,7 @@
if(--fs->syncing == 0)
rwakeupall(&fs->syncrz);
qunlock(&fs->synclk);
- }else if(!checkflag(b, Bfreed)){
+ } else if(!checkflag(b, Bfreed)){
if(syncblk(b) == -1){
ainc(&fs->broken);
fprint(2, "write: %r\n");
--- a/cache.c
+++ b/cache.c
@@ -170,6 +170,7 @@
assert(b->ref == 0);
cachedel(b->bp.addr);
lrudel(b);
+ if(checkflag(b, Bcached)) print("cached %B freed %#p\n", b->bp, b->freed);
assert(!checkflag(b, Bcached));
b->flag = 0;
b->lasthold = 0;
--- a/dat.h
+++ b/dat.h
@@ -407,7 +407,6 @@
struct Bfree {
Bfree *next;
- Blk *b;
Bptr bp;
};
--- a/fns.h
+++ b/fns.h
@@ -53,8 +53,7 @@
void epochend(int);
void epochclean(void);
void freesync(void);
-void freeblk(Tree*, Blk*);
-void freebp(Tree*, Bptr);
+void freeblk(Tree*, Bptr);
int dlappend(Dlist *dl, Bptr);
int killblk(Tree*, Bptr);
int blkdealloc(vlong);
--- a/fs.c
+++ b/fs.c
@@ -376,7 +376,7 @@
memcpy(b->buf, t->buf, Blksz);
dropblk(t);
}
- freebp(f->mnt->root, bp);
+ freeblk(f->mnt->root, bp);
}else if(e != Esrch){
werrstr("%s", e);
return -1;
@@ -1994,7 +1994,7 @@
n = writeb(f, &kv[i], &bp[i], p, o, c, f->dent->length);
if(n == -1){
for(j = 0; j < i; j++)
- freebp(f->mnt->root, bp[i]);
+ freeblk(f->mnt->root, bp[i]);
wunlock(f->dent);
fprint(2, "%r");
putfid(f);
--- a/snap.c
+++ b/snap.c
@@ -161,7 +161,8 @@
}
}
bp = b->deadp;
- freeblk(&fs->snap, b);
+ freeblk(&fs->snap, b->bp);
+ setflag(b, Bfreed);
dropblk(b);
}
return nil;
--- a/tree.c
+++ b/tree.c
@@ -497,7 +497,7 @@
while(j < up->hi){
if(m.op == Oclearb){
bp = unpackbp(v.v, v.nv);
- freebp(t, bp);
+ freeblk(t, bp);
}
ok = apply(&v, &m, buf, sizeof(buf));
Copy:
@@ -636,8 +636,8 @@
l = newblk(t, b->type);
r = newblk(t, b->type);
if(l == nil || r == nil){
- freeblk(t, l);
- freeblk(t, r);
+ freeblk(t, l->bp);
+ freeblk(t, r->bp);
return -1;
}
@@ -735,8 +735,8 @@
l = newblk(t, b->type);
r = newblk(t, b->type);
if(l == nil || r == nil){
- freeblk(t, l);
- freeblk(t, r);
+ freeblk(t, l->bp);
+ freeblk(t, r->bp);
return -1;
}
d = l;
@@ -870,8 +870,8 @@
l = newblk(t, a->type);
r = newblk(t, a->type);
if(l == nil || r == nil){
- freeblk(t, l);
- freeblk(t, r);
+ freeblk(t, l->bp);
+ freeblk(t, r->bp);
return -1;
}
d = l;
@@ -1085,10 +1085,14 @@
Path *p;
for(p = path; p != path + npath; p++){
- if(p->b != nil)
- freeblk(t, p->b);
- if(p->m != nil)
- freeblk(t, p->m);
+ if(p->b != nil){
+ freeblk(t, p->b->bp);
+ setflag(p->b, Bfreed);
+ }
+ if(p->m != nil){
+ freeblk(t, p->m->bp);
+ setflag(p->m, Bfreed);
+ }
dropblk(p->b);
dropblk(p->nl);
dropblk(p->nr);
@@ -1192,7 +1196,8 @@
t->dirty = 1;
unlock(&t->lk);
- freeblk(t, b);
+ freeblk(t, b->bp);
+ setflag(b, Bfreed);
dropblk(b);
dropblk(r);
return nil;