9front - general discussion about 9front
 help / color / mirror / Atom feed
From: qwx@sciops.net
To: 9front@9front.org
Subject: Re: [9front] page(1) performance fixes
Date: Tue, 18 Jan 2022 02:18:07 +0100	[thread overview]
Message-ID: <9D6BEF2F599E49ED2BE34541320DADE0@wopr.sciops.net> (raw)
In-Reply-To: <E0E2C17856EE9BD645D68E2E2AC88C6B@wopr.sciops.net>

Hello,

Here's another patch improving on the previous one.  The previous
patch allowed readahead procs to skip over pages that others are
processing, but without touching the LRU queue, which frequently
results in pages being unloaded before they've been shown, and ending
up reloading them several times.  Touching the queue any time a page
is looked at in the loadpages loop avoids such issues.

I've also bumped the proc limit which helps avoid delays and hangs, I
don't really see a downside to doing this.

To recap the changes so far:

- 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

I'm still not satisfied with performance.  IMHO this implementation is
fairly fragile, and I haven't found an easy way to fix it.  It might be
a lot easier to do without libevent and using libthread etc, but I'd
like to implement that first to know for sure.

In the mean time, if this looks alright, I'd like to push it.
Thoughts?

Thanks!
qwx


diff 6f9838a6a5b80e0253bdc8fb194ad6f15eb655f5 uncommitted
--- 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(;;){

      reply	other threads:[~2022-01-18 10:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13  1:54 qwx
2022-01-14 11:30 ` cinap_lenrek
2022-01-14 17:48   ` qwx
2022-01-14 17:54     ` qwx
2022-01-18  1:18       ` qwx [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9D6BEF2F599E49ED2BE34541320DADE0@wopr.sciops.net \
    --to=qwx@sciops.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).