git: 9front

Download patch

ref: d9bb90f2456d2a3a623328a887f198b8c102e4fc
parent: 3c5a33eaa77e22461dffec4611b1941fecab6579
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Jul 27 02:42:41 EDT 2015

kernel: clunk the cache when removing cache flag on a channel, only call cread() chen CCACHE flag is set

to avoid double caching, attachimage() and setswapchan() clear
the CCACHE flag on the channel but this keeps the read ahread
state of the cache arround (until the chan gets closed), so also
call cclunk() to detach the mcp and free the read ahead state.

avoid the call to cread() when CCACHE flag is clear.

--- a/sys/src/9/port/devmnt.c
+++ b/sys/src/9/port/devmnt.c
@@ -706,7 +706,7 @@
 		if(nreq > c->iounit)
 			nreq = c->iounit;
 
-		if(type == Tread) {
+		if(type == Tread && (c->flag&CCACHE) != 0) {
 			nr = cread(c, (uchar*)uba, nreq, off);
 			if(nr > 0) {
 				nreq = nr;
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -232,6 +232,9 @@
 {
 	Image *i, **l;
 
+	c->flag &= ~CCACHE;
+	cclunk(c);
+
 	lock(&imagealloc);
 
 	/*
@@ -272,7 +275,6 @@
 	unlock(&imagealloc);
 	if(i->c == nil){
 		i->c = c;
-		c->flag &= ~CCACHE;
 		incref(c);
 	}
 
--- a/sys/src/9/port/swap.c
+++ b/sys/src/9/port/swap.c
@@ -424,6 +424,7 @@
 		}
 	}
 	c->flag &= ~CCACHE;
+	cclunk(c);
 	swapimage.c = c;
 	poperror();
 }
--