From 3f85b6589809fc7d9f674dd73f26bbf641d90ef2 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 15 Jan 1999 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1999-01-15 --- port/qio.c | 45 +++++++++++++++++++++++++++++---------------- port/swap.c | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/port/qio.c b/port/qio.c index 4d7162f47b469acc98fef50c8517e6a4c773b3b5..3b6b72b7b4db85b11fbbabd6c042b50d86dd7aa8 100644 --- a/port/qio.c +++ b/port/qio.c @@ -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 */ diff --git a/port/swap.c b/port/swap.c index 337bdf0788d471d0d16ad0ccaa19c43028c2d8f3..6ee65b0d1e0db595002d60eee5bcb64e82445e15 100644 --- a/port/swap.c +++ b/port/swap.c @@ -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; }