- * If we found a long-time sleeper, or we are desperate and
- * found anyone to swap out, or if someone deserves to come
- * in and we didn't find a sleeper, but found someone who
- * has been in core for a reasonable length of time, then
- * we kick the poor luser out.
- */
- if (sleeper || desperate && p || deservin && inpri > maxslp) {
- (void) spl6();
- p->p_flag &= ~SLOAD;
- if (p->p_stat == SRUN)
- remrq(p);
- (void) spl0();
- if (desperate) {
- /*
- * Want to give this space to the rest of
- * the processes in core so give them a chance
- * by increasing the deficit.
- */
- gives = p->p_rssize;
- if (p->p_textp)
- gives += p->p_textp->x_rssize / p->p_textp->x_ccount;
- gives = min(gives, lotsfree);
- deficit += gives;
- } else
- gives = 0; /* someone else taketh away */
- if (swapout(p, p->p_dsize, p->p_ssize) == 0)
- deficit -= imin(gives, deficit);
- goto loop;
- }
- /*
- * Want to swap someone in, but can't
- * so wait on runin.
- */
- (void) spl6();
- runin++;
- sleep((caddr_t)&runin, PSWP);
- (void) spl0();
- goto loop;
-}
-
-vmmeter()
-{
- register unsigned *cp, *rp, *sp;
-
- deficit -= imin(deficit,
- imax(deficit / 10, ((klin * CLSIZE) / 2) * maxpgio / 2));
- ave(avefree, freemem, 5);
- ave(avefree30, freemem, 30);
- /* v_pgin is maintained by clock.c */
- cp = &cnt.v_first; rp = &rate.v_first; sp = &sum.v_first;
- while (cp <= &cnt.v_last) {
- ave(*rp, *cp, 5);
- *sp += *cp;
- *cp = 0;
- rp++, cp++, sp++;
- }
- if (time % 5 == 0) {
- vmtotal();
- rate.v_swpin = cnt.v_swpin;
- sum.v_swpin += cnt.v_swpin;
- cnt.v_swpin = 0;
- rate.v_swpout = cnt.v_swpout;
- sum.v_swpout += cnt.v_swpout;
- cnt.v_swpout = 0;
- }
- if (avefree < minfree && runout || proc[0].p_slptime > maxslp/2) {
- runout = 0;
- runin = 0;
- wakeup((caddr_t)&runin);
- wakeup((caddr_t)&runout);
- }
-}
-
-vmpago()
-{
- register int vavail;
- register int 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.