ref: 9d43029ff984435111eff658308a44b4f3eee1cc
parent: aa14ba62fd02ffd0e7053c23b2918e7aa46bcb86
author: qwx <[email protected]>
date: Wed Jan 19 17:58:53 EST 2022
page: performance fixes - fix showpage1 only decrementing proc counter once limit is reached; this blocked having more than one loadpages process after NPROC calls, since the next one has to wait until the last has exited - allow procs to skip pages currently being loaded by others; this forced processes to wait for each other at the same page - bump NPROC from 4 to 8 - (hack) immediately fork a few times after adding all pages at startup to force loading a batch of pages in parallel
--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -54,7 +54,7 @@
char pagespool[] = "/tmp/pagespool.";
enum {
- NPROC = 4,
+ NPROC = 8,
NBUF = 8*1024,
NPATH = 1024,
};
@@ -898,10 +898,6 @@
{
int fd;
- qlock(&lru);
- llinkhead(p);
- qunlock(&lru);
-
if(p->open != nil && p->image == nil){
fd = openpage(p);
if(fd >= 0){
@@ -951,7 +947,11 @@
loadpages(Page *p, int oviewgen)
{
while(p != nil && viewgen == oviewgen){
- qlock(p);
+ qlock(&lru);
+ llinkhead(p);
+ qunlock(&lru);
+ if(!canqlock(p))
+ goto next;
loadpage(p);
if(viewgen != oviewgen){
unloadpage(p);
@@ -972,6 +972,7 @@
unlockdisplay(display);
}
qunlock(p);
+ next:
if(p != current && imemsize >= imemlimit)
break; /* only one page ahead once we reach the limit */
if(forward < 0){
@@ -1309,16 +1310,17 @@
writeaddr(p, "/dev/label");
current = p;
oviewgen = viewgen;
+ if(nproc >= NPROC)
+ waitpid();
switch(rfork(RFPROC|RFMEM)){
case -1:
sysfatal("rfork: %r");
case 0:
loadpages(p, oviewgen);
+ nproc--;
exits(nil);
}
- if(++nproc >= NPROC)
- if(waitpid() > 0)
- nproc--;
+ nproc++;
}
/* recursive display lock, called from main proc only */
@@ -1691,6 +1693,8 @@
addpage(root, "stdin", popenfile, strdup("/fd/0"), -1);
for(; *argv; argv++)
addpage(root, *argv, popenfile, strdup(*argv), -1);
+ for(i=0; i<NPROC/4; i++) /* rice */
+ showpage1(current);
drawlock(1);
for(;;){