getkerninfo skipped defaults ``dupedkeyed'' behind the root node;
[unix-history] / usr / src / sys / vm / vm_meter.c
index eaa078a..a134d36 100644 (file)
@@ -1,15 +1,29 @@
-/*     vm_meter.c      6.2     84/05/22        */
+/*
+ * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)vm_meter.c  7.8 (Berkeley) %G%
+ */
 
 
-#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"
+#include "param.h"
+#include "systm.h"
+#include "user.h"
+#include "proc.h"
+#include "text.h"
+#include "vm.h"
+#include "kernel.h"
 
 int    maxslp = MAXSLP;
 int    saferss = SAFERSS;
 
 int    maxslp = MAXSLP;
 int    saferss = SAFERSS;
@@ -34,69 +48,7 @@ int  kltxt = KLTXT;
 int    klout = KLOUT;
 int    multprog = -1;          /* so we don't count process 2 */
 
 int    klout = KLOUT;
 int    multprog = -1;          /* so we don't count process 2 */
 
-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;
-}
+fixpt_t        averunnable[3];         /* load average, of runnable procs */
 
 /*
  * The main loop of the scheduling (swapping) process.
 
 /*
  * The main loop of the scheduling (swapping) process.
@@ -161,8 +113,9 @@ loop:
         *         memory is less than desirable.
         */
        if (kmapwnt ||
         *         memory is less than desirable.
         */
        if (kmapwnt ||
-           (avenrun[0] >= 2 && imax(avefree, avefree30) < desfree &&
-           (rate.v_pgin + rate.v_pgout > maxpgio || avefree < minfree))) {
+           (averunnable[0] >= 2 * FSCALE &&
+            imax(avefree, avefree30) < desfree &&
+            (rate.v_pgin + rate.v_pgout > maxpgio || avefree < minfree))) {
                desperate = 1;
                goto hardswap;
        }
                desperate = 1;
                goto hardswap;
        }
@@ -199,26 +152,20 @@ 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);
-                       goto loop;
+                       (void) swapout(rp, rp->p_dsize, rp->p_mmsize, rp->p_ssize);
                }
                continue;
        }
 
        /*
                }
                continue;
        }
 
        /*
-        * No one wants in, so nothing to do.
+        * If something came ready after we checked it,
+        * wantin will be set.  Otherwise,
+        * no one wants in, so nothing to do.
         */
        if (outpri == -20000) {
         */
        if (outpri == -20000) {
-               (void) spl6();
-               if (wantin) {
-                       wantin = 0;
-                       sleep((caddr_t)&lbolt, PSWP);
-               } else {
+               (void) splhigh();
+               if (wantin == 0) {
                        runout++;
                        sleep((caddr_t)&runout, PSWP);
                }
                        runout++;
                        sleep((caddr_t)&runout, PSWP);
                }
@@ -318,7 +265,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);
@@ -336,15 +283,16 @@ hardswap:
                        deficit += gives;
                } else
                        gives = 0;      /* someone else taketh away */
                        deficit += gives;
                } else
                        gives = 0;      /* someone else taketh away */
-               if (swapout(p, p->p_dsize, p->p_ssize) == 0)
+               if (swapout(p, p->p_dsize, p->p_mmsize, p->p_ssize) == 0)
                        deficit -= imin(gives, deficit);
                        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();
@@ -384,8 +332,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
@@ -393,18 +339,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);
@@ -421,7 +364,7 @@ vmtotal()
        total.t_rmtxt = 0;
        total.t_armtxt = 0;
        for (xp = text; xp < textNTEXT; xp++)
        total.t_rmtxt = 0;
        total.t_armtxt = 0;
        for (xp = text; xp < textNTEXT; xp++)
-               if (xp->x_iptr) {
+               if (xp->x_vptr) {
                        total.t_vmtxt += xp->x_size;
                        total.t_rmtxt += xp->x_rssize;
                        for (p = xp->x_caddr; p; p = p->p_xlink)
                        total.t_vmtxt += xp->x_size;
                        total.t_rmtxt += xp->x_rssize;
                        for (p = xp->x_caddr; p; p = p->p_xlink)
@@ -455,14 +398,17 @@ next:
                if (p->p_flag & SSYS)
                        continue;
                if (p->p_stat) {
                if (p->p_flag & SSYS)
                        continue;
                if (p->p_stat) {
-                       total.t_vm += p->p_dsize + p->p_ssize;
-                       total.t_rm += p->p_rssize;
+                       if (p->p_stat != SZOMB) {
+                               total.t_vm += p->p_dsize + p->p_ssize;
+                               total.t_rm += p->p_rssize;
+                       }
                        switch (p->p_stat) {
 
                        case SSLEEP:
                        switch (p->p_stat) {
 
                        case SSLEEP:
-                       case SSTOP:
-                               if (p->p_pri <= PZERO)
+                               if (p->p_pri <= PZERO && p->p_slptime == 0)
                                        nrun++;
                                        nrun++;
+                               /* fall through */
+                       case SSTOP:
                                if (p->p_flag & SPAGE)
                                        total.t_pw++;
                                else if (p->p_flag & SLOAD) {
                                if (p->p_flag & SPAGE)
                                        total.t_pw++;
                                else if (p->p_flag & SLOAD) {
@@ -495,17 +441,17 @@ active:
        total.t_rm += total.t_rmtxt;
        total.t_arm += total.t_armtxt;
        total.t_free = avefree;
        total.t_rm += total.t_rmtxt;
        total.t_arm += total.t_armtxt;
        total.t_free = avefree;
-       loadav(avenrun, nrun);
+       loadav(averunnable, nrun);
 }
 
 /*
  * Constants for averages over 1, 5, and 15 minutes
  * when sampling at 5 second intervals.
  */
 }
 
 /*
  * Constants for averages over 1, 5, and 15 minutes
  * when sampling at 5 second intervals.
  */
-double cexp[3] = {
-       0.9200444146293232    /* exp(-1/12) */
-       0.9834714538216174    /* exp(-1/60) */
-       0.9944598480048967    /* exp(-1/180) */
+fixpt_t        cexp[3] = {
+       0.9200444146293232 * FSCALE,    /* exp(-1/12) */
+       0.9834714538216174 * FSCALE,    /* exp(-1/60) */
+       0.9944598480048967 * FSCALE,    /* exp(-1/180) */
 };
 
 /*
 };
 
 /*
@@ -513,11 +459,16 @@ double    cexp[3] = {
  * 1, 5 and 15 minute intervals.
  */
 loadav(avg, n)
  * 1, 5 and 15 minute intervals.
  */
 loadav(avg, n)
-       register double *avg;
+       register fixpt_t *avg;
        int n;
 {
        register int i;
 
        for (i = 0; i < 3; i++)
        int n;
 {
        register int i;
 
        for (i = 0; i < 3; i++)
-               avg[i] = cexp[i] * avg[i] + n * (1.0 - cexp[i]);
+               avg[i] = (cexp[i] * avg[i] + n * FSCALE * (FSCALE - cexp[i]))
+                        >> FSHIFT;
+#if defined(COMPAT_43) && (defined(vax) || defined(tahoe))
+       for (i = 0; i < 3; i++)
+               avenrun[i] = (double) averunnable[i] / FSCALE;
+#endif /* COMPAT_43 */
 }
 }