merge
This commit is contained in:
commit
86d5243b67
|
@ -140,14 +140,20 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
|
||||||
|
|
||||||
lkp = *pg;
|
lkp = *pg;
|
||||||
lock(lkp);
|
lock(lkp);
|
||||||
|
if(lkp->ref <= 0)
|
||||||
|
panic("fault: lkp->ref %d <= 0", lkp->ref);
|
||||||
if(lkp->image == &swapimage)
|
if(lkp->image == &swapimage)
|
||||||
ref = lkp->ref + swapcount(lkp->daddr);
|
ref = lkp->ref + swapcount(lkp->daddr);
|
||||||
else
|
else
|
||||||
ref = lkp->ref;
|
ref = lkp->ref;
|
||||||
if(ref > 1) {
|
if(ref == 1 && lkp->image){
|
||||||
unlock(lkp);
|
/* 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);
|
new = newpage(0, &s, addr);
|
||||||
if(s == 0)
|
if(s == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -155,13 +161,6 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
|
||||||
copypage(lkp, *pg);
|
copypage(lkp, *pg);
|
||||||
putpage(lkp);
|
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;
|
mmuphys = PPN((*pg)->pa) | PTEWRITE | PTEVALID;
|
||||||
(*pg)->modref = PG_MOD|PG_REF;
|
(*pg)->modref = PG_MOD|PG_REF;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -275,6 +275,17 @@ duppage(Page *p) /* Always call with p locked */
|
||||||
|
|
||||||
retries = 0;
|
retries = 0;
|
||||||
retry:
|
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){
|
if(retries++ > dupretries){
|
||||||
print("duppage %d, up %p\n", retries, up);
|
print("duppage %d, up %p\n", retries, up);
|
||||||
|
@ -285,11 +296,6 @@ retry:
|
||||||
return 1;
|
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
|
* normal lock ordering is to call
|
||||||
* lock(&palloc) before lock(p).
|
* lock(&palloc) before lock(p).
|
||||||
|
@ -337,6 +343,8 @@ retry:
|
||||||
* once they finally lock(np).
|
* once they finally lock(np).
|
||||||
*/
|
*/
|
||||||
lock(np);
|
lock(np);
|
||||||
|
if(np->ref != 0) /* should never happen */
|
||||||
|
panic("duppage: np->ref %d != 0\n", np->ref);
|
||||||
unlock(&palloc);
|
unlock(&palloc);
|
||||||
|
|
||||||
/* Cache the new version */
|
/* Cache the new version */
|
||||||
|
|
Loading…
Reference in a new issue