shithub: gefs

Download patch

ref: 16e4185644abdd971c430634fa29b9325a360325
parent: bb7420d7d8bd0abd589481ae05c6e0ae95995e2d
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Apr 20 08:51:45 EDT 2023

blk: spread blocks across arenas

take into account the qid of the file being written
to, so different workers can flush in parallel when
writing.

--- a/blk.c
+++ b/blk.c
@@ -14,7 +14,7 @@
 #include "atomic.h"
 
 static vlong	blkalloc_lk(Arena*, int);
-static vlong	blkalloc(int);
+static vlong	blkalloc(int, uint);
 static int	blkdealloc_lk(vlong);
 static Blk*	initblk(Blk*, vlong, vlong, int);
 static int	logop(Arena *, vlong, vlong, int);
@@ -132,11 +132,15 @@
 }
 
 static Arena*
-pickarena(int hint, int tries)
+pickarena(uint ty, uint hint, int tries)
 {
-	int n;
+	uint n;
 
-	n = tries + hint + ainc(&fs->roundrobin)/1024;
+	n = hint + tries + ainc(&fs->roundrobin)/1024;
+	if(ty == Tdat)
+		n++;
+	if(hint % fs->narena == 0)
+		n++;
 	return &fs->arenas[n%fs->narena];
 }
 
@@ -640,7 +644,7 @@
 }
 
 static vlong
-blkalloc(int hint)
+blkalloc(int ty, uint hint)
 {
 	Arena *a;
 	vlong b;
@@ -648,7 +652,7 @@
 
 	tries = 0;
 Again:
-	a = pickarena(hint, tries);
+	a = pickarena(ty, hint, tries);
 	if(a == nil || tries == fs->narena){
 		werrstr("no empty arenas");
 		return -1;
@@ -741,12 +745,12 @@
 }
 
 Blk*
-newblk(Tree *t, int ty)
+newdblk(Tree *t, int ty, vlong hint)
 {
 	vlong bp;
 	Blk *b;
 
-	if((bp = blkalloc(ty)) == -1)
+	if((bp = blkalloc(ty, hint)) == -1)
 		return nil;
 	if((b = cachepluck()) == nil)
 		return nil;
@@ -753,6 +757,12 @@
 	initblk(b, bp, t->gen, ty);
 	b->alloced = getcallerpc(&t);
 	return b;
+}
+
+Blk*
+newblk(Tree *t, int ty)
+{
+	return newdblk(t, ty, 0);
 }
 
 Blk*
--- a/fns.h
+++ b/fns.h
@@ -27,8 +27,9 @@
 #define	PACK64(p,v)	do{(p)[0]=(v)>>56;(p)[1]=(v)>>48;(p)[2]=(v)>>40;(p)[3]=(v)>>32;\
 			   (p)[4]=(v)>>24;(p)[5]=(v)>>16;(p)[6]=(v)>>8;(p)[7]=(v);}while(0)
 
-Blk*	newblk(Tree *t, int type);
-Blk*	dupblk(Tree *t, Blk*);
+Blk*	newdblk(Tree *, int, vlong);
+Blk*	newblk(Tree *, int);
+Blk*	dupblk(Tree *, Blk*);
 Blk*	getroot(Tree*, int*);
 Blk*	getblk(Bptr, int);
 Blk*	holdblk(Blk*);
--- a/fs.c
+++ b/fs.c
@@ -335,7 +335,7 @@
 	if(frozen(f->mnt->root))
 		if(updatesnap(&f->mnt->root, f->mnt->root, f->mnt->name) != nil)
 			return -1;
-	b = newblk(f->mnt->root, Tdat);
+	b = newdblk(f->mnt->root, Tdat, f->qpath);
 	if(b == nil)
 		return -1;
 	t = nil;