BSD 4_3 release
[unix-history] / usr / src / sys / sys / vm_sched.c
index 07aeed7..01d1a8e 100644 (file)
@@ -1,15 +1,23 @@
-/*     vm_sched.c      6.1     83/07/29        */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)vm_sched.c  7.1 (Berkeley) 6/5/86
+ */
+
+#include "param.h"
+#include "systm.h"
+#include "seg.h"
+#include "dir.h"
+#include "user.h"
+#include "proc.h"
+#include "text.h"
+#include "vm.h"
+#include "cmap.h"
+#include "kernel.h"
+
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/seg.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/proc.h"
-#include "../h/text.h"
-#include "../h/vm.h"
-#include "../h/cmap.h"
-#include "../h/kernel.h"
 
 int    maxslp = MAXSLP;
 int    saferss = SAFERSS;
 
 int    maxslp = MAXSLP;
 int    saferss = SAFERSS;
@@ -36,68 +44,6 @@ int  multprog = -1;          /* so we don't count process 2 */
 
 double avenrun[3];             /* load average, of runnable procs */
 
 
 double avenrun[3];             /* load average, of runnable procs */
 
-/*
- * Setup the paging constants for the clock algorithm.
- * Called after the system is initialized and the amount of memory
- * and number of paging devices is known.
- *
- * Threshold constants are defined in ../machine/vmparam.h.
- */
-setupclock()
-{
-
-       /*
-        * Setup thresholds for paging:
-        *      lotsfree        is threshold where paging daemon turns on
-        *      desfree         is amount of memory desired free.  if less
-        *                      than this for extended period, do swapping
-        *      minfree         is minimal amount of free memory which is
-        *                      tolerable.
-        */
-       if (lotsfree == 0)
-               lotsfree = LOOPPAGES / LOTSFREEFRACT;
-       if (desfree == 0) {
-               desfree = DESFREE / NBPG;
-               if (desfree > LOOPPAGES / DESFREEFRACT)
-                       desfree = LOOPPAGES / DESFREEFRACT;
-       }
-       if (minfree == 0) {
-               minfree = MINFREE / NBPG;
-               if (minfree > desfree / MINFREEFRACT)
-                       minfree = desfree / MINFREEFRACT;
-       }
-       /*
-        * Maxpgio thresholds how much paging is acceptable.
-        * This figures that 2/3 busy on an arm is all that is
-        * tolerable for paging.  We assume one operation per disk rev.
-        */
-       if (maxpgio == 0)
-               maxpgio = (DISKRPM * 2) / 3;
-
-       /*
-        * Clock to scan using max of ~~10% of processor time for sampling,
-        *     this estimated to allow maximum of 200 samples per second.
-        * This yields a ``fastscan'' of roughly (with CLSIZE=2):
-        *      <=1m    2m      3m      4m      8m
-        *      5s      10s     15s     20s     40s
-        */
-       if (nswdev == 1 && physmem*NBPG > LOTSOFMEM*1024*(1024-16))
-               printf("WARNING: should run interleaved swap with >= %dMb\n",
-                   LOTSOFMEM);
-       if (fastscan == 0)
-               fastscan = (LOOPPAGES/CLSIZE) / 200;
-       if (fastscan < 5)
-               fastscan = 5;
-       if (nswdev >= 2)
-               maxpgio = (maxpgio * 3) / 2;
-
-       /*
-        * Set slow scan time to 1/2 the fast scan time.
-        */
-       if (slowscan == 0)
-               slowscan = 2 * fastscan;
-}
-
 /*
  * The main loop of the scheduling (swapping) process.
  *
 /*
  * The main loop of the scheduling (swapping) process.
  *
@@ -172,7 +118,7 @@ loop:
         * look for someone who deserves to be brought in.
         */
        outpri = -20000;
         * look for someone who deserves to be brought in.
         */
        outpri = -20000;
-       for (rp = proc; rp < procNPROC; rp++) switch(rp->p_stat) {
+       for (rp = allproc; rp != NULL; rp = rp->p_nxt) switch(rp->p_stat) {
 
        case SRUN:
                if ((rp->p_flag&SLOAD) == 0) {
 
        case SRUN:
                if ((rp->p_flag&SLOAD) == 0) {
@@ -199,13 +145,8 @@ loop:
                        /*
                         * Kick out deadwood.
                         */
                        /*
                         * Kick out deadwood.
                         */
-                       (void) spl6();
                        rp->p_flag &= ~SLOAD;
                        rp->p_flag &= ~SLOAD;
-                       if (rp->p_stat == SRUN)
-                               remrq(rp);
-                       (void) spl0();
                        (void) swapout(rp, rp->p_dsize, rp->p_ssize);
                        (void) swapout(rp, rp->p_dsize, rp->p_ssize);
-                       goto loop;
                }
                continue;
        }
                }
                continue;
        }
@@ -214,7 +155,7 @@ loop:
         * No one wants in, so nothing to do.
         */
        if (outpri == -20000) {
         * No one wants in, so nothing to do.
         */
        if (outpri == -20000) {
-               (void) spl6();
+               (void) splhigh();
                if (wantin) {
                        wantin = 0;
                        sleep((caddr_t)&lbolt, PSWP);
                if (wantin) {
                        wantin = 0;
                        sleep((caddr_t)&lbolt, PSWP);
@@ -264,11 +205,9 @@ hardswap:
                nbig = 1;
        biggot = 0;
        bplist.bp_link = 0;
                nbig = 1;
        biggot = 0;
        bplist.bp_link = 0;
-       for (rp = proc; rp < procNPROC; rp++) {
+       for (rp = allproc; rp != NULL; rp = rp->p_nxt) {
                if (!swappable(rp))
                        continue;
                if (!swappable(rp))
                        continue;
-               if (rp->p_stat==SZOMB)
-                       continue;
                if (rp == inp)
                        continue;
                if (rp->p_textp && rp->p_textp->x_flag&XLOCK)
                if (rp == inp)
                        continue;
                if (rp->p_textp && rp->p_textp->x_flag&XLOCK)
@@ -320,7 +259,7 @@ hardswap:
         * we kick the poor luser out.
         */
        if (sleeper || desperate && p || deservin && inpri > maxslp) {
         * we kick the poor luser out.
         */
        if (sleeper || desperate && p || deservin && inpri > maxslp) {
-               (void) spl6();
+               (void) splhigh();
                p->p_flag &= ~SLOAD;
                if (p->p_stat == SRUN)
                        remrq(p);
                p->p_flag &= ~SLOAD;
                if (p->p_stat == SRUN)
                        remrq(p);
@@ -340,13 +279,14 @@ hardswap:
                        gives = 0;      /* someone else taketh away */
                if (swapout(p, p->p_dsize, p->p_ssize) == 0)
                        deficit -= imin(gives, deficit);
                        gives = 0;      /* someone else taketh away */
                if (swapout(p, p->p_dsize, p->p_ssize) == 0)
                        deficit -= imin(gives, deficit);
-               goto loop;
+               else
+                       goto loop;
        }
        /*
         * Want to swap someone in, but can't
         * so wait on runin.
         */
        }
        /*
         * Want to swap someone in, but can't
         * so wait on runin.
         */
-       (void) spl6();
+       (void) splhigh();
        runin++;
        sleep((caddr_t)&runin, PSWP);
        (void) spl0();
        runin++;
        sleep((caddr_t)&runin, PSWP);
        (void) spl0();
@@ -386,8 +326,6 @@ vmmeter()
        }
 }
 
        }
 }
 
-#define        RATETOSCHEDPAGING       4               /* hz that is */
-
 /*
  * Schedule rate for paging.
  * Rate is linear interpolation between
 /*
  * Schedule rate for paging.
  * Rate is linear interpolation between
@@ -395,18 +333,15 @@ vmmeter()
  */
 schedpaging()
 {
  */
 schedpaging()
 {
-       register int vavail, scanrate;
+       register int vavail;
 
        nscan = desscan = 0;
        vavail = freemem - deficit;
        if (vavail < 0)
                vavail = 0;
        if (freemem < lotsfree) {
 
        nscan = desscan = 0;
        vavail = freemem - deficit;
        if (vavail < 0)
                vavail = 0;
        if (freemem < lotsfree) {
-               scanrate =
-                       (slowscan * vavail + fastscan * (lotsfree - vavail)) /
-                               nz(lotsfree);
-               desscan = ((LOOPPAGES / CLSIZE) / nz(scanrate)) /
-                               RATETOSCHEDPAGING;
+               desscan = (slowscan * vavail + fastscan * (lotsfree - vavail)) /
+                       nz(lotsfree) / RATETOSCHEDPAGING;
                wakeup((caddr_t)&proc[2]);
        }
        timeout(schedpaging, (caddr_t)0, hz / RATETOSCHEDPAGING);
                wakeup((caddr_t)&proc[2]);
        }
        timeout(schedpaging, (caddr_t)0, hz / RATETOSCHEDPAGING);
@@ -453,7 +388,7 @@ next:
        total.t_pw = 0;
        total.t_sl = 0;
        total.t_sw = 0;
        total.t_pw = 0;
        total.t_sl = 0;
        total.t_sw = 0;
-       for (p = proc; p < procNPROC; p++) {
+       for (p = allproc; p != NULL; p = p->p_nxt) {
                if (p->p_flag & SSYS)
                        continue;
                if (p->p_stat) {
                if (p->p_flag & SSYS)
                        continue;
                if (p->p_stat) {