ref: 880b001017993ccb3146b7968e62e83f67742983
parent: 674086d9ed1009b5378e4358d5bf888a4f987dca
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jan 16 12:50:28 EST 2024
tree: free blocks when we get a replacing insert this slows down the freeing of blocks, but reduces the amount of blocks that we leak. (There is still a leak that needs to be hunted down)
--- a/fs.c
+++ b/fs.c
@@ -465,7 +465,6 @@
memcpy(b->buf, t->buf, Blksz);
dropblk(t);
}
- freeblk(r, nil, bp);
}
if(fo+n > Blksz)
n = Blksz-fo;
--- a/tree.c
+++ b/tree.c
@@ -512,11 +512,14 @@
i++;
j++;
cpkvp(&v, &v, buf, sizeof(buf));
- ok = apply(&v, &m, buf, sizeof(buf));
- if(ok && m.op == Oclearb){
+ if(v.nk > 0 && v.k[0] == Kdat)
+ if(m.op == Oclearb
+ || m.op == Oinsert
+ || m.op == Odelete){
bp = unpackbp(v.v, v.nv);
freeblk(t, nil, bp);
}
+ ok = apply(&v, &m, buf, sizeof(buf));
goto Copyloop;
/* Message before value: Insert message sequence */
case 1:
@@ -533,7 +536,10 @@
while(j < up->hi){
if(pullmsg(up, j, &v, &m, &full, spc) != 0)
break;
- if(ok && m.op == Oclearb){
+ if(ok && v.nk > 0 && v.k[0] == Kdat)
+ if(m.op == Oclearb
+ || m.op == Oinsert
+ || m.op == Odelete){
bp = unpackbp(v.v, v.nv);
freeblk(t, nil, bp);
}
@@ -690,11 +696,14 @@
j++;
cpkvp(&v, &v, buf, sizeof(buf));
copied += valsz(&v);
- ok = apply(&v, &m, buf, sizeof(buf));
- if(ok && m.op == Oclearb){
+ if(v.nk > 0 && v.k[0] == Kdat)
+ if(m.op == Oclearb
+ || m.op == Oinsert
+ || m.op == Odelete){
bp = unpackbp(v.v, v.nv);
freeblk(t, nil, bp);
}
+ ok = apply(&v, &m, buf, sizeof(buf));
goto Copyloop;
case 1:
j++;
@@ -711,7 +720,10 @@
while(j < up->hi){
if(pullmsg(up, j, &v, &m, &full, spc) != 0)
break;
- if(ok && m.op == Oclearb){
+ if(ok && v.nk > 0 && v.k[0] == Kdat)
+ if(m.op == Oclearb
+ || m.op == Oinsert
+ || m.op == Odelete){
bp = unpackbp(v.v, v.nv);
freeblk(t, nil, bp);
}
@@ -1347,7 +1359,7 @@
j = bufsearch(p[i], k, &m, &same);
if(j < 0 || !same)
continue;
- if(!(ok || m.op == Oinsert))
+ if(!(ok || m.op == Oinsert || m.op == Oclearb))
fatal("lookup %K << %M missing insert\n", k, &m);
ok = apply(r, &m, buf, nbuf);
for(j++; j < p[i]->nbuf; j++){