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
This commit is contained in:
qwx 2022-01-19 22:58:53 +00:00
parent aa14ba62fd
commit 9d43029ff9

View file

@ -54,7 +54,7 @@ Image *frame, *paper, *ground;
char pagespool[] = "/tmp/pagespool.";
enum {
NPROC = 4,
NPROC = 8,
NBUF = 8*1024,
NPATH = 1024,
};
@ -898,10 +898,6 @@ loadpage(Page *p)
{
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 @@ void
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 @@ loadpages(Page *p, int oviewgen)
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 @@ showpage1(Page *p)
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 @@ main(int argc, char *argv[])
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(;;){