Home | History | Annotate | Line # | Download | only in uvm
uvm_meter.c revision 1.32
      1  1.32    atatat /*	$NetBSD: uvm_meter.c,v 1.32 2004/05/25 04:31:17 atatat Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4   1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5   1.1       mrg  * Copyright (c) 1982, 1986, 1989, 1993
      6  1.19       chs  *      The Regents of the University of California.
      7   1.1       mrg  *
      8   1.1       mrg  * All rights reserved.
      9   1.1       mrg  *
     10   1.1       mrg  * Redistribution and use in source and binary forms, with or without
     11   1.1       mrg  * modification, are permitted provided that the following conditions
     12   1.1       mrg  * are met:
     13   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     14   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     15   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     18   1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     19   1.1       mrg  *    must display the following acknowledgement:
     20   1.1       mrg  *      This product includes software developed by Charles D. Cranor,
     21  1.19       chs  *      Washington University, and the University of California, Berkeley
     22   1.1       mrg  *      and its contributors.
     23   1.1       mrg  * 4. Neither the name of the University nor the names of its contributors
     24   1.1       mrg  *    may be used to endorse or promote products derived from this software
     25   1.1       mrg  *    without specific prior written permission.
     26   1.1       mrg  *
     27   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28   1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29   1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30   1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31   1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32   1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33   1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34   1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35   1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37   1.1       mrg  * SUCH DAMAGE.
     38   1.1       mrg  *
     39   1.1       mrg  *      @(#)vm_meter.c  8.4 (Berkeley) 1/4/94
     40   1.3       mrg  * from: Id: uvm_meter.c,v 1.1.2.1 1997/08/14 19:10:35 chuck Exp
     41   1.1       mrg  */
     42  1.22     lukem 
     43  1.22     lukem #include <sys/cdefs.h>
     44  1.32    atatat __KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.32 2004/05/25 04:31:17 atatat Exp $");
     45   1.1       mrg 
     46   1.1       mrg #include <sys/param.h>
     47   1.1       mrg #include <sys/proc.h>
     48   1.1       mrg #include <sys/systm.h>
     49   1.1       mrg #include <sys/kernel.h>
     50  1.13       mrg #include <uvm/uvm_extern.h>
     51   1.1       mrg #include <sys/sysctl.h>
     52   1.1       mrg 
     53   1.1       mrg /*
     54   1.1       mrg  * maxslp: ???? XXXCDC
     55   1.1       mrg  */
     56   1.1       mrg 
     57   1.1       mrg int maxslp = MAXSLP;	/* patchable ... */
     58  1.14       chs struct loadavg averunnable;
     59   1.1       mrg 
     60   1.1       mrg /*
     61  1.19       chs  * constants for averages over 1, 5, and 15 minutes when sampling at
     62   1.1       mrg  * 5 second intervals.
     63   1.1       mrg  */
     64   1.1       mrg 
     65   1.1       mrg static fixpt_t cexp[3] = {
     66   1.1       mrg 	0.9200444146293232 * FSCALE,	/* exp(-1/12) */
     67   1.1       mrg 	0.9834714538216174 * FSCALE,	/* exp(-1/60) */
     68   1.1       mrg 	0.9944598480048967 * FSCALE,	/* exp(-1/180) */
     69   1.1       mrg };
     70   1.1       mrg 
     71   1.1       mrg /*
     72   1.1       mrg  * prototypes
     73   1.1       mrg  */
     74   1.1       mrg 
     75  1.30  junyoung static void uvm_loadav(struct loadavg *);
     76  1.30  junyoung static void uvm_total(struct vmtotal *);
     77   1.1       mrg 
     78   1.1       mrg /*
     79   1.1       mrg  * uvm_meter: calculate load average and wake up the swapper (if needed)
     80   1.1       mrg  */
     81   1.4       mrg void
     82   1.4       mrg uvm_meter()
     83   1.1       mrg {
     84   1.4       mrg 	if ((time.tv_sec % 5) == 0)
     85   1.4       mrg 		uvm_loadav(&averunnable);
     86  1.24   thorpej 	if (lwp0.l_slptime > (maxslp / 2))
     87  1.14       chs 		wakeup(&proc0);
     88   1.1       mrg }
     89   1.1       mrg 
     90   1.1       mrg /*
     91  1.19       chs  * uvm_loadav: compute a tenex style load average of a quantity on
     92   1.1       mrg  * 1, 5, and 15 minute internvals.
     93   1.1       mrg  */
     94   1.4       mrg static void
     95   1.4       mrg uvm_loadav(avg)
     96   1.4       mrg 	struct loadavg *avg;
     97   1.1       mrg {
     98   1.4       mrg 	int i, nrun;
     99  1.24   thorpej 	struct lwp *l;
    100   1.1       mrg 
    101  1.10   thorpej 	proclist_lock_read();
    102  1.14       chs 	nrun = 0;
    103  1.24   thorpej 	LIST_FOREACH(l, &alllwp, l_list) {
    104  1.24   thorpej 		switch (l->l_stat) {
    105  1.24   thorpej 		case LSSLEEP:
    106  1.24   thorpej 			if (l->l_priority > PZERO || l->l_slptime > 1)
    107   1.4       mrg 				continue;
    108   1.4       mrg 		/* fall through */
    109  1.24   thorpej 		case LSRUN:
    110  1.24   thorpej 		case LSONPROC:
    111  1.24   thorpej 		case LSIDL:
    112   1.4       mrg 			nrun++;
    113   1.4       mrg 		}
    114   1.4       mrg 	}
    115   1.9   thorpej 	proclist_unlock_read();
    116   1.4       mrg 	for (i = 0; i < 3; i++)
    117   1.4       mrg 		avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
    118   1.4       mrg 		    nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
    119   1.1       mrg }
    120   1.1       mrg 
    121   1.1       mrg /*
    122  1.27    atatat  * sysctl helper routine for the vm.vmmeter node.
    123   1.1       mrg  */
    124  1.27    atatat static int
    125  1.27    atatat sysctl_vm_meter(SYSCTLFN_ARGS)
    126   1.1       mrg {
    127  1.27    atatat 	struct sysctlnode node;
    128   1.4       mrg 	struct vmtotal vmtotals;
    129   1.1       mrg 
    130  1.27    atatat 	node = *rnode;
    131  1.27    atatat 	node.sysctl_data = &vmtotals;
    132  1.27    atatat 	uvm_total(&vmtotals);
    133  1.23       chs 
    134  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    135  1.27    atatat }
    136  1.23       chs 
    137  1.27    atatat /*
    138  1.27    atatat  * sysctl helper routine for the vm.uvmexp node.
    139  1.27    atatat  */
    140  1.27    atatat static int
    141  1.27    atatat sysctl_vm_uvmexp(SYSCTLFN_ARGS)
    142  1.27    atatat {
    143  1.27    atatat 	struct sysctlnode node;
    144  1.23       chs 
    145  1.27    atatat 	node = *rnode;
    146  1.27    atatat 	if (oldp)
    147  1.27    atatat 		node.sysctl_size = min(*oldlenp, node.sysctl_size);
    148  1.23       chs 
    149  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    150  1.15    simonb }
    151  1.15    simonb 
    152  1.15    simonb static int
    153  1.27    atatat sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
    154  1.15    simonb {
    155  1.27    atatat 	struct sysctlnode node;
    156  1.15    simonb 	struct uvmexp_sysctl u;
    157  1.15    simonb 
    158  1.16    simonb 	memset(&u, 0, sizeof(u));
    159  1.16    simonb 
    160  1.16    simonb 	/* Entries here are in order of uvmexp_sysctl, not uvmexp */
    161  1.15    simonb 	u.pagesize = uvmexp.pagesize;
    162  1.15    simonb 	u.pagemask = uvmexp.pagemask;
    163  1.15    simonb 	u.pageshift = uvmexp.pageshift;
    164  1.15    simonb 	u.npages = uvmexp.npages;
    165  1.15    simonb 	u.free = uvmexp.free;
    166  1.15    simonb 	u.active = uvmexp.active;
    167  1.15    simonb 	u.inactive = uvmexp.inactive;
    168  1.15    simonb 	u.paging = uvmexp.paging;
    169  1.15    simonb 	u.wired = uvmexp.wired;
    170  1.15    simonb 	u.zeropages = uvmexp.zeropages;
    171  1.15    simonb 	u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
    172  1.15    simonb 	u.reserve_kernel = uvmexp.reserve_kernel;
    173  1.15    simonb 	u.freemin = uvmexp.freemin;
    174  1.15    simonb 	u.freetarg = uvmexp.freetarg;
    175  1.15    simonb 	u.inactarg = uvmexp.inactarg;
    176  1.15    simonb 	u.wiredmax = uvmexp.wiredmax;
    177  1.15    simonb 	u.nswapdev = uvmexp.nswapdev;
    178  1.15    simonb 	u.swpages = uvmexp.swpages;
    179  1.15    simonb 	u.swpginuse = uvmexp.swpginuse;
    180  1.15    simonb 	u.swpgonly = uvmexp.swpgonly;
    181  1.15    simonb 	u.nswget = uvmexp.nswget;
    182  1.15    simonb 	u.nanon = uvmexp.nanon;
    183  1.15    simonb 	u.nanonneeded = uvmexp.nanonneeded;
    184  1.15    simonb 	u.nfreeanon = uvmexp.nfreeanon;
    185  1.15    simonb 	u.faults = uvmexp.faults;
    186  1.15    simonb 	u.traps = uvmexp.traps;
    187  1.15    simonb 	u.intrs = uvmexp.intrs;
    188  1.15    simonb 	u.swtch = uvmexp.swtch;
    189  1.15    simonb 	u.softs = uvmexp.softs;
    190  1.15    simonb 	u.syscalls = uvmexp.syscalls;
    191  1.15    simonb 	u.pageins = uvmexp.pageins;
    192  1.15    simonb 	u.swapins = uvmexp.swapins;
    193  1.15    simonb 	u.swapouts = uvmexp.swapouts;
    194  1.15    simonb 	u.pgswapin = uvmexp.pgswapin;
    195  1.15    simonb 	u.pgswapout = uvmexp.pgswapout;
    196  1.15    simonb 	u.forks = uvmexp.forks;
    197  1.15    simonb 	u.forks_ppwait = uvmexp.forks_ppwait;
    198  1.15    simonb 	u.forks_sharevm = uvmexp.forks_sharevm;
    199  1.15    simonb 	u.pga_zerohit = uvmexp.pga_zerohit;
    200  1.15    simonb 	u.pga_zeromiss = uvmexp.pga_zeromiss;
    201  1.15    simonb 	u.zeroaborts = uvmexp.zeroaborts;
    202  1.15    simonb 	u.fltnoram = uvmexp.fltnoram;
    203  1.15    simonb 	u.fltnoanon = uvmexp.fltnoanon;
    204  1.15    simonb 	u.fltpgwait = uvmexp.fltpgwait;
    205  1.15    simonb 	u.fltpgrele = uvmexp.fltpgrele;
    206  1.15    simonb 	u.fltrelck = uvmexp.fltrelck;
    207  1.15    simonb 	u.fltrelckok = uvmexp.fltrelckok;
    208  1.15    simonb 	u.fltanget = uvmexp.fltanget;
    209  1.15    simonb 	u.fltanretry = uvmexp.fltanretry;
    210  1.15    simonb 	u.fltamcopy = uvmexp.fltamcopy;
    211  1.15    simonb 	u.fltnamap = uvmexp.fltnamap;
    212  1.15    simonb 	u.fltnomap = uvmexp.fltnomap;
    213  1.15    simonb 	u.fltlget = uvmexp.fltlget;
    214  1.15    simonb 	u.fltget = uvmexp.fltget;
    215  1.15    simonb 	u.flt_anon = uvmexp.flt_anon;
    216  1.15    simonb 	u.flt_acow = uvmexp.flt_acow;
    217  1.15    simonb 	u.flt_obj = uvmexp.flt_obj;
    218  1.15    simonb 	u.flt_prcopy = uvmexp.flt_prcopy;
    219  1.15    simonb 	u.flt_przero = uvmexp.flt_przero;
    220  1.15    simonb 	u.pdwoke = uvmexp.pdwoke;
    221  1.15    simonb 	u.pdrevs = uvmexp.pdrevs;
    222  1.15    simonb 	u.pdswout = uvmexp.pdswout;
    223  1.15    simonb 	u.pdfreed = uvmexp.pdfreed;
    224  1.15    simonb 	u.pdscans = uvmexp.pdscans;
    225  1.15    simonb 	u.pdanscan = uvmexp.pdanscan;
    226  1.15    simonb 	u.pdobscan = uvmexp.pdobscan;
    227  1.15    simonb 	u.pdreact = uvmexp.pdreact;
    228  1.15    simonb 	u.pdbusy = uvmexp.pdbusy;
    229  1.15    simonb 	u.pdpageouts = uvmexp.pdpageouts;
    230  1.15    simonb 	u.pdpending = uvmexp.pdpending;
    231  1.15    simonb 	u.pddeact = uvmexp.pddeact;
    232  1.16    simonb 	u.anonpages = uvmexp.anonpages;
    233  1.23       chs 	u.filepages = uvmexp.filepages;
    234  1.23       chs 	u.execpages = uvmexp.execpages;
    235  1.18   thorpej 	u.colorhit = uvmexp.colorhit;
    236  1.18   thorpej 	u.colormiss = uvmexp.colormiss;
    237  1.15    simonb 
    238  1.27    atatat 	node = *rnode;
    239  1.27    atatat 	node.sysctl_data = &u;
    240  1.27    atatat 	node.sysctl_size = sizeof(u);
    241  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    242  1.27    atatat }
    243  1.27    atatat 
    244  1.27    atatat /*
    245  1.27    atatat  * sysctl helper routine for the vm.{anon,exec,file}{min,max} nodes.
    246  1.27    atatat  * makes sure that they all correlate properly and none are set too
    247  1.27    atatat  * large.
    248  1.27    atatat  */
    249  1.27    atatat static int
    250  1.27    atatat sysctl_vm_updateminmax(SYSCTLFN_ARGS)
    251  1.27    atatat {
    252  1.27    atatat 	int t, error;
    253  1.27    atatat 	struct sysctlnode node;
    254  1.27    atatat 
    255  1.27    atatat 	node = *rnode;
    256  1.27    atatat 	node.sysctl_data = &t;
    257  1.27    atatat 	t = *(int*)rnode->sysctl_data;
    258  1.27    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    259  1.27    atatat 	if (error || newp == NULL)
    260  1.27    atatat 		return (error);
    261  1.27    atatat 
    262  1.27    atatat 	if (t < 0 || t > 100)
    263  1.27    atatat 		return (EINVAL);
    264  1.27    atatat 
    265  1.27    atatat #define UPDATEMIN(a, ap, bp, cp, tp) do { \
    266  1.27    atatat 		if (tp + uvmexp.bp + uvmexp.cp > 95) \
    267  1.27    atatat 			return (EINVAL); \
    268  1.27    atatat 		uvmexp.ap = tp; \
    269  1.27    atatat 		uvmexp.a = uvmexp.ap * 256 / 100; \
    270  1.27    atatat 	} while (0/*CONSTCOND*/)
    271  1.27    atatat 
    272  1.27    atatat #define UPDATEMAX(a, ap, tp) do { \
    273  1.27    atatat 		uvmexp.ap = tp; \
    274  1.27    atatat 		uvmexp.a = tp * 256 / 100; \
    275  1.27    atatat 	} while (0/*CONSTCOND*/)
    276  1.27    atatat 
    277  1.27    atatat 	switch (rnode->sysctl_num) {
    278  1.27    atatat 	case VM_ANONMIN:
    279  1.27    atatat 		UPDATEMIN(anonmin, anonminpct, fileminpct, execminpct, t);
    280  1.27    atatat 		break;
    281  1.27    atatat 	case VM_EXECMIN:
    282  1.29      yamt 		UPDATEMIN(execmin, execminpct, anonminpct, fileminpct, t);
    283  1.27    atatat 		break;
    284  1.27    atatat 	case VM_FILEMIN:
    285  1.29      yamt 		UPDATEMIN(filemin, fileminpct, execminpct, anonminpct, t);
    286  1.27    atatat 		break;
    287  1.27    atatat 	case VM_ANONMAX:
    288  1.27    atatat 		UPDATEMAX(anonmax, anonmaxpct, t);
    289  1.27    atatat 		break;
    290  1.27    atatat 	case VM_EXECMAX:
    291  1.27    atatat 		UPDATEMAX(execmax, execmaxpct, t);
    292  1.27    atatat 		break;
    293  1.27    atatat 	case VM_FILEMAX:
    294  1.27    atatat 		UPDATEMAX(filemax, filemaxpct, t);
    295  1.27    atatat 		break;
    296  1.27    atatat 	default:
    297  1.27    atatat 		return (EINVAL);
    298  1.27    atatat 	}
    299  1.27    atatat 
    300  1.27    atatat #undef UPDATEMIN
    301  1.27    atatat #undef UPDATEMAX
    302  1.27    atatat 
    303  1.27    atatat 	return (0);
    304  1.27    atatat }
    305  1.27    atatat 
    306  1.27    atatat /*
    307  1.27    atatat  * uvm_sysctl: sysctl hook into UVM system.
    308  1.27    atatat  */
    309  1.27    atatat SYSCTL_SETUP(sysctl_vm_setup, "sysctl vm subtree setup")
    310  1.27    atatat {
    311  1.27    atatat 
    312  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    313  1.31    atatat 		       CTLFLAG_PERMANENT,
    314  1.27    atatat 		       CTLTYPE_NODE, "vm", NULL,
    315  1.27    atatat 		       NULL, 0, NULL, 0,
    316  1.27    atatat 		       CTL_VM, CTL_EOL);
    317  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    318  1.31    atatat 		       CTLFLAG_PERMANENT,
    319  1.32    atatat 		       CTLTYPE_STRUCT, "vmmeter",
    320  1.32    atatat 		       SYSCTL_DESCR("Simple system-wide virtual memory "
    321  1.32    atatat 				    "statistics"),
    322  1.27    atatat 		       sysctl_vm_meter, 0, NULL, sizeof(struct vmtotal),
    323  1.27    atatat 		       CTL_VM, VM_METER, CTL_EOL);
    324  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    325  1.31    atatat 		       CTLFLAG_PERMANENT,
    326  1.32    atatat 		       CTLTYPE_STRUCT, "loadavg",
    327  1.32    atatat 		       SYSCTL_DESCR("System load average history"),
    328  1.27    atatat 		       NULL, 0, &averunnable, sizeof(averunnable),
    329  1.27    atatat 		       CTL_VM, VM_LOADAVG, CTL_EOL);
    330  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    331  1.31    atatat 		       CTLFLAG_PERMANENT,
    332  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp",
    333  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    334  1.32    atatat 				    "statistics"),
    335  1.27    atatat 		       sysctl_vm_uvmexp, 0, &uvmexp, sizeof(uvmexp),
    336  1.27    atatat 		       CTL_VM, VM_UVMEXP, CTL_EOL);
    337  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    338  1.31    atatat 		       CTLFLAG_PERMANENT,
    339  1.32    atatat 		       CTLTYPE_INT, "nkmempages",
    340  1.32    atatat 		       SYSCTL_DESCR("Default number of pages in kmem_map"),
    341  1.27    atatat 		       NULL, 0, &nkmempages, 0,
    342  1.27    atatat 		       CTL_VM, VM_NKMEMPAGES, CTL_EOL);
    343  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    344  1.31    atatat 		       CTLFLAG_PERMANENT,
    345  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp2",
    346  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    347  1.32    atatat 				    "statistics (MI)"),
    348  1.27    atatat 		       sysctl_vm_uvmexp2, 0, NULL, 0,
    349  1.27    atatat 		       CTL_VM, VM_UVMEXP2, CTL_EOL);
    350  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    351  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    352  1.32    atatat 		       CTLTYPE_INT, "anonmin",
    353  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory reserved "
    354  1.32    atatat 				    "for anonymous application data"),
    355  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.anonminpct, 0,
    356  1.27    atatat 		       CTL_VM, VM_ANONMIN, CTL_EOL);
    357  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    358  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    359  1.32    atatat 		       CTLTYPE_INT, "execmin",
    360  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory reserved "
    361  1.32    atatat 				    "for cached executable data"),
    362  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.execminpct, 0,
    363  1.27    atatat 		       CTL_VM, VM_EXECMIN, CTL_EOL);
    364  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    365  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    366  1.32    atatat 		       CTLTYPE_INT, "filemin",
    367  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory reserved "
    368  1.32    atatat 				    "for cached file data"),
    369  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.fileminpct, 0,
    370  1.27    atatat 		       CTL_VM, VM_FILEMIN, CTL_EOL);
    371  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    372  1.32    atatat 		       CTLFLAG_PERMANENT, CTLTYPE_INT, "maxslp",
    373  1.32    atatat 		       SYSCTL_DESCR("Maximum process sleep time before being "
    374  1.32    atatat 				    "swapped"),
    375  1.27    atatat 		       NULL, 0, &maxslp, 0,
    376  1.27    atatat 		       CTL_VM, VM_MAXSLP, CTL_EOL);
    377  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    378  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    379  1.32    atatat 		       CTLTYPE_INT, "uspace",
    380  1.32    atatat 		       SYSCTL_DESCR("Number of bytes allocated for a kernel "
    381  1.32    atatat 				    "stack"),
    382  1.27    atatat 		       NULL, USPACE, NULL, 0,
    383  1.27    atatat 		       CTL_VM, VM_USPACE, CTL_EOL);
    384  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    385  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    386  1.32    atatat 		       CTLTYPE_INT, "anonmax",
    387  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory which will "
    388  1.32    atatat 				    "be reclaimed from other usage for "
    389  1.32    atatat 				    "anonymous application data"),
    390  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.anonmaxpct, 0,
    391  1.27    atatat 		       CTL_VM, VM_ANONMAX, CTL_EOL);
    392  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    393  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    394  1.32    atatat 		       CTLTYPE_INT, "execmax",
    395  1.32    atatat                        SYSCTL_DESCR("Percentage of physical memory which will "
    396  1.32    atatat 				    "be reclaimed from other usage for cached "
    397  1.32    atatat 				    "executable data"),
    398  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.execmaxpct, 0,
    399  1.27    atatat 		       CTL_VM, VM_EXECMAX, CTL_EOL);
    400  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    401  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    402  1.32    atatat 		       CTLTYPE_INT, "filemax",
    403  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory which will "
    404  1.32    atatat 				    "be reclaimed from other usage for cached "
    405  1.32    atatat 				    "file data"),
    406  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.filemaxpct, 0,
    407  1.27    atatat 		       CTL_VM, VM_FILEMAX, CTL_EOL);
    408   1.1       mrg }
    409   1.1       mrg 
    410   1.1       mrg /*
    411   1.1       mrg  * uvm_total: calculate the current state of the system.
    412   1.1       mrg  */
    413   1.4       mrg static void
    414   1.4       mrg uvm_total(totalp)
    415   1.4       mrg 	struct vmtotal *totalp;
    416   1.1       mrg {
    417  1.24   thorpej 	struct lwp *l;
    418   1.1       mrg #if 0
    419  1.20       chs 	struct vm_map_entry *	entry;
    420  1.20       chs 	struct vm_map *map;
    421   1.4       mrg 	int paging;
    422   1.1       mrg #endif
    423   1.1       mrg 
    424   1.7     perry 	memset(totalp, 0, sizeof *totalp);
    425   1.1       mrg 
    426   1.4       mrg 	/*
    427   1.4       mrg 	 * calculate process statistics
    428   1.4       mrg 	 */
    429   1.4       mrg 
    430  1.10   thorpej 	proclist_lock_read();
    431  1.30  junyoung 	    LIST_FOREACH(l, &alllwp, l_list) {
    432  1.24   thorpej 		if (l->l_proc->p_flag & P_SYSTEM)
    433   1.4       mrg 			continue;
    434  1.24   thorpej 		switch (l->l_stat) {
    435   1.4       mrg 		case 0:
    436   1.4       mrg 			continue;
    437   1.6       mrg 
    438  1.24   thorpej 		case LSSLEEP:
    439  1.24   thorpej 		case LSSTOP:
    440  1.24   thorpej 			if (l->l_flag & L_INMEM) {
    441  1.24   thorpej 				if (l->l_priority <= PZERO)
    442   1.4       mrg 					totalp->t_dw++;
    443  1.24   thorpej 				else if (l->l_slptime < maxslp)
    444   1.4       mrg 					totalp->t_sl++;
    445  1.24   thorpej 			} else if (l->l_slptime < maxslp)
    446   1.4       mrg 				totalp->t_sw++;
    447  1.24   thorpej 			if (l->l_slptime >= maxslp)
    448   1.4       mrg 				continue;
    449   1.4       mrg 			break;
    450   1.6       mrg 
    451  1.24   thorpej 		case LSRUN:
    452  1.24   thorpej 		case LSONPROC:
    453  1.24   thorpej 		case LSIDL:
    454  1.24   thorpej 			if (l->l_flag & L_INMEM)
    455   1.4       mrg 				totalp->t_rq++;
    456   1.4       mrg 			else
    457   1.4       mrg 				totalp->t_sw++;
    458  1.24   thorpej 			if (l->l_stat == LSIDL)
    459   1.4       mrg 				continue;
    460   1.4       mrg 			break;
    461   1.4       mrg 		}
    462   1.4       mrg 		/*
    463   1.4       mrg 		 * note active objects
    464   1.4       mrg 		 */
    465   1.1       mrg #if 0
    466   1.4       mrg 		/*
    467   1.5       mrg 		 * XXXCDC: BOGUS!  rethink this.   in the mean time
    468   1.5       mrg 		 * don't do it.
    469   1.4       mrg 		 */
    470   1.4       mrg 		paging = 0;
    471   1.5       mrg 		vm_map_lock(map);
    472   1.4       mrg 		for (map = &p->p_vmspace->vm_map, entry = map->header.next;
    473   1.4       mrg 		    entry != &map->header; entry = entry->next) {
    474   1.4       mrg 			if (entry->is_a_map || entry->is_sub_map ||
    475   1.5       mrg 			    entry->object.uvm_obj == NULL)
    476   1.4       mrg 				continue;
    477   1.5       mrg 			/* XXX how to do this with uvm */
    478   1.4       mrg 		}
    479   1.5       mrg 		vm_map_unlock(map);
    480   1.4       mrg 		if (paging)
    481   1.4       mrg 			totalp->t_pw++;
    482   1.1       mrg #endif
    483   1.4       mrg 	}
    484   1.9   thorpej 	proclist_unlock_read();
    485   1.4       mrg 	/*
    486   1.4       mrg 	 * Calculate object memory usage statistics.
    487   1.4       mrg 	 */
    488   1.5       mrg 	totalp->t_free = uvmexp.free;
    489   1.5       mrg 	totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
    490   1.5       mrg 	totalp->t_avm = uvmexp.active + uvmexp.swpginuse;	/* XXX */
    491   1.5       mrg 	totalp->t_rm = uvmexp.npages - uvmexp.free;
    492   1.5       mrg 	totalp->t_arm = uvmexp.active;
    493   1.5       mrg 	totalp->t_vmshr = 0;		/* XXX */
    494   1.5       mrg 	totalp->t_avmshr = 0;		/* XXX */
    495   1.5       mrg 	totalp->t_rmshr = 0;		/* XXX */
    496   1.5       mrg 	totalp->t_armshr = 0;		/* XXX */
    497   1.1       mrg }
    498