-/* 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;
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.
*
* 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) {
/*
* Kick out deadwood.
*/
- (void) spl6();
rp->p_flag &= ~SLOAD;
- if (rp->p_stat == SRUN)
- remrq(rp);
- (void) spl0();
(void) swapout(rp, rp->p_dsize, rp->p_ssize);
- goto loop;
}
continue;
}
* No one wants in, so nothing to do.
*/
if (outpri == -20000) {
- (void) spl6();
+ (void) splhigh();
if (wantin) {
wantin = 0;
sleep((caddr_t)&lbolt, PSWP);
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 (rp->p_stat==SZOMB)
- continue;
if (rp == inp)
continue;
if (rp->p_textp && rp->p_textp->x_flag&XLOCK)
* 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);
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.
*/
- (void) spl6();
+ (void) splhigh();
runin++;
sleep((caddr_t)&runin, PSWP);
(void) spl0();
}
}
-#define RATETOSCHEDPAGING 4 /* hz that is */
-
/*
* Schedule rate for paging.
* Rate is linear interpolation between
*/
schedpaging()
{
- register int vavail, scanrate;
+ register int vavail;
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);
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) {