ref: c32c77ec90cb57b1a0cdfd3a94f5693475f160c7
parent: 65400ec2148185b59cf4af747ff4dbe4748df944
author: Ori Bernstein <ori@eigenstate.org>
date: Sat May 13 17:18:28 EDT 2023
fs: reimplement flushing we only need to delay the rflush until the in flight requests are done; do that.
--- a/dat.h
+++ b/dat.h
@@ -37,6 +37,7 @@
Nrefbuf = 1024, /* number of ref incs before syncing */
Nfidtab = 1024, /* number of fit hash entries */
+ Nflushtab = 1024, /* flush table size */
Ndtab = 1024, /* number of dir tab entries */
Max9p = 32*KiB, /* biggest message size we're willing to negotiate */
Nsec = 1000LL*1000*1000, /* nanoseconds to the second */
@@ -377,7 +378,6 @@
Fcall;
Conn *conn;
int sz; /* the size of the message buf */
- Fmsg *flush; /* the flush message */
Amsg *a; /* admin messages */
uchar buf[];
};
@@ -508,8 +508,7 @@
usize ccount;
usize cmax;
- Lock mflushlk;
- Fmsg *mflush[Maxtag];
+ RWLock flushq[Nflushtab];
Stats stats;
};
--- a/fs.c
+++ b/fs.c
@@ -194,7 +194,7 @@
static void
respond(Fmsg *m, Fcall *r)
{
- Fcall rf;
+ RWLock *lk;
uchar buf[Max9p+IOHDRSZ];
int w, n;
@@ -205,14 +205,11 @@
w = write(m->conn->wfd, buf, n);
if(w != n)
fshangup(m->conn, Eio);
- if(m->type != Tflush) {
- lock(&fs->mflushlk);
- fs->mflush[m->tag] = nil;
- rf.type = Rflush;
- if(m->flush != nil)
- respond(m->flush, &rf);
- unlock(&fs->mflushlk);
- }
+ lk = &fs->flushq[ihash(m->tag) % Nflushtab];
+ if(m->type == Tflush)
+ wunlock(lk);
+ else
+ runlock(lk);
free(m);
}
@@ -660,7 +657,6 @@
m->conn = c;
m->sz = sz;
m->a = nil;
- m->flush = nil;
PBIT32(m->buf, sz);
*pm = m;
return 0;
@@ -2040,20 +2036,10 @@
void
fsflush(Fmsg *m)
{
- Fmsg *o;
Fcall r;
- lock(&fs->mflushlk);
- o = fs->mflush[m->oldtag];
- if(o != nil){
- if(o->flush != nil)
- free(o->flush);
- o->flush = m;
- }else{
- r.type = Rflush;
- respond(m, &r);
- }
- unlock(&fs->mflushlk);
+ r.type = Rflush;
+ respond(m, &r);
}
Conn *
@@ -2076,6 +2062,7 @@
void
runfs(int, void *pc)
{
+ RWLock *lk;
Conn *c;
u32int h;
char err[128];
@@ -2100,9 +2087,11 @@
}
dprint("← %F\n", &m->Fcall);
- lock(&fs->mflushlk);
- fs->mflush[m->tag] = m;
- unlock(&fs->mflushlk);
+ lk = &fs->flushq[ihash(m->tag) % Nflushtab];
+ if(m->type == Tflush)
+ wlock(lk);
+ else
+ rlock(lk);
h = ihash(m->fid) % fs->nreaders;
switch(m->type){