early non-blocking stuff
[unix-history] / usr / src / sys / kern / vfs_bio.c
index 9814663..39beb56 100644 (file)
@@ -1,4 +1,4 @@
-/*     vfs_bio.c       4.11    %G%     */
+/*     vfs_bio.c       4.23    81/07/25        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -34,6 +34,9 @@
  *     brelse
  */
 
  *     brelse
  */
 
+struct buf bfreelist[BQUEUES];
+struct buf bswlist, *bclnlist;
+
 #define        BUFHSZ  63
 struct bufhd bufhash[BUFHSZ];
 #define        BUFHASH(dev, dblkno)    \
 #define        BUFHSZ  63
 struct bufhd bufhash[BUFHSZ];
 #define        BUFHASH(dev, dblkno)    \
@@ -60,7 +63,7 @@ struct {
        long    nreada;
        long    ncache;
        long    nwrite;
        long    nreada;
        long    ncache;
        long    nwrite;
-       long    bufcount[NBUF];
+       long    bufcount[64];
 } io_info;
 #endif
 
 } io_info;
 #endif
 
@@ -74,12 +77,12 @@ struct {
  * page push, when the I/O completes, it is inserted 
  * in a list of cleaned pages to be processed by the pageout daemon.
  */
  * page push, when the I/O completes, it is inserted 
  * in a list of cleaned pages to be processed by the pageout daemon.
  */
-struct buf swbuf[NSWBUF];
-short  swsize[NSWBUF];         /* CAN WE JUST USE B_BCOUNT? */
-int    swpf[NSWBUF];
+struct buf *swbuf;
+short  *swsize;                /* CAN WE JUST USE B_BCOUNT? */
+int    *swpf;
 
 
 
 
-#ifdef FASTVAX
+#ifndef        UNFAST
 #define        notavail(bp) \
 { \
        int s = spl6(); \
 #define        notavail(bp) \
 { \
        int s = spl6(); \
@@ -102,8 +105,8 @@ daddr_t blkno;
 
        bp = getblk(dev, blkno);
        if (bp->b_flags&B_DONE) {
 
        bp = getblk(dev, blkno);
        if (bp->b_flags&B_DONE) {
-#ifdef EPAWNJ
-               trace(TR_BREAD|TR_HIT, dev, blkno);
+#ifdef TRACE
+               trace(TR_BREADHIT, dev, blkno);
 #endif
 #ifdef DISKMON
                io_info.ncache++;
 #endif
 #ifdef DISKMON
                io_info.ncache++;
@@ -113,8 +116,8 @@ daddr_t blkno;
        bp->b_flags |= B_READ;
        bp->b_bcount = BSIZE;
        (*bdevsw[major(dev)].d_strategy)(bp);
        bp->b_flags |= B_READ;
        bp->b_bcount = BSIZE;
        (*bdevsw[major(dev)].d_strategy)(bp);
-#ifdef EPAWNJ
-       trace(TR_BREAD|TR_MISS, dev, blkno);
+#ifdef TRACE
+       trace(TR_BREADMISS, dev, blkno);
 #endif
 #ifdef DISKMON
        io_info.nread++;
 #endif
 #ifdef DISKMON
        io_info.nread++;
@@ -142,32 +145,32 @@ daddr_t blkno, rablkno;
                        bp->b_flags |= B_READ;
                        bp->b_bcount = BSIZE;
                        (*bdevsw[major(dev)].d_strategy)(bp);
                        bp->b_flags |= B_READ;
                        bp->b_bcount = BSIZE;
                        (*bdevsw[major(dev)].d_strategy)(bp);
-#ifdef EPAWNJ
-                       trace(TR_BREAD|TR_MISS, dev, blkno);
+#ifdef TRACE
+                       trace(TR_BREADMISS, dev, blkno);
 #endif
 #ifdef DISKMON
                        io_info.nread++;
 #endif
                        u.u_vm.vm_inblk++;              /* pay for read */
                }
 #endif
 #ifdef DISKMON
                        io_info.nread++;
 #endif
                        u.u_vm.vm_inblk++;              /* pay for read */
                }
-#ifdef EPAWNJ
+#ifdef TRACE
                else
                else
-                       trace(TR_BREAD|TR_HIT, dev, blkno);
+                       trace(TR_BREADHIT, dev, blkno);
 #endif
        }
        if (rablkno && !incore(dev, rablkno)) {
                rabp = getblk(dev, rablkno);
                if (rabp->b_flags & B_DONE) {
                        brelse(rabp);
 #endif
        }
        if (rablkno && !incore(dev, rablkno)) {
                rabp = getblk(dev, rablkno);
                if (rabp->b_flags & B_DONE) {
                        brelse(rabp);
-#ifdef EPAWNJ
-                       trace(TR_BREAD|TR_HIT|TR_RA, dev, blkno);
+#ifdef TRACE
+                       trace(TR_BREADHITRA, dev, blkno);
 #endif
                } else {
                        rabp->b_flags |= B_READ|B_ASYNC;
                        rabp->b_bcount = BSIZE;
                        (*bdevsw[major(dev)].d_strategy)(rabp);
 #endif
                } else {
                        rabp->b_flags |= B_READ|B_ASYNC;
                        rabp->b_bcount = BSIZE;
                        (*bdevsw[major(dev)].d_strategy)(rabp);
-#ifdef EPAWNJ
-                       trace(TR_BREAD|TR_MISS|TR_RA, dev, rablock);
+#ifdef TRACE
+                       trace(TR_BREADMISSRA, dev, rablock);
 #endif
 #ifdef DISKMON
                        io_info.nreada++;
 #endif
 #ifdef DISKMON
                        io_info.nreada++;
@@ -198,8 +201,8 @@ register struct buf *bp;
 #endif
        if ((flag&B_DELWRI) == 0)
                u.u_vm.vm_oublk++;              /* noone paid yet */
 #endif
        if ((flag&B_DELWRI) == 0)
                u.u_vm.vm_oublk++;              /* noone paid yet */
-#ifdef EPAWNJ
-       trace(TR_BWRITE, bp->b_dev, dbtofsb(bp->b_blkno));
+#ifdef TRACE
+       trace(TR_BWRITE, bp->b_dev, bp->b_blkno);
 #endif
        (*bdevsw[major(bp->b_dev)].d_strategy)(bp);
        if ((flag&B_ASYNC) == 0) {
 #endif
        (*bdevsw[major(bp->b_dev)].d_strategy)(bp);
        if ((flag&B_ASYNC) == 0) {
@@ -261,8 +264,11 @@ register struct buf *bp;
                bfreelist[0].b_flags &= ~B_WANTED;
                wakeup((caddr_t)bfreelist);
        }
                bfreelist[0].b_flags &= ~B_WANTED;
                wakeup((caddr_t)bfreelist);
        }
-       if ((bp->b_flags&B_ERROR) && bp->b_dev != NODEV)
-               bp->b_dev = NODEV;  /* no assoc. on error */
+       if (bp->b_flags&B_ERROR)
+               if (bp->b_flags & B_LOCKED)
+                       bp->b_flags &= ~B_ERROR;        /* try again later */
+               else
+                       bp->b_dev = NODEV;              /* no assoc */
        s = spl6();
        if (bp->b_flags & (B_ERROR|B_INVAL)) {
                /* block has no info ... put at front of most free list */
        s = spl6();
        if (bp->b_flags & (B_ERROR|B_INVAL)) {
                /* block has no info ... put at front of most free list */
@@ -358,7 +364,7 @@ daddr_t blkno;
                        i++;
                        dp = dp->av_forw;
                }
                        i++;
                        dp = dp->av_forw;
                }
-               if (i<NBUF)
+               if (i<64)
                        io_info.bufcount[i]++;
 #endif
                notavail(bp);
                        io_info.bufcount[i]++;
 #endif
                notavail(bp);
@@ -384,8 +390,8 @@ daddr_t blkno;
                bwrite(bp);
                goto loop;
        }
                bwrite(bp);
                goto loop;
        }
-#ifdef EPAWNJ
-       trace(TR_BRELSE, bp->b_dev, dbtofsb(bp->b_blkno));
+#ifdef TRACE
+       trace(TR_BRELSE, bp->b_dev, bp->b_blkno);
 #endif
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
 #endif
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
@@ -426,8 +432,8 @@ loop:
                bwrite(bp);
                goto loop;
        }
                bwrite(bp);
                goto loop;
        }
-#ifdef EPAWNJ
-       trace(TR_BRELSE, bp->b_dev, dbtofsb(bp->b_blkno));
+#ifdef TRACE
+       trace(TR_BRELSE, bp->b_dev, bp->b_blkno);
 #endif
        bp->b_flags = B_BUSY|B_INVAL;
        bp->b_back->b_forw = bp->b_forw;
 #endif
        bp->b_flags = B_BUSY|B_INVAL;
        bp->b_back->b_forw = bp->b_forw;
@@ -455,7 +461,7 @@ register struct buf *bp;
        geterror(bp);
 }
 
        geterror(bp);
 }
 
-#ifndef FASTVAX
+#ifdef UNFAST
 /*
  * Unlink a buffer from the available list and mark it busy.
  * (internal interface)
 /*
  * Unlink a buffer from the available list and mark it busy.
  * (internal interface)
@@ -493,10 +499,11 @@ register struct buf *bp;
                if (bp->b_flags & B_ERROR)
                        panic("IO err in push");
                s = spl6();
                if (bp->b_flags & B_ERROR)
                        panic("IO err in push");
                s = spl6();
-               cnt.v_pgout++;
                bp->av_forw = bclnlist;
                bp->b_bcount = swsize[bp - swbuf];
                bp->b_pfcent = swpf[bp - swbuf];
                bp->av_forw = bclnlist;
                bp->b_bcount = swsize[bp - swbuf];
                bp->b_pfcent = swpf[bp - swbuf];
+               cnt.v_pgout++;
+               cnt.v_pgpgout += bp->b_bcount / NBPG;
                bclnlist = bp;
                if (bswlist.b_flags & B_WANTED)
                        wakeup((caddr_t)&proc[2]);
                bclnlist = bp;
                if (bswlist.b_flags & B_WANTED)
                        wakeup((caddr_t)&proc[2]);
@@ -590,6 +597,9 @@ swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
                        swpf[bp - swbuf] = pfcent;
                        swsize[bp - swbuf] = nbytes;
                }
                        swpf[bp - swbuf] = pfcent;
                        swsize[bp - swbuf] = nbytes;
                }
+#ifdef TRACE
+               trace(TR_SWAPIO, dev, bp->b_blkno);
+#endif
                (*bdevsw[major(dev)].d_strategy)(bp);
                if (flag & B_DIRTY) {
                        if (c < nbytes)
                (*bdevsw[major(dev)].d_strategy)(bp);
                if (flag & B_DIRTY) {
                        if (c < nbytes)
@@ -631,12 +641,14 @@ swkill(p, rout)
        struct proc *p;
        char *rout;
 {
        struct proc *p;
        char *rout;
 {
+       char *mesg;
 
 
-       printf("%d: ", p->p_pid);
+       printf("pid %d: ", p->p_pid);
        if (rout)
        if (rout)
-               printf("out of swap space in %s\n", rout);
+               printf(mesg = "killed due to no swap space\n");
        else
        else
-               printf("killed on swap error\n");
+               printf(mesg = "killed on swap error\n");
+       uprintf("sorry, pid %d was %s", p->p_pid, mesg);
        /*
         * To be sure no looping (e.g. in vmsched trying to
         * swap out) mark process locked in core (as though
        /*
         * To be sure no looping (e.g. in vmsched trying to
         * swap out) mark process locked in core (as though
@@ -707,7 +719,7 @@ unsigned (*mincnt)();
        bp->b_error = 0;
        bp->b_proc = u.u_procp;
        bp->b_un.b_addr = u.u_base;
        bp->b_error = 0;
        bp->b_proc = u.u_procp;
        bp->b_un.b_addr = u.u_base;
-       while (u.u_count != 0 && bp->b_error==0) {
+       while (u.u_count != 0) {
                bp->b_flags = B_BUSY | B_PHYS | rw;
                bp->b_dev = dev;
                bp->b_blkno = u.u_offset >> PGSHIFT;
                bp->b_flags = B_BUSY | B_PHYS | rw;
                bp->b_dev = dev;
                bp->b_blkno = u.u_offset >> PGSHIFT;
@@ -728,6 +740,8 @@ unsigned (*mincnt)();
                bp->b_un.b_addr += c;
                u.u_count -= c;
                u.u_offset += c;
                bp->b_un.b_addr += c;
                u.u_count -= c;
                u.u_offset += c;
+               if (bp->b_flags&B_ERROR)
+                       break;
        }
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
        u.u_count = bp->b_resid;
        }
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
        u.u_count = bp->b_resid;