git: 9front

Download patch

ref: e56dc2a7b9e5fe71e694fd315b150c2da561741d
parent: b257fefc815be831485119950a8be6b4c7d50da7
author: cinap_lenrek <cinap_lenrek@rei2.9hal>
date: Thu Feb 16 13:04:08 EST 2012

kernel: remove duppage debug, add comments, cleanup

--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -140,8 +140,8 @@
 
 		lkp = *pg;
 		lock(lkp);
-		if(lkp->ref <= 0)
-			panic("fault: lkp->ref %d <= 0", lkp->ref);
+		if(lkp->ref < 1)
+			panic("fault: lkp->ref %d < 1", lkp->ref);
 		if(lkp->image == &swapimage)
 			ref = lkp->ref + swapcount(lkp->daddr);
 		else
@@ -149,7 +149,6 @@
 		if(ref == 1 && lkp->image){
 			/* save a copy of the original for the image cache */
 			duppage(lkp);
-
 			ref = lkp->ref;
 		}
 		unlock(lkp);
@@ -246,7 +245,7 @@
 	}
 	n = devtab[c->type]->read(c, kaddr, ask, daddr);
 	if(n != ask)
-		faulterror(Eioload, c, 0);
+		error(Eioload);
 	if(ask < BY2PG)
 		memset(kaddr+ask, 0, BY2PG-ask);
 
--- a/sys/src/9/port/page.c
+++ b/sys/src/9/port/page.c
@@ -266,7 +266,7 @@
 
 static int dupretries = 15000;
 
-int
+void
 duppage(Page *p)				/* Always call with p locked */
 {
 	Page *np;
@@ -275,25 +275,17 @@
 
 	retries = 0;
 retry:
-	/* don't dup shared page */
-	if(p->ref != 1){
-		print("duppage: p->ref %d != 1\n", p->ref);
-		return 0;
-	}
+	/* don't dup pages that are shared or have no image */
+	if(p->ref != 1 || p->image == nil || p->image->notext)
+		return;
 
-	/* don't dup pages with no image */
-	if(p->image == nil || p->image->notext){
-		print("duppage: noimage\n");
-		return 0;
-	}
-
 	if(retries++ > dupretries){
 		print("duppage %d, up %p\n", retries, up);
 		dupretries += 100;
 		if(dupretries > 100000)
-			panic("duppage\n");
+			panic("duppage");
 		uncachepage(p);
-		return 1;
+		return;
 	}
 
 	/*
@@ -300,7 +292,10 @@
 	 *  normal lock ordering is to call
 	 *  lock(&palloc) before lock(p).
 	 *  To avoid deadlock, we have to drop
-	 *  our locks and try again.
+	 *  our locks and try again. as the page
+	 *  is from the image cache, this might
+	 *  let someone else come in and grab it
+	 *  so we check page ref above.
 	 */
 	if(!canlock(&palloc)){
 		unlock(p);
@@ -314,7 +309,7 @@
 	if(palloc.freecount < swapalloc.highwater) {
 		unlock(&palloc);
 		uncachepage(p);
-		return 1;
+		return;
 	}
 
 	color = getpgcolor(p->va);
@@ -326,7 +321,7 @@
 	if(np == 0) {
 		unlock(&palloc);
 		uncachepage(p);
-		return 1;
+		return;
 	}
 
 	pageunchain(np);
@@ -344,7 +339,7 @@
 */
 	lock(np);
 	if(np->ref != 0)	/* should never happen */
-		panic("duppage: np->ref %d != 0\n", np->ref);
+		panic("duppage: np->ref %d != 0", np->ref);
 	unlock(&palloc);
 
 	/* Cache the new version */
@@ -355,8 +350,6 @@
 	cachepage(np, p->image);
 	unlock(np);
 	uncachepage(p);
-
-	return 0;
 }
 
 void
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -82,7 +82,7 @@
 void		dumpregs(Ureg*);
 void		dumpstack(void);
 Fgrp*		dupfgrp(Fgrp*);
-int		duppage(Page*);
+void		duppage(Page*);
 void		dupswap(Page*);
 void		edfinit(Proc*);
 char*		edfadmit(Proc*);
--