shithub: front

Download patch

ref: 8759403bdb867b564b8ec4f2ee130034f7ebc582
parent: 5c0670bfaefe6411157322437e6f220e63aefda4
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 2 15:52:12 EDT 2024

gefs: fix file truncation performance (thanks cinap)

We were inserting very oversized deletion messages when
removing a file, instead of inserting the right size
message. This also batches the insertions, reducing the
number of upserts.

--- a/sys/src/cmd/gefs/fs.c
+++ b/sys/src/cmd/gefs/fs.c
@@ -443,7 +443,7 @@
 static int
 readb(Tree *t, Fid *f, char *d, vlong o, vlong n, vlong sz)
 {
-	char buf[17], kvbuf[17+32];
+	char buf[Offksz], kvbuf[Offksz+32];
 	vlong fb, fo;
 	Bptr bp;
 	Blk *b;
@@ -2442,6 +2442,7 @@
 runsweep(int id, void*)
 {
 	char buf[Kvmax];
+	Msg mb[Kvmax/Offksz];
 	Bptr bp, nb, *oldhd;
 	vlong off;
 	Tree *t;
@@ -2448,7 +2449,6 @@
 	Arena *a;
 	Amsg *am;
 	Blk *b;
-	Msg m, mb[2];
 	int i, nm;
 
 	if((oldhd = calloc(fs->narena, sizeof(Bptr))) == nil)
@@ -2591,26 +2591,30 @@
 			if(am->dent != nil)
 				qlock(&am->dent->trunclk);
 			fs->snap.dirty = 1;
+			nm = 0;
 			for(off = am->off; off < am->end; off += Blksz){
-				qlock(&fs->mutlk);
-				if(waserror()){
+				mb[nm].op = Oclearb;
+				mb[nm].k = buf + Offksz * nm;
+				mb[nm].nk = Offksz;
+				mb[nm].k[0] = Kdat;
+				PACK64(mb[nm].k+1, am->qpath);
+				PACK64(mb[nm].k+9, off);
+				mb[nm].v = nil;
+				mb[nm].nv = 0;
+				if(++nm >= nelem(mb) || off + Blksz >= am->end){
+					qlock(&fs->mutlk);
+					if(waserror()){
+						qunlock(&fs->mutlk);
+						nexterror();
+					}
+					epochstart(id);
+					upsert(am->mnt, mb, nm);
+					epochend(id);
+					epochclean();
 					qunlock(&fs->mutlk);
-					nexterror();
+					poperror();
+					nm = 0;
 				}
-				epochstart(id);
-				m.k = buf;
-				m.nk = sizeof(buf);
-				m.op = Oclearb;
-				m.k[0] = Kdat;
-				PACK64(m.k+1, am->qpath);
-				PACK64(m.k+9, off);
-				m.v = nil;
-				m.nv = 0;
-				upsert(am->mnt, &m, 1);
-				epochend(id);
-				epochclean();
-				qunlock(&fs->mutlk);
-				poperror();
 			}
 			if(am->dent != nil){
 				am->dent->trunc = 0;
--