shithub: gefs

Download patch

ref: 24cb0baaaaffe67972734d90765b50b7ef6b45db
parent: 76d83e6d63310062f9e7f01a007085c7622d2ca6
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 14 01:11:22 EST 2023

blk: use blocks from the arena block cache for log compression

the arena blocks don't get freed, so if we pluck new ones
from the cache they'll get leaked; don't do that.

--- a/blk.c
+++ b/blk.c
@@ -403,7 +403,7 @@
 	char *p;
 
 	if(a->logtl != nil && checkflag(a->logtl, Bdirty))
-		enqueue(a->logtl);
+		syncblk(a->logtl);
 	/*
 	 * Prepare what we're writing back.
 	 * Arenas must be sized so that we can
@@ -444,16 +444,13 @@
 	initblk(b, blks[i++], -1, Tlog);
 	for(r = (Arange*)avlmin(a->free); r != nil; r = (Arange*)avlnext(r)){
 		if(b->logsz >= Logspc - Logslop){
-			if((nb = cachepluck()) == nil)
-				return -1;
 			a->nlog++;
+			nb = a->logbuf[a->lbidx++ % nelem(a->logbuf)];
 			initblk(nb, blks[i++], -1, Tlog);
-
 			b->logp = nb->bp;
 			setflag(b, Bdirty);
 			finalize(b);
-			enqueue(b);
-			dropblk(b);
+			syncblk(b);
 			b = nb;
 		}
 		p = b->data + b->logsz;
@@ -464,7 +461,7 @@
 		setflag(b, Bdirty);
 	}
 	finalize(b);
-	enqueue(b);
+	syncblk(b);
 
 	/*
 	 * now we have a valid freelist, and we can start
@@ -471,7 +468,6 @@
 	 * appending stuff to it. Clean up the old logs
 	 * and the eagerly allocated extra blocks.
 	 */
-	dropblk(a->logtl);
 	a->loghd = hd;
 	a->logtl = b;
 	for(; i < nblks; i++){
--- a/fs.c
+++ b/fs.c
@@ -259,6 +259,14 @@
 	return btupsert(mnt->root, m, nm);
 }
 
+/*
+ * When truncating a file, mutations need
+ * to wait for the sweeper to finish; this
+ * means the mutator needs to release the
+ * mutation lock, exit the epoch, and
+ * allow the sweeper to finish its job
+ * before resuming.
+ */
 static void
 truncwait(Dent *de, int id)
 {
--- a/load.c
+++ b/load.c
@@ -104,6 +104,8 @@
 		a = &fs->arenas[i];
 		a->logbuf[0] = cachepluck();
 		a->logbuf[1] = cachepluck();
+		a->logbuf[0]->bp = (Bptr){-1, -1, -1};
+		a->logbuf[1]->bp = (Bptr){-1, -1, -1};
 		if(loadlog(a, a->loghd) == -1)
 			sysfatal("load log %B: %r", a->loghd);
 	}