ref: 43b2656fa5c3795561642952f48712e200f89981
parent: 1a4e1fc2e52ab80b55ef0d7fdccca973267fb4cc
author: 9ferno <[email protected]>
date: Thu Dec 8 03:23:57 EST 2022
streamline ctl reads from multiple processes
--- a/9p.c
+++ b/9p.c
@@ -18,6 +18,8 @@
a = emalloc9p(sizeof(Aux));
a->dblkno = addr;
a->uid = uid;
+ a->ctlmsg = nil;
+ a->nctlmsg = 0;
return a;
}
@@ -26,6 +28,8 @@
{
if(a == nil)
return;
+ if(a->ctlmsg != nil)
+ free(a->ctlmsg);
free(a);
}
--- a/ctl.c
+++ b/ctl.c
@@ -72,33 +72,30 @@
return 0;
};
-void
-ctlread(Req *req)
+u64
+fillctlmsg(s8 *buf, u64 nbuf)
{
u64 nfree, used;
- char *buf;
- int n;
+ u64 n;
nfree = nfrees(&frees);
used = config.nblocks - nfree;
- buf = emalloc9p(MiB);
-/* n = snprint(buf, MiB, "pending writes %llud blocks\n", pendingwrites());*/
- n = snprint(buf, MiB, "hash buckets:\n");
- n += showhashbuckets(buf+n, MiB-n);
- n += snprint(buf+n, MiB-n, "memunits extents:\n");
- n += saveextents(&memunits, buf+n, MiB-n);
- n += snprint(buf+n, MiB-n, "frees extents:\n");
- n += saveextents(&frees, buf+n, MiB-n);
+ n = snprint(buf, nbuf, "hash buckets:\n");
+ n += showhashbuckets(buf+n, nbuf-n);
+ n += snprint(buf+n, nbuf-n, "memunits extents:\n");
+ n += saveextents(&memunits, buf+n, nbuf-n);
+ n += snprint(buf+n, nbuf-n, "frees extents:\n");
+ n += saveextents(&frees, buf+n, nbuf-n);
if(config.size > TiB)
- n += snprint(buf+n, MiB-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
- "(MiB) free %ulld, used %ulld, total %ulld\n"
+ n += snprint(buf+n, nbuf-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
+ "(nbuf) free %ulld, used %ulld, total %ulld\n"
"(GiB) free %ulld, used %ulld, total %ulld\n"
"(TiB) free %ulld, used %ulld, total %ulld\n",
nfree, used, config.nblocks,
- nfree * Blocksize / MiB,
- used * Blocksize / MiB,
- config.size / MiB,
+ nfree * Blocksize / nbuf,
+ used * Blocksize / nbuf,
+ config.size / nbuf,
nfree * Blocksize / GiB,
used * Blocksize / GiB,
config.size / GiB,
@@ -107,27 +104,27 @@
config.size / TiB
);
else if(config.size > GiB)
- n += snprint(buf+n, MiB-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
- "(MiB) free %ulld, used %ulld, total %ulld\n"
+ n += snprint(buf+n, nbuf-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
+ "(nbuf) free %ulld, used %ulld, total %ulld\n"
"(GiB) free %ulld, used %ulld, total %ulld\n",
nfree, used, config.nblocks,
- nfree * Blocksize / MiB,
- used * Blocksize / MiB,
- config.size / MiB,
+ nfree * Blocksize / nbuf,
+ used * Blocksize / nbuf,
+ config.size / nbuf,
nfree * Blocksize / GiB,
used * Blocksize / GiB,
config.size / GiB
);
- else if(config.size > MiB)
- n += snprint(buf+n, MiB-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
- "(MiB) free %ulld, used %ulld, total %ulld\n",
+ else if(config.size > nbuf)
+ n += snprint(buf+n, nbuf-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
+ "(nbuf) free %ulld, used %ulld, total %ulld\n",
nfree, used, config.nblocks,
- nfree * Blocksize / MiB,
- used * Blocksize / MiB,
- config.size / MiB
+ nfree * Blocksize / nbuf,
+ used * Blocksize / nbuf,
+ config.size / nbuf
);
else
- n += snprint(buf+n, MiB-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
+ n += snprint(buf+n, nbuf-n, "(blocks) free %ulld, used %ulld, total %ulld\n"
"(KiB) free %ulld, used %ulld, total %ulld\n",
nfree, used, config.nblocks,
nfree * Blocksize / KiB,
@@ -134,13 +131,31 @@
used * Blocksize / KiB,
config.size / KiB
);
- if(req->ifcall.offset < n){
- req->ofcall.count = min(req->ifcall.count,n);
- memcpy(req->ofcall.data, buf+req->ifcall.offset, req->ofcall.count);
+ if(n >= nbuf)
+ panic("increase ctl message buffer: n %llud nbuf %llud\n", n, nbuf);
+ return n;
+}
+
+void
+ctlread(Req *req)
+{
+ if(((Aux*)req->fid->aux)->ctlmsg == nil){
+ ((Aux*)req->fid->aux)->ctlmsg = emalloc9p(MiB);
+ ((Aux*)req->fid->aux)->nctlmsg = 0;
+ }
+ if(req->ifcall.offset == 0)
+ ((Aux*)req->fid->aux)->nctlmsg = fillctlmsg(((Aux*)req->fid->aux)->ctlmsg, MiB);
+ if(req->ifcall.offset < ((Aux*)req->fid->aux)->nctlmsg){
+ req->ofcall.count = min(req->ifcall.count,((Aux*)req->fid->aux)->nctlmsg-req->ifcall.offset);
+ memcpy(req->ofcall.data, ((Aux*)req->fid->aux)->ctlmsg+req->ifcall.offset, req->ofcall.count);
req->ofcall.offset = req->ifcall.offset+req->ofcall.count;
}
+ if(req->ifcall.offset == ((Aux*)req->fid->aux)->nctlmsg){
+ free(((Aux*)req->fid->aux)->ctlmsg);
+ ((Aux*)req->fid->aux)->ctlmsg = nil;
+ ((Aux*)req->fid->aux)->nctlmsg = 0;
+ }
respond(req, nil);
- free(buf);
}
u32 mpsrvpid = 0;
--- a/dat.h
+++ b/dat.h
@@ -231,6 +231,8 @@
u16 uid;
u8 tlocked; /* for exclusive use files, flag to indicate lock */
u64 dri; /* directory index while reading a directory */
+ s8 *ctlmsg;
+ u64 nctlmsg;
/* u64 lastreadahead; TODO */
};