From 2bc9e8e5e3b3eab7063c718fc6711b0a1cd14dbe Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 8 Nov 2013 22:31:26 +0100 Subject: kernel: make image cache not hold onto the channel, remove nocache flag the image cache should not hold onto the text file channel when not neccesary. now, the image keeps track of the number of page cache references in Image.pgref. if the number of page cache references and Image.ref are equal, this means all the references to this image are from the page cache. so no segments are using this image. in that case, we can close the channel, but keep the Image in the hash table. when attachimage() finds our image, it will check if Image.c is nil and reattach the channel to the image before it is used. the Image.nocache flag isnt needed anymore. --- sys/src/9/port/page.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'sys/src/9/port/page.c') diff --git a/sys/src/9/port/page.c b/sys/src/9/port/page.c index 50cb4efca..f9eda93f7 100644 --- a/sys/src/9/port/page.c +++ b/sys/src/9/port/page.c @@ -228,9 +228,6 @@ putpage(Page *p) return; } - if(p->image && p->image->nocache) - uncachepage(p); - if(p->image && p->image != &swapimage) pagechaintail(p); else @@ -294,8 +291,8 @@ duppage(Page *p) /* Always call with p locked */ return; } - /* No freelist cache with uncached image or when memory is very low */ - if(p->image->nocache || palloc.freecount < swapalloc.highwater) { + /* No freelist cache when memory is very low */ + if(palloc.freecount < swapalloc.highwater) { unlock(&palloc); uncachepage(p); return; @@ -360,8 +357,10 @@ void uncachepage(Page *p) /* Always called with a locked page */ { Page **l, *f; + Image *i; - if(p->image == 0) + i = p->image; + if(i == 0) return; lock(&palloc.hashlock); @@ -374,9 +373,13 @@ uncachepage(Page *p) /* Always called with a locked page */ l = &f->hash; } unlock(&palloc.hashlock); - putimage(p->image); p->image = 0; p->daddr = 0; + + lock(i); + i->pgref--; + unlock(i); + putimage(i); } void @@ -392,7 +395,11 @@ cachepage(Page *p, Image *i) if(p->image) panic("cachepage"); - incref(i); + lock(i); + i->ref++; + i->pgref++; + unlock(i); + lock(&palloc.hashlock); p->image = i; l = &pghash(p->daddr); -- cgit v1.2.3