shithub: riscv

Download patch

ref: 86d5243b67fa419ba0b6883c78464b4cc2137287
parent: 436f0abcdabc7670cfbe66cd6b1a81a1058724ea
parent: 083612b34eb152ea20b31aa5d7fbef1c11e4173e
author: glenda <glenda@t9f>
date: Thu Feb 16 05:47:07 EST 2012

merge

--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -140,14 +140,20 @@
 
 		lkp = *pg;
 		lock(lkp);
-
+		if(lkp->ref <= 0)
+			panic("fault: lkp->ref %d <= 0", lkp->ref);
 		if(lkp->image == &swapimage)
 			ref = lkp->ref + swapcount(lkp->daddr);
 		else
 			ref = lkp->ref;
-		if(ref > 1) {
-			unlock(lkp);
+		if(ref == 1 && lkp->image){
+			/* save a copy of the original for the image cache */
+			duppage(lkp);
 
+			ref = lkp->ref;
+		}
+		unlock(lkp);
+		if(ref > 1){
 			new = newpage(0, &s, addr);
 			if(s == 0)
 				return -1;
@@ -154,13 +160,6 @@
 			*pg = new;
 			copypage(lkp, *pg);
 			putpage(lkp);
-		}
-		else {
-			/* save a copy of the original for the image cache */
-			if(lkp->image)
-				duppage(lkp);
-
-			unlock(lkp);
 		}
 		mmuphys = PPN((*pg)->pa) | PTEWRITE | PTEVALID;
 		(*pg)->modref = PG_MOD|PG_REF;
--- a/sys/src/9/port/page.c
+++ b/sys/src/9/port/page.c
@@ -275,7 +275,18 @@
 
 	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 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;
@@ -284,12 +295,7 @@
 		uncachepage(p);
 		return 1;
 	}
-		
 
-	/* don't dup pages with no image */
-	if(p->ref == 0 || p->image == nil || p->image->notext)
-		return 0;
-
 	/*
 	 *  normal lock ordering is to call
 	 *  lock(&palloc) before lock(p).
@@ -337,6 +343,8 @@
 * once they finally lock(np).
 */
 	lock(np);
+	if(np->ref != 0)	/* should never happen */
+		panic("duppage: np->ref %d != 0\n", np->ref);
 	unlock(&palloc);
 
 	/* Cache the new version */