remove dupseg. Reference: /n/atom/patch/applied/nodupseg Date: Thu Jun 12 02:27:05 CES 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/port/page.c Thu Jun 12 02:26:41 2014 +++ /sys/src/nix/port/page.c Thu Jun 12 02:26:43 2014 @@ -252,7 +252,7 @@ * reacquired the segment locks */ if(dontalloc) - return 0; + return nil; lock(&pga); } @@ -352,98 +352,6 @@ unlock(&pga); return p; -} - -static int dupretries = 15000; - -int -duppage(Page *p) /* Always call with p locked */ -{ - Pgsza *pa; - Page *np; - int color; - int retries; - - retries = 0; -retry: - - if(retries++ > dupretries){ - print("duppage %d, up %#p\n", retries, up); - dupretries += 100; - if(dupretries > 100000) - panic("duppage"); - 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(&pga) before lock(p). - * To avoid deadlock, we have to drop - * our locks and try again. - */ - if(!canlock(&pga)){ - unlock(p); - if(up) - sched(); - lock(p); - goto retry; - } - - pa = &pga.pgsza[p->pgszi]; - /* No freelist cache when memory is very low */ - if(pa->freecount < Nminfree){ - unlock(&pga); - uncachepage(p); - return 1; - } - - color = p->color; - for(np = pa->head; np; np = np->next) - if(np->color == color) - break; - - /* No page of the correct color */ - if(np == nil){ - unlock(&pga); - uncachepage(p); - return 1; - } - - pageunchain(np); - pagechaintail(np); - /* - * XXX - here's a bug? - np is on the freelist but it's not really free. - * when we unlock palloc someone else can come in, decide to - * use np, and then try to lock it. they succeed after we've - * run copypage and cachepage and unlock(np). then what? - * they call pageunchain before locking(np), so it's removed - * from the freelist, but still in the cache because of - * cachepage below. if someone else looks in the cache - * before they remove it, the page will have a nonzero ref - * once they finally lock(np). - * - * What I know is that not doing the pagechaintail, but - * doing it at the end, to prevent the race, leads to a - * deadlock, even following the pga, pg lock ordering. -nemo - */ - lock(np); - unlock(&pga); - - /* Cache the new version */ - uncachepage(np); - np->va = p->va; - np->daddr = p->daddr; - copypage(p, np); - cachepage(np, p->image); - unlock(np); - uncachepage(p); - - return 0; } void --- /sys/src/nix/port/fault.c Thu Jun 12 02:26:45 2014 +++ /sys/src/nix/port/fault.c Thu Jun 12 02:26:46 2014 @@ -148,23 +148,19 @@ lock(lkp); ref = lkp->ref; - if(ref > 1) { + if(ref == 0) + panic("mach%d: %s %d fault %#p ref == 0", m->machno, up->text, up->pid, lkp); + if(ref == 1 && lkp->image == nil) + unlock(lkp); + else{ unlock(lkp); - new = newpage(0, &s, addr, pgsz, color); - if(s == 0) + if(s == nil) return -1; *pg = new; copypage(lkp, *pg); putpage(lkp); } - else { - /* save a copy of the original for the image cache */ - if(lkp->image != nil) - duppage(lkp); - - unlock(lkp); - } mmuattr = PTEWRITE|PTEVALID; (*pg)->modref = PG_MOD|PG_REF; break; @@ -225,8 +221,8 @@ *p = new; return; } -//iprint("pio: (%s) %#.4ux %#P %#lux pgsz=%#P\n", chanpath(s->image->c), s->type, addr, soff, pgsz); c = s->image->c; +//iprint("pio: (%s) %#.4ux %#P %#lux pgsz=%#P\n", chanpath(c), s->type, addr, soff, pgsz); ask = s->flen-soff; if(ask < 0){ --- /sys/src/nix/port/portfns.h Thu Jun 12 02:26:49 2014 +++ /sys/src/nix/port/portfns.h Thu Jun 12 02:26:50 2014 @@ -83,7 +83,6 @@ void dumpregs(Ureg*); void dumpstack(void); Fgrp* dupfgrp(Fgrp*); -int duppage(Page*); Segment* dupseg(Segment**, int, int); void dupswap(Page*); char* edfadmit(Proc*);