changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: kernel: get rid of auxpage() and preserve cache index bits in Page.va in mount cache

changeset 4350: 1f9d7811d546
parent 4349: b36183064b7a
child 4351: 71022a4ed87a
child 4352: 95701f864bec
author: cinap_lenrek@felloff.net
date: Mon, 16 Mar 2015 05:46:08 +0100
files: sys/src/9/bitsy/mmu.c sys/src/9/port/cache.c sys/src/9/port/page.c sys/src/9/port/portfns.h
description: kernel: get rid of auxpage() and preserve cache index bits in Page.va in mount cache

the mount cache uses Page.va to store cached range offset and
limit, but mips kernel uses cache index bits from Page.va to
maintain page coloring. Page.va was not initialized by auxpage().

this change removes auxpage() which was primarily used only
by the mount cache and use newpage() with cache file offset
page as va so we will get a page of the right color.

mount cache keeps the index bits intact by only using the top
and buttom PGSHIFT bits of Page.va for the range offset/limit.
     1.1--- a/sys/src/9/bitsy/mmu.c
     1.2+++ b/sys/src/9/bitsy/mmu.c
     1.3@@ -379,9 +379,9 @@ putmmu(uintptr va, uintptr pa, Page *pg)
     1.4 		if(l2pg != nil){
     1.5 			up->mmufree = l2pg->next;
     1.6 		} else {
     1.7-			l2pg = auxpage();
     1.8-			if(l2pg == nil)
     1.9-				pexit("out of memory", 1);
    1.10+			splx(s);
    1.11+			l2pg = newpage(0, 0, 0);
    1.12+			splhi();
    1.13 		}
    1.14 		l2pg->va = VA(kmap(l2pg));
    1.15 		up->l1page[va>>20] = l2pg;
     2.1--- a/sys/src/9/port/cache.c
     2.2+++ b/sys/src/9/port/cache.c
     2.3@@ -205,6 +205,11 @@ ccache(Chan *c)
     2.4 	return nil;
     2.5 }
     2.6 
     2.7+enum {
     2.8+	VABITS	= 8*sizeof(uintptr) - 2*PGSHIFT,
     2.9+	VAMASK	= (((uintptr)1 << VABITS)-1) << PGSHIFT,
    2.10+};
    2.11+
    2.12 static Page*
    2.13 cpage(Mntcache *m, ulong pn, ulong *po, ulong *pe)
    2.14 {
    2.15@@ -219,12 +224,19 @@ cpage(Mntcache *m, ulong pn, ulong *po, 
    2.16 		m->bitmap[pn/MAPBITS] &= ~b;
    2.17 		return nil;
    2.18 	}
    2.19-	/* see cachedata() below */
    2.20-	*po = (ulong)p->va & (BY2PG-1);
    2.21-	*pe = (ulong)p->va >> PGSHIFT;
    2.22+	*po = p->va & (BY2PG-1);
    2.23+	*pe = 1 + (p->va >> (PGSHIFT+VABITS));
    2.24+	assert(*po < *pe);
    2.25 	return p;
    2.26 }
    2.27 
    2.28+static void
    2.29+cpageset(Page *p, ulong po, ulong pe)
    2.30+{
    2.31+	assert(po < pe);
    2.32+	p->va = po | (p->va & VAMASK) | ((uintptr)pe - 1) << (PGSHIFT+VABITS);
    2.33+}
    2.34+
    2.35 int
    2.36 cread(Chan *c, uchar *buf, int len, vlong off)
    2.37 {
    2.38@@ -253,7 +265,7 @@ cread(Chan *c, uchar *buf, int len, vlon
    2.39 		p = cpage(m, pn, &po, &pe);
    2.40 		if(p == nil)
    2.41 			break;
    2.42-		if(po >= pe || offset < po || offset >= pe){
    2.43+		if(offset < po || offset >= pe){
    2.44 			putpage(p);
    2.45 			break;
    2.46 		}
    2.47@@ -326,8 +338,8 @@ cachedata(Mntcache *m, uchar *buf, int l
    2.48 			l = len;
    2.49 		p = cpage(m, pn, &po, &pe);
    2.50 		if(p != nil){
    2.51-			if(po >= pe || offset > pe || (offset+l) < po){
    2.52-				/* cached range empty or not extendable, set new cached range */
    2.53+			if(offset > pe || (offset+l) < po){
    2.54+				/* cached range not extendable, set new cached range */
    2.55 				po = offset;
    2.56 				pe = offset+l;
    2.57 			} else {
    2.58@@ -338,13 +350,12 @@ cachedata(Mntcache *m, uchar *buf, int l
    2.59 					pe = offset+l;
    2.60 			}
    2.61 		} else {
    2.62-			p = auxpage();
    2.63-			if(p == nil){
    2.64+			if(needpages(nil) || waserror()){
    2.65 				invalidate(m, offset + pn*BY2PG, len);
    2.66 				break;
    2.67 			}
    2.68-
    2.69-			p->va = 0;
    2.70+			p = newpage(0, nil, pn*BY2PG);
    2.71+			poperror();
    2.72 			p->daddr = cacheaddr(m, pn);
    2.73 			cachedel(&fscache, p->daddr);
    2.74 			cachepage(p, &fscache);
    2.75@@ -353,6 +364,7 @@ cachedata(Mntcache *m, uchar *buf, int l
    2.76 			po = offset;
    2.77 			pe = offset+l;
    2.78 		}
    2.79+		cpageset(p, po, pe);
    2.80 
    2.81 		k = kmap(p);
    2.82 		if(waserror()) {
    2.83@@ -365,9 +377,6 @@ cachedata(Mntcache *m, uchar *buf, int l
    2.84 		memmove((uchar*)VA(k) + offset, buf, l);
    2.85 		poperror();
    2.86 		kunmap(k);
    2.87-
    2.88-		/* update cached range */
    2.89-		p->va = po | (pe << PGSHIFT);
    2.90 		putpage(p);
    2.91 
    2.92 		offset = 0;
     3.1--- a/sys/src/9/port/page.c
     3.2+++ b/sys/src/9/port/page.c
     3.3@@ -234,26 +234,6 @@ putpage(Page *p)
     3.4 		freepages(p, p, 1);
     3.5 }
     3.6 
     3.7-Page*
     3.8-auxpage(void)
     3.9-{
    3.10-	Page *p;
    3.11-
    3.12-	lock(&palloc);
    3.13-	p = palloc.head;
    3.14-	if(p == nil || palloc.freecount < swapalloc.highwater) {
    3.15-		unlock(&palloc);
    3.16-		return nil;
    3.17-	}
    3.18-	palloc.head = p->next;
    3.19-	p->next = nil;
    3.20-	palloc.freecount--;
    3.21-	unlock(&palloc);
    3.22-	p->ref = 1;
    3.23-
    3.24-	return p;
    3.25-}
    3.26-
    3.27 void
    3.28 copypage(Page *f, Page *t)
    3.29 {
     4.1--- a/sys/src/9/port/portfns.h
     4.2+++ b/sys/src/9/port/portfns.h
     4.3@@ -10,7 +10,6 @@ Block*		allocb(int);
     4.4 int		anyhigher(void);
     4.5 int		anyready(void);
     4.6 Image*		attachimage(int, Chan*, uintptr, ulong);
     4.7-Page*		auxpage(void);
     4.8 Block*		bl2mem(uchar*, Block*, int);
     4.9 int		blocklen(Block*);
    4.10 void		bootlinks(void);
    4.11@@ -185,6 +184,7 @@ void		mul64fract(uvlong*, uvlong, uvlong
    4.12 void		muxclose(Mnt*);
    4.13 Chan*		namec(char*, int, int, ulong);
    4.14 void		nameerror(char*, char*);
    4.15+int		needpages(void*);
    4.16 Chan*		newchan(void);
    4.17 int		newfd(Chan*);
    4.18 Mhead*		newmhead(Chan*);