@@ 590,6 590,7 @@ qconsume(Queue *q, void *vp, int len)
Block *b;
int n, dowakeup;
uchar *p = vp;
+ Block *tofree = nil;
/* sync with qwrite */
ilock(q);
@@ 608,7 609,10 @@ qconsume(Queue *q, void *vp, int len)
break;
q->bfirst = b->next;
q->len -= BALLOC(b);
- freeb(b);
+
+ /* remember to free this */
+ b->next = tofree;
+ tofree = b;
};
if(n < len)
@@ 620,6 624,17 @@ qconsume(Queue *q, void *vp, int len)
b->rp += len;
q->dlen -= len;
+ /* discard the block if we're done with it */
+ if((q->state & Qmsg) || len == n){
+ b->next = 0;
+ q->len -= BALLOC(b);
+ q->dlen -= BLEN(b);
+
+ /* remember to free this */
+ b->next = tofree;
+ tofree = b;
+ }
+
/* if writer flow controlled, restart */
if((q->state & Qflow) && q->len < q->limit/2){
q->state &= ~Qflow;
@@ 632,14 647,9 @@ qconsume(Queue *q, void *vp, int len)
if(dowakeup)
wakeup(&q->wr);
- QDEBUG checkb(b, "qconsume 2");
- /* discard the block if we're done with it */
- if((q->state & Qmsg) || len == n){
- b->next = 0;
- q->len -= BALLOC(b);
- q->dlen -= BLEN(b);
- freeb(b);
- }
+ if(tofree != nil)
+ freeblist(tofree);
+
return len;
}
@@ 798,6 808,9 @@ qproduce(Queue *q, void *vp, int len)
q->state &= ~Qstarve;
dowakeup = 1;
}
+
+ if(q->len >= q->limit)
+ q->state |= Qflow;
iunlock(q);
if(dowakeup)
@@ 938,13 951,6 @@ qbread(Queue *q, int len)
q->len -= BALLOC(b);
QDEBUG checkb(b, "qbread 1");
- /* if writer flow controlled, restart */
- if((q->state & Qflow) && q->len < q->limit/2){
- q->state &= ~Qflow;
- dowakeup = 1;
- } else
- dowakeup = 0;
-
/* split block if it's too big and this is not a message-oriented queue */
nb = b;
if(n > len){
@@ 967,6 973,13 @@ qbread(Queue *q, int len)
nb->wp = nb->rp + len;
}
+ /* if writer flow controlled, restart */
+ if((q->state & Qflow) && q->len < q->limit/2){
+ q->state &= ~Qflow;
+ dowakeup = 1;
+ } else
+ dowakeup = 0;
+
iunlock(q);
/* wakeup flow controlled writers */
@@ 369,6 369,9 @@ needpages(void*)
void
setswapchan(Chan *c)
{
+ char dirbuf[DIRLEN];
+ Dir d;
+
if(swapimage.c) {
if(swapalloc.free != conf.nswap){
cclose(c);
@@ 376,5 379,20 @@ setswapchan(Chan *c)
}
cclose(swapimage.c);
}
+
+ /*
+ * if this isn't a file, set the swap space
+ * to be at most the size of the partition
+ */
+ if(devtab[c->type]->dc != L'M'){
+ devtab[c->type]->stat(c, dirbuf);
+ convM2D(dirbuf, &d);
+ if(d.length < conf.nswap*BY2PG){
+ conf.nswap = d.length/BY2PG;
+ swapalloc.top = &swapalloc.swmap[conf.nswap];
+ swapalloc.free = conf.nswap;
+ }
+ }
+
swapimage.c = c;
}