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/segment.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'sys/src/9/port/segment.c') diff --git a/sys/src/9/port/segment.c b/sys/src/9/port/segment.c index 1e263fd43..04923d9e7 100644 --- a/sys/src/9/port/segment.c +++ b/sys/src/9/port/segment.c @@ -247,12 +247,8 @@ attachimage(int type, Chan *c, ulong base, ulong len) for(i = ihash(c->qid.path); i; i = i->hash) { if(c->qid.path == i->qid.path) { lock(i); - if(eqqid(c->qid, i->qid) && - eqqid(c->mqid, i->mqid) && - c->mchan == i->mchan && - c->type == i->type) { + if(eqchantdqid(c, i->type, i->dev, i->qid, 0) && c->qid.type == i->qid.type) goto found; - } unlock(i); } } @@ -274,18 +270,20 @@ attachimage(int type, Chan *c, ulong base, ulong len) imagealloc.free = i->next; lock(i); - incref(c); - i->nocache = (c->flag & CCACHE) == 0; - c->flag &= ~CCACHE; - i->c = c; i->type = c->type; + i->dev = c->dev; i->qid = c->qid; - i->mqid = c->mqid; - i->mchan = c->mchan; + l = &ihash(c->qid.path); i->hash = *l; *l = i; + found: + if(i->c == nil){ + i->c = c; + c->flag &= ~CCACHE; + incref(c); + } unlock(&imagealloc); if(i->s == 0) { @@ -360,12 +358,21 @@ putimage(Image *i) if(i->notext) return; + c = nil; lock(i); - if(--i->ref == 0) { + if(--i->ref == i->pgref){ + /* + * all remaining references to this image are from the + * page cache now. close the channel as we can reattach + * the chan on attachimage() + */ + c = i->c; + i->c = nil; + } + if(i->ref == 0){ l = &ihash(i->qid.path); mkqid(&i->qid, ~0, ~0, QTFILE); unlock(i); - c = i->c; lock(&imagealloc); for(f = *l; f; f = f->hash) { @@ -375,15 +382,13 @@ putimage(Image *i) } l = &f->hash; } - i->next = imagealloc.free; imagealloc.free = i; unlock(&imagealloc); - + } else + unlock(i); + if(c) ccloseq(c); /* does not block */ - return; - } - unlock(i); } long -- cgit v1.2.3