speed-ups using the new constants
[unix-history] / usr / src / sys / vm / vm_meter.c
index 8deb1ff..b23e009 100644 (file)
@@ -1,4 +1,4 @@
-/*     vm_meter.c      4.10    81/04/26        */
+/*     vm_meter.c      4.18    83/01/08        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -9,6 +9,7 @@
 #include "../h/text.h"
 #include "../h/vm.h"
 #include "../h/cmap.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;
@@ -42,7 +43,6 @@ double        avenrun[3];             /* load average, of runnable procs */
  */
 setupclock()
 {
  */
 setupclock()
 {
-       int nclust, nkb;
 
        /*
         * Setup thresholds for paging:
 
        /*
         * Setup thresholds for paging:
@@ -79,32 +79,27 @@ setupclock()
                maxpgio = (DISKRPM * 2) / 3;
 
        /*
                maxpgio = (DISKRPM * 2) / 3;
 
        /*
-        * Clock to scan using max of ~~15% of processor time for sampling,
-        *     this estimated to allow maximum of 300 samples per second.
+        * 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):
         * This yields a ``fastscan'' of roughly (with CLSIZE=2):
-        *      <=1m    2m      3m      4m      >=6m
-        *      5s      6s      7s      13s     20s
+        *      <=1m    2m      3m      4m      8m
+        *      5s      10s     15s     20s     40s
         */
        if (nswdev == 1 && physmem*NBPG > 2*1024*(1024-16))
                printf("WARNING: should run interleaved swap with >= 2Mb\n");
        if (fastscan == 0)
         */
        if (nswdev == 1 && physmem*NBPG > 2*1024*(1024-16))
                printf("WARNING: should run interleaved swap with >= 2Mb\n");
        if (fastscan == 0)
-               fastscan = (LOOPPAGES/CLSIZE) / 300;
+               fastscan = (LOOPPAGES/CLSIZE) / 200;
        if (fastscan < 5)
                fastscan = 5;
        if (fastscan < 5)
                fastscan = 5;
-       if (fastscan > maxslp)
-               fastscan = maxslp;
-       if (nswdev == 2)
+       if (nswdev >= 2)
                maxpgio = (maxpgio * 3) / 2;
 
        /*
                maxpgio = (maxpgio * 3) / 2;
 
        /*
-        * Set slow scan time to 1/3 the fast scan time but at most
-        * maxslp (a macroscopic slow).
+        * Set slow scan time to 1/2 the fast scan time.
         */
        if (slowscan == 0)
         */
        if (slowscan == 0)
-               slowscan = 3 * fastscan;
-       if (slowscan > maxslp)
-               slowscan = maxslp;
-#if defined(BERT) || defined(ERNIE)
+               slowscan = 2 * fastscan;
+#ifdef notdef
        printf("slowscan %d, fastscan %d, maxpgio %d\n",
            slowscan, fastscan, maxpgio);
        printf("lotsfree %d, desfree %d, minfree %d\n",
        printf("slowscan %d, fastscan %d, maxpgio %d\n",
            slowscan, fastscan, maxpgio);
        printf("lotsfree %d, desfree %d, minfree %d\n",
@@ -174,7 +169,11 @@ loop:
         * and  3. the short (5-second) and longer (30-second) average
         *         memory is less than desirable.
         */
         * and  3. the short (5-second) and longer (30-second) average
         *         memory is less than desirable.
         */
-       if (kmapwnt || (avenrun[0] >= 2 && max(avefree, avefree30) < desfree &&
+       if (
+#ifdef NOPAGING
+           freemem == 0 ||
+#endif
+           kmapwnt || (avenrun[0] >= 2 && imax(avefree, avefree30) < desfree &&
            (rate.v_pgin + rate.v_pgout > maxpgio || avefree < minfree))) {
                desperate = 1;
                goto hardswap;
            (rate.v_pgin + rate.v_pgout > maxpgio || avefree < minfree))) {
                desperate = 1;
                goto hardswap;
@@ -250,7 +249,11 @@ loop:
        divisor = 1;
        if (outpri > maxslp/2) {
                deservin = 1;
        divisor = 1;
        if (outpri > maxslp/2) {
                deservin = 1;
+#ifdef NOPAGING
+               divisor = 1;
+#else
                divisor = 2;
                divisor = 2;
+#endif
        }
        needs = p->p_swrss;
        if (p->p_textp && p->p_textp->x_ccount == 0)
        }
        needs = p->p_swrss;
        if (p->p_textp && p->p_textp->x_ccount == 0)
@@ -347,7 +350,7 @@ hardswap:
                        gives = p->p_rssize;
                        if (p->p_textp)
                                gives += p->p_textp->x_rssize / p->p_textp->x_ccount;
                        gives = p->p_rssize;
                        if (p->p_textp)
                                gives += p->p_textp->x_rssize / p->p_textp->x_ccount;
-                       gives = min(gives, lotsfree);
+                       gives = imin(gives, lotsfree);
                        deficit += gives;
                } else
                        gives = 0;      /* someone else taketh away */
                        deficit += gives;
                } else
                        gives = 0;      /* someone else taketh away */
@@ -382,7 +385,7 @@ vmmeter()
                *cp = 0;
                rp++, cp++, sp++;
        }
                *cp = 0;
                rp++, cp++, sp++;
        }
-       if (time % 5 == 0) {
+       if (time.tv_sec % 5 == 0) {
                vmtotal();
                rate.v_swpin = cnt.v_swpin;
                sum.v_swpin += cnt.v_swpin;
                vmtotal();
                rate.v_swpin = cnt.v_swpin;
                sum.v_swpin += cnt.v_swpin;
@@ -399,32 +402,30 @@ vmmeter()
        }
 }
 
        }
 }
 
-vmpago()
+#define        RATETOSCHEDPAGING       4               /* hz that is */
+
+/*
+ * Schedule rate for paging.
+ * Rate is linear interpolation between
+ * slowscan with lotsfree and fastscan when out of memory.
+ */
+schedpaging()
 {
 {
-       register int vavail;
-       register int scanrate;
+       register int vavail, scanrate;
 
 
-       /*
-        * Compute new rate for clock; if
-        * nonzero, restart clock.
-        * Rate ranges linearly from one rev per
-        * slowscan seconds when there is lotsfree memory
-        * available to one rev per fastscan seconds when
-        * there is no memory available.
-        */
        nscan = desscan = 0;
        vavail = freemem - deficit;
        if (vavail < 0)
                vavail = 0;
        nscan = desscan = 0;
        vavail = freemem - deficit;
        if (vavail < 0)
                vavail = 0;
-       if (freemem >= lotsfree)
-               return;
-       scanrate = (slowscan * vavail + fastscan * (lotsfree - vavail)) / nz(lotsfree);
-       desscan = (LOOPPAGES / CLSIZE) / nz(scanrate);
-       /*
-        * DIVIDE BY 4 TO ACCOUNT FOR RUNNING 4* A SECOND (see clock.c)
-        */
-       desscan /= 4;
-       wakeup((caddr_t)&proc[2]);
+       if (freemem < lotsfree) {
+               scanrate =
+                       (slowscan * vavail + fastscan * (lotsfree - vavail)) /
+                               nz(lotsfree);
+               desscan = ((LOOPPAGES / CLSIZE) / nz(scanrate)) /
+                               RATETOSCHEDPAGING;
+               wakeup((caddr_t)&proc[2]);
+       }
+       timeout(schedpaging, (caddr_t)0, hz / RATETOSCHEDPAGING);
 }
 
 vmtotal()
 }
 
 vmtotal()