BSD 4_4 release
[unix-history] / usr / src / sys / vm / swap_pager.c
index e5dde39..3f863e5 100644 (file)
@@ -1,17 +1,43 @@
 /*
  * Copyright (c) 1990 University of Utah.
 /*
  * Copyright (c) 1990 University of Utah.
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  *
  * from: Utah $Hdr: swap_pager.c 1.4 91/04/30$
  *
  *
  * from: Utah $Hdr: swap_pager.c 1.4 91/04/30$
  *
- *     @(#)swap_pager.c        7.13 (Berkeley) %G%
+ *     @(#)swap_pager.c        8.1 (Berkeley) 6/11/93
  */
 
 /*
  */
 
 /*
@@ -21,9 +47,6 @@
  *     Deal with async writes in a better fashion
  */
 
  *     Deal with async writes in a better fashion
  */
 
-#include "swappager.h"
-#if NSWAPPAGER > 0
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
@@ -35,7 +58,6 @@
 #include <miscfs/specfs/specdev.h>
 
 #include <vm/vm.h>
 #include <miscfs/specfs/specdev.h>
 
 #include <vm/vm.h>
-#include <vm/queue.h>
 #include <vm/vm_page.h>
 #include <vm/vm_pageout.h>
 #include <vm/swap_pager.h>
 #include <vm/vm_page.h>
 #include <vm/vm_pageout.h>
 #include <vm/swap_pager.h>
@@ -555,7 +577,7 @@ swap_pager_io(swp, m, flags)
         * Get a swap buffer header and perform the IO
         */
        s = splbio();
         * Get a swap buffer header and perform the IO
         */
        s = splbio();
-       while (bswlist.av_forw == NULL) {
+       while (bswlist.b_actf == NULL) {
 #ifdef DEBUG
                if (swpagerdebug & SDB_ANOM)
                        printf("swap_pager_io: wait on swbuf for %x (%d)\n",
 #ifdef DEBUG
                if (swpagerdebug & SDB_ANOM)
                        printf("swap_pager_io: wait on swbuf for %x (%d)\n",
@@ -564,8 +586,8 @@ swap_pager_io(swp, m, flags)
                bswlist.b_flags |= B_WANTED;
                sleep((caddr_t)&bswlist, PSWP+1);
        }
                bswlist.b_flags |= B_WANTED;
                sleep((caddr_t)&bswlist, PSWP+1);
        }
-       bp = bswlist.av_forw;
-       bswlist.av_forw = bp->av_forw;
+       bp = bswlist.b_actf;
+       bswlist.b_actf = bp->b_actf;
        splx(s);
        bp->b_flags = B_BUSY | (flags & B_READ);
        bp->b_proc = &proc0;    /* XXX (but without B_PHYS set this is ok) */
        splx(s);
        bp->b_flags = B_BUSY | (flags & B_READ);
        bp->b_proc = &proc0;    /* XXX (but without B_PHYS set this is ok) */
@@ -653,8 +675,8 @@ swap_pager_io(swp, m, flags)
 #endif
        rv = (bp->b_flags & B_ERROR) ? VM_PAGER_ERROR : VM_PAGER_OK;
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
 #endif
        rv = (bp->b_flags & B_ERROR) ? VM_PAGER_ERROR : VM_PAGER_OK;
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
-       bp->av_forw = bswlist.av_forw;
-       bswlist.av_forw = bp;
+       bp->b_actf = bswlist.b_actf;
+       bswlist.b_actf = bp;
        if (bp->b_vp)
                brelvp(bp);
        if (bswlist.b_flags & B_WANTED) {
        if (bp->b_vp)
                brelvp(bp);
        if (bswlist.b_flags & B_WANTED) {
@@ -662,7 +684,7 @@ swap_pager_io(swp, m, flags)
                thread_wakeup((int)&bswlist);
        }
        if ((flags & B_READ) == 0 && rv == VM_PAGER_OK) {
                thread_wakeup((int)&bswlist);
        }
        if ((flags & B_READ) == 0 && rv == VM_PAGER_OK) {
-               m->clean = TRUE;
+               m->flags |= PG_CLEAN;
                pmap_clear_modify(VM_PAGE_TO_PHYS(m));
        }
        splx(s);
                pmap_clear_modify(VM_PAGE_TO_PHYS(m));
        }
        splx(s);
@@ -800,7 +822,7 @@ swap_pager_finish(spc)
                if (swpagerdebug & SDB_ANOM)
                        printf("swap_pager_finish: page %x dirty again\n",
                               spc->spc_m);
                if (swpagerdebug & SDB_ANOM)
                        printf("swap_pager_finish: page %x dirty again\n",
                               spc->spc_m);
-               spc->spc_m->busy = FALSE;
+               spc->spc_m->flags &= ~PG_BUSY;
                PAGE_WAKEUP(spc->spc_m);
                vm_object_unlock(object);
                return(1);
                PAGE_WAKEUP(spc->spc_m);
                vm_object_unlock(object);
                return(1);
@@ -814,12 +836,12 @@ swap_pager_finish(spc)
        if (spc->spc_flags & SPC_ERROR) {
                printf("swap_pager_finish: clean of page %x failed\n",
                       VM_PAGE_TO_PHYS(spc->spc_m));
        if (spc->spc_flags & SPC_ERROR) {
                printf("swap_pager_finish: clean of page %x failed\n",
                       VM_PAGE_TO_PHYS(spc->spc_m));
-               spc->spc_m->laundry = TRUE;
+               spc->spc_m->flags |= PG_LAUNDRY;
        } else {
        } else {
-               spc->spc_m->clean = TRUE;
+               spc->spc_m->flags |= PG_CLEAN;
                pmap_clear_modify(VM_PAGE_TO_PHYS(spc->spc_m));
        }
                pmap_clear_modify(VM_PAGE_TO_PHYS(spc->spc_m));
        }
-       spc->spc_m->busy = FALSE;
+       spc->spc_m->flags &= ~PG_BUSY;
        PAGE_WAKEUP(spc->spc_m);
 
        vm_object_unlock(object);
        PAGE_WAKEUP(spc->spc_m);
 
        vm_object_unlock(object);
@@ -875,15 +897,19 @@ swap_pager_iodone(bp)
        }
                
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
        }
                
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
-       bp->av_forw = bswlist.av_forw;
-       bswlist.av_forw = bp;
+       bp->b_actf = bswlist.b_actf;
+       bswlist.b_actf = bp;
        if (bp->b_vp)
                brelvp(bp);
        if (bswlist.b_flags & B_WANTED) {
                bswlist.b_flags &= ~B_WANTED;
                thread_wakeup((int)&bswlist);
        }
        if (bp->b_vp)
                brelvp(bp);
        if (bswlist.b_flags & B_WANTED) {
                bswlist.b_flags &= ~B_WANTED;
                thread_wakeup((int)&bswlist);
        }
-       thread_wakeup((int) &vm_pages_needed);
+       /*
+        * Only kick the pageout daemon if we are really hurting
+        * for pages, otherwise this page will be picked up later.
+        */
+       if (cnt.v_free_count < cnt.v_free_min)
+               thread_wakeup((int) &vm_pages_needed);
        splx(s);
 }
        splx(s);
 }
-#endif