shithub: riscv

Download patch

ref: c88ed6488f36eaa7d499dac424f647d166267dec
parent: de8580ed9f8fa2d34ae01f5b73bb14263322824a
author: cinap_lenrek <[email protected]>
date: Wed Jan 2 05:26:38 EST 2019

upas/fs: don't put messages on the lru that cannot be uncached

the lru is there to track least recently used messages so
we can evict them from the cache and refetch them again on
demand. for pop3 mailbox, which doesnt provide fetch routine,
the messages should never be put on the freelist.

--- a/sys/src/cmd/upas/fs/cache.c
+++ b/sys/src/cmd/upas/fs/cache.c
@@ -3,7 +3,7 @@
 #include "dat.h"
 
 static void
-addlru(Mcache *c, Message *m)
+addlru(Mailbox *c, Message *m)
 {
 	Message *l, **ll;
 
@@ -10,6 +10,8 @@
 	if((m->cstate & (Cheader|Cbody)) == 0)
 		return;
 
+	assert(c->fetch != nil);
+
 	c->nlru++;
 	ll = &c->lru;
 	while((l = *ll) != nil){
@@ -35,12 +37,12 @@
 }
 
 void
-cachefree(Mailbox *mb, Message *m, int force)
+cachefree(Mailbox *mb, Message *m)
 {
 	long i;
 	Message *s, **ll;
 
-	if(Topmsg(mb, m)){
+	if(Topmsg(mb, m) && mb->fetch != nil){
 		for(ll = &mb->lru; *ll != nil; ll = &((*ll)->lru)){
 			if(*ll == m){
 				mb->nlru--;
@@ -49,14 +51,12 @@
 				break;
 			}
 		}
-		if(mb->decache)
+		if(mb->decache != nil)
 			mb->decache(mb, m);
 		mb->cached -= m->csize;
 	}
 	for(s = m->part; s; s = s->next)
-		cachefree(mb, s, force);
-	if(!force && mb->fetch == nil)
-		return;
+		cachefree(mb, s);
 	if(m->mallocd){
 		free(m->start);
 		m->mallocd = 0;
@@ -94,6 +94,8 @@
 {
 	int n;
 
+	if(mb->fetch == nil)
+		return;
 	while(!Topmsg(mb, m)) m = m->whole;
 	addlru(mb, m);
 	while(mb->lru != nil && (mb->cached > cachetarg || mb->nlru > 10)){
@@ -103,7 +105,7 @@
 				return;
 			addlru(mb, mb->lru);
 		}
-		cachefree(mb, mb->lru, 0);
+		cachefree(mb, mb->lru);
 	}
 }
 
--- a/sys/src/cmd/upas/fs/dat.h
+++ b/sys/src/cmd/upas/fs/dat.h
@@ -207,7 +207,7 @@
 
 /**/
 void		putcache(Mailbox*, Message*);		/* asymmetricial */
-void		cachefree(Mailbox*, Message*, int);
+void		cachefree(Mailbox*, Message*);
 
 char*		syncmbox(Mailbox*, int);
 void*		emalloc(ulong);
--- a/sys/src/cmd/upas/fs/mbox.c
+++ b/sys/src/cmd/upas/fs/mbox.c
@@ -1041,7 +1041,7 @@
 
 		if(Topmsg(mb, m))
 			mtreedelete(mb, m);
-		cachefree(mb, m, 1);
+		cachefree(mb, m);
 		idxfree(m);
 	}
 	free(m->unixfrom);