Home | History | Annotate | Line # | Download | only in uvm
uvm_meter.c revision 1.36
      1  1.36    simonb /*	$NetBSD: uvm_meter.c,v 1.36 2005/11/09 12:47:39 simonb 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.36    simonb __KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.36 2005/11/09 12:47:39 simonb 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.35   thorpej static const 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.35   thorpej uvm_meter(void)
     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.35   thorpej uvm_loadav(struct loadavg *avg)
     96   1.1       mrg {
     97   1.4       mrg 	int i, nrun;
     98  1.24   thorpej 	struct lwp *l;
     99   1.1       mrg 
    100  1.10   thorpej 	proclist_lock_read();
    101  1.14       chs 	nrun = 0;
    102  1.24   thorpej 	LIST_FOREACH(l, &alllwp, l_list) {
    103  1.24   thorpej 		switch (l->l_stat) {
    104  1.24   thorpej 		case LSSLEEP:
    105  1.24   thorpej 			if (l->l_priority > PZERO || l->l_slptime > 1)
    106   1.4       mrg 				continue;
    107   1.4       mrg 		/* fall through */
    108  1.24   thorpej 		case LSRUN:
    109  1.24   thorpej 		case LSONPROC:
    110  1.24   thorpej 		case LSIDL:
    111   1.4       mrg 			nrun++;
    112   1.4       mrg 		}
    113   1.4       mrg 	}
    114   1.9   thorpej 	proclist_unlock_read();
    115   1.4       mrg 	for (i = 0; i < 3; i++)
    116   1.4       mrg 		avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
    117   1.4       mrg 		    nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
    118   1.1       mrg }
    119   1.1       mrg 
    120   1.1       mrg /*
    121  1.27    atatat  * sysctl helper routine for the vm.vmmeter node.
    122   1.1       mrg  */
    123  1.27    atatat static int
    124  1.27    atatat sysctl_vm_meter(SYSCTLFN_ARGS)
    125   1.1       mrg {
    126  1.27    atatat 	struct sysctlnode node;
    127   1.4       mrg 	struct vmtotal vmtotals;
    128   1.1       mrg 
    129  1.27    atatat 	node = *rnode;
    130  1.27    atatat 	node.sysctl_data = &vmtotals;
    131  1.27    atatat 	uvm_total(&vmtotals);
    132  1.23       chs 
    133  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    134  1.27    atatat }
    135  1.23       chs 
    136  1.27    atatat /*
    137  1.27    atatat  * sysctl helper routine for the vm.uvmexp node.
    138  1.27    atatat  */
    139  1.27    atatat static int
    140  1.27    atatat sysctl_vm_uvmexp(SYSCTLFN_ARGS)
    141  1.27    atatat {
    142  1.27    atatat 	struct sysctlnode node;
    143  1.23       chs 
    144  1.27    atatat 	node = *rnode;
    145  1.27    atatat 	if (oldp)
    146  1.27    atatat 		node.sysctl_size = min(*oldlenp, node.sysctl_size);
    147  1.23       chs 
    148  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    149  1.15    simonb }
    150  1.15    simonb 
    151  1.15    simonb static int
    152  1.27    atatat sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
    153  1.15    simonb {
    154  1.27    atatat 	struct sysctlnode node;
    155  1.15    simonb 	struct uvmexp_sysctl u;
    156  1.15    simonb 
    157  1.16    simonb 	memset(&u, 0, sizeof(u));
    158  1.16    simonb 
    159  1.16    simonb 	/* Entries here are in order of uvmexp_sysctl, not uvmexp */
    160  1.15    simonb 	u.pagesize = uvmexp.pagesize;
    161  1.15    simonb 	u.pagemask = uvmexp.pagemask;
    162  1.15    simonb 	u.pageshift = uvmexp.pageshift;
    163  1.15    simonb 	u.npages = uvmexp.npages;
    164  1.15    simonb 	u.free = uvmexp.free;
    165  1.15    simonb 	u.active = uvmexp.active;
    166  1.15    simonb 	u.inactive = uvmexp.inactive;
    167  1.15    simonb 	u.paging = uvmexp.paging;
    168  1.15    simonb 	u.wired = uvmexp.wired;
    169  1.15    simonb 	u.zeropages = uvmexp.zeropages;
    170  1.15    simonb 	u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
    171  1.15    simonb 	u.reserve_kernel = uvmexp.reserve_kernel;
    172  1.15    simonb 	u.freemin = uvmexp.freemin;
    173  1.15    simonb 	u.freetarg = uvmexp.freetarg;
    174  1.15    simonb 	u.inactarg = uvmexp.inactarg;
    175  1.15    simonb 	u.wiredmax = uvmexp.wiredmax;
    176  1.15    simonb 	u.nswapdev = uvmexp.nswapdev;
    177  1.15    simonb 	u.swpages = uvmexp.swpages;
    178  1.15    simonb 	u.swpginuse = uvmexp.swpginuse;
    179  1.15    simonb 	u.swpgonly = uvmexp.swpgonly;
    180  1.15    simonb 	u.nswget = uvmexp.nswget;
    181  1.15    simonb 	u.faults = uvmexp.faults;
    182  1.15    simonb 	u.traps = uvmexp.traps;
    183  1.15    simonb 	u.intrs = uvmexp.intrs;
    184  1.15    simonb 	u.swtch = uvmexp.swtch;
    185  1.15    simonb 	u.softs = uvmexp.softs;
    186  1.15    simonb 	u.syscalls = uvmexp.syscalls;
    187  1.15    simonb 	u.pageins = uvmexp.pageins;
    188  1.15    simonb 	u.swapins = uvmexp.swapins;
    189  1.15    simonb 	u.swapouts = uvmexp.swapouts;
    190  1.15    simonb 	u.pgswapin = uvmexp.pgswapin;
    191  1.15    simonb 	u.pgswapout = uvmexp.pgswapout;
    192  1.15    simonb 	u.forks = uvmexp.forks;
    193  1.15    simonb 	u.forks_ppwait = uvmexp.forks_ppwait;
    194  1.15    simonb 	u.forks_sharevm = uvmexp.forks_sharevm;
    195  1.15    simonb 	u.pga_zerohit = uvmexp.pga_zerohit;
    196  1.15    simonb 	u.pga_zeromiss = uvmexp.pga_zeromiss;
    197  1.15    simonb 	u.zeroaborts = uvmexp.zeroaborts;
    198  1.15    simonb 	u.fltnoram = uvmexp.fltnoram;
    199  1.15    simonb 	u.fltnoanon = uvmexp.fltnoanon;
    200  1.15    simonb 	u.fltpgwait = uvmexp.fltpgwait;
    201  1.15    simonb 	u.fltpgrele = uvmexp.fltpgrele;
    202  1.15    simonb 	u.fltrelck = uvmexp.fltrelck;
    203  1.15    simonb 	u.fltrelckok = uvmexp.fltrelckok;
    204  1.15    simonb 	u.fltanget = uvmexp.fltanget;
    205  1.15    simonb 	u.fltanretry = uvmexp.fltanretry;
    206  1.15    simonb 	u.fltamcopy = uvmexp.fltamcopy;
    207  1.15    simonb 	u.fltnamap = uvmexp.fltnamap;
    208  1.15    simonb 	u.fltnomap = uvmexp.fltnomap;
    209  1.15    simonb 	u.fltlget = uvmexp.fltlget;
    210  1.15    simonb 	u.fltget = uvmexp.fltget;
    211  1.15    simonb 	u.flt_anon = uvmexp.flt_anon;
    212  1.15    simonb 	u.flt_acow = uvmexp.flt_acow;
    213  1.15    simonb 	u.flt_obj = uvmexp.flt_obj;
    214  1.15    simonb 	u.flt_prcopy = uvmexp.flt_prcopy;
    215  1.15    simonb 	u.flt_przero = uvmexp.flt_przero;
    216  1.15    simonb 	u.pdwoke = uvmexp.pdwoke;
    217  1.15    simonb 	u.pdrevs = uvmexp.pdrevs;
    218  1.15    simonb 	u.pdswout = uvmexp.pdswout;
    219  1.15    simonb 	u.pdfreed = uvmexp.pdfreed;
    220  1.15    simonb 	u.pdscans = uvmexp.pdscans;
    221  1.15    simonb 	u.pdanscan = uvmexp.pdanscan;
    222  1.15    simonb 	u.pdobscan = uvmexp.pdobscan;
    223  1.15    simonb 	u.pdreact = uvmexp.pdreact;
    224  1.15    simonb 	u.pdbusy = uvmexp.pdbusy;
    225  1.15    simonb 	u.pdpageouts = uvmexp.pdpageouts;
    226  1.15    simonb 	u.pdpending = uvmexp.pdpending;
    227  1.15    simonb 	u.pddeact = uvmexp.pddeact;
    228  1.16    simonb 	u.anonpages = uvmexp.anonpages;
    229  1.23       chs 	u.filepages = uvmexp.filepages;
    230  1.23       chs 	u.execpages = uvmexp.execpages;
    231  1.18   thorpej 	u.colorhit = uvmexp.colorhit;
    232  1.18   thorpej 	u.colormiss = uvmexp.colormiss;
    233  1.15    simonb 
    234  1.27    atatat 	node = *rnode;
    235  1.27    atatat 	node.sysctl_data = &u;
    236  1.27    atatat 	node.sysctl_size = sizeof(u);
    237  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    238  1.27    atatat }
    239  1.27    atatat 
    240  1.27    atatat /*
    241  1.27    atatat  * sysctl helper routine for the vm.{anon,exec,file}{min,max} nodes.
    242  1.27    atatat  * makes sure that they all correlate properly and none are set too
    243  1.27    atatat  * large.
    244  1.27    atatat  */
    245  1.27    atatat static int
    246  1.27    atatat sysctl_vm_updateminmax(SYSCTLFN_ARGS)
    247  1.27    atatat {
    248  1.27    atatat 	int t, error;
    249  1.27    atatat 	struct sysctlnode node;
    250  1.27    atatat 
    251  1.27    atatat 	node = *rnode;
    252  1.27    atatat 	node.sysctl_data = &t;
    253  1.27    atatat 	t = *(int*)rnode->sysctl_data;
    254  1.27    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    255  1.27    atatat 	if (error || newp == NULL)
    256  1.27    atatat 		return (error);
    257  1.27    atatat 
    258  1.27    atatat 	if (t < 0 || t > 100)
    259  1.27    atatat 		return (EINVAL);
    260  1.27    atatat 
    261  1.27    atatat #define UPDATEMIN(a, ap, bp, cp, tp) do { \
    262  1.27    atatat 		if (tp + uvmexp.bp + uvmexp.cp > 95) \
    263  1.27    atatat 			return (EINVAL); \
    264  1.27    atatat 		uvmexp.ap = tp; \
    265  1.27    atatat 		uvmexp.a = uvmexp.ap * 256 / 100; \
    266  1.27    atatat 	} while (0/*CONSTCOND*/)
    267  1.27    atatat 
    268  1.27    atatat #define UPDATEMAX(a, ap, tp) do { \
    269  1.27    atatat 		uvmexp.ap = tp; \
    270  1.27    atatat 		uvmexp.a = tp * 256 / 100; \
    271  1.27    atatat 	} while (0/*CONSTCOND*/)
    272  1.27    atatat 
    273  1.27    atatat 	switch (rnode->sysctl_num) {
    274  1.27    atatat 	case VM_ANONMIN:
    275  1.27    atatat 		UPDATEMIN(anonmin, anonminpct, fileminpct, execminpct, t);
    276  1.27    atatat 		break;
    277  1.27    atatat 	case VM_EXECMIN:
    278  1.29      yamt 		UPDATEMIN(execmin, execminpct, anonminpct, fileminpct, t);
    279  1.27    atatat 		break;
    280  1.27    atatat 	case VM_FILEMIN:
    281  1.29      yamt 		UPDATEMIN(filemin, fileminpct, execminpct, anonminpct, t);
    282  1.27    atatat 		break;
    283  1.27    atatat 	case VM_ANONMAX:
    284  1.27    atatat 		UPDATEMAX(anonmax, anonmaxpct, t);
    285  1.27    atatat 		break;
    286  1.27    atatat 	case VM_EXECMAX:
    287  1.27    atatat 		UPDATEMAX(execmax, execmaxpct, t);
    288  1.27    atatat 		break;
    289  1.27    atatat 	case VM_FILEMAX:
    290  1.27    atatat 		UPDATEMAX(filemax, filemaxpct, t);
    291  1.27    atatat 		break;
    292  1.27    atatat 	default:
    293  1.27    atatat 		return (EINVAL);
    294  1.27    atatat 	}
    295  1.27    atatat 
    296  1.27    atatat #undef UPDATEMIN
    297  1.27    atatat #undef UPDATEMAX
    298  1.27    atatat 
    299  1.27    atatat 	return (0);
    300  1.27    atatat }
    301  1.27    atatat 
    302  1.27    atatat /*
    303  1.27    atatat  * uvm_sysctl: sysctl hook into UVM system.
    304  1.27    atatat  */
    305  1.27    atatat SYSCTL_SETUP(sysctl_vm_setup, "sysctl vm subtree setup")
    306  1.27    atatat {
    307  1.27    atatat 
    308  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    309  1.31    atatat 		       CTLFLAG_PERMANENT,
    310  1.27    atatat 		       CTLTYPE_NODE, "vm", NULL,
    311  1.27    atatat 		       NULL, 0, NULL, 0,
    312  1.27    atatat 		       CTL_VM, CTL_EOL);
    313  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    314  1.31    atatat 		       CTLFLAG_PERMANENT,
    315  1.32    atatat 		       CTLTYPE_STRUCT, "vmmeter",
    316  1.32    atatat 		       SYSCTL_DESCR("Simple system-wide virtual memory "
    317  1.32    atatat 				    "statistics"),
    318  1.27    atatat 		       sysctl_vm_meter, 0, NULL, sizeof(struct vmtotal),
    319  1.27    atatat 		       CTL_VM, VM_METER, CTL_EOL);
    320  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    321  1.31    atatat 		       CTLFLAG_PERMANENT,
    322  1.32    atatat 		       CTLTYPE_STRUCT, "loadavg",
    323  1.32    atatat 		       SYSCTL_DESCR("System load average history"),
    324  1.27    atatat 		       NULL, 0, &averunnable, sizeof(averunnable),
    325  1.27    atatat 		       CTL_VM, VM_LOADAVG, CTL_EOL);
    326  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    327  1.31    atatat 		       CTLFLAG_PERMANENT,
    328  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp",
    329  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    330  1.32    atatat 				    "statistics"),
    331  1.27    atatat 		       sysctl_vm_uvmexp, 0, &uvmexp, sizeof(uvmexp),
    332  1.27    atatat 		       CTL_VM, VM_UVMEXP, CTL_EOL);
    333  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    334  1.31    atatat 		       CTLFLAG_PERMANENT,
    335  1.32    atatat 		       CTLTYPE_INT, "nkmempages",
    336  1.32    atatat 		       SYSCTL_DESCR("Default number of pages in kmem_map"),
    337  1.27    atatat 		       NULL, 0, &nkmempages, 0,
    338  1.27    atatat 		       CTL_VM, VM_NKMEMPAGES, CTL_EOL);
    339  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    340  1.31    atatat 		       CTLFLAG_PERMANENT,
    341  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp2",
    342  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    343  1.32    atatat 				    "statistics (MI)"),
    344  1.27    atatat 		       sysctl_vm_uvmexp2, 0, NULL, 0,
    345  1.27    atatat 		       CTL_VM, VM_UVMEXP2, CTL_EOL);
    346  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    347  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    348  1.32    atatat 		       CTLTYPE_INT, "anonmin",
    349  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory reserved "
    350  1.32    atatat 				    "for anonymous application data"),
    351  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.anonminpct, 0,
    352  1.27    atatat 		       CTL_VM, VM_ANONMIN, CTL_EOL);
    353  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    354  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    355  1.32    atatat 		       CTLTYPE_INT, "execmin",
    356  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory reserved "
    357  1.32    atatat 				    "for cached executable data"),
    358  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.execminpct, 0,
    359  1.27    atatat 		       CTL_VM, VM_EXECMIN, CTL_EOL);
    360  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    361  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    362  1.32    atatat 		       CTLTYPE_INT, "filemin",
    363  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory reserved "
    364  1.32    atatat 				    "for cached file data"),
    365  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.fileminpct, 0,
    366  1.27    atatat 		       CTL_VM, VM_FILEMIN, CTL_EOL);
    367  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    368  1.32    atatat 		       CTLFLAG_PERMANENT, CTLTYPE_INT, "maxslp",
    369  1.32    atatat 		       SYSCTL_DESCR("Maximum process sleep time before being "
    370  1.32    atatat 				    "swapped"),
    371  1.27    atatat 		       NULL, 0, &maxslp, 0,
    372  1.27    atatat 		       CTL_VM, VM_MAXSLP, CTL_EOL);
    373  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    374  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    375  1.32    atatat 		       CTLTYPE_INT, "uspace",
    376  1.32    atatat 		       SYSCTL_DESCR("Number of bytes allocated for a kernel "
    377  1.32    atatat 				    "stack"),
    378  1.27    atatat 		       NULL, USPACE, NULL, 0,
    379  1.27    atatat 		       CTL_VM, VM_USPACE, CTL_EOL);
    380  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    381  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    382  1.32    atatat 		       CTLTYPE_INT, "anonmax",
    383  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory which will "
    384  1.32    atatat 				    "be reclaimed from other usage for "
    385  1.32    atatat 				    "anonymous application data"),
    386  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.anonmaxpct, 0,
    387  1.27    atatat 		       CTL_VM, VM_ANONMAX, CTL_EOL);
    388  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    389  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    390  1.32    atatat 		       CTLTYPE_INT, "execmax",
    391  1.32    atatat                        SYSCTL_DESCR("Percentage of physical memory which will "
    392  1.32    atatat 				    "be reclaimed from other usage for cached "
    393  1.32    atatat 				    "executable data"),
    394  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.execmaxpct, 0,
    395  1.27    atatat 		       CTL_VM, VM_EXECMAX, CTL_EOL);
    396  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    397  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    398  1.32    atatat 		       CTLTYPE_INT, "filemax",
    399  1.32    atatat 		       SYSCTL_DESCR("Percentage of physical memory which will "
    400  1.32    atatat 				    "be reclaimed from other usage for cached "
    401  1.32    atatat 				    "file data"),
    402  1.27    atatat 		       sysctl_vm_updateminmax, 0, &uvmexp.filemaxpct, 0,
    403  1.27    atatat 		       CTL_VM, VM_FILEMAX, CTL_EOL);
    404  1.33      yamt 	sysctl_createv(clog, 0, NULL, NULL,
    405  1.33      yamt 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    406  1.33      yamt 		       CTLTYPE_INT, "idlezero",
    407  1.33      yamt 		       SYSCTL_DESCR("Whether try to zero pages in idle loop"),
    408  1.33      yamt 		       NULL, 0, &vm_page_zero_enable, 0,
    409  1.33      yamt 		       CTL_VM, CTL_CREATE, CTL_EOL);
    410   1.1       mrg }
    411   1.1       mrg 
    412   1.1       mrg /*
    413   1.1       mrg  * uvm_total: calculate the current state of the system.
    414   1.1       mrg  */
    415   1.4       mrg static void
    416  1.35   thorpej uvm_total(struct vmtotal *totalp)
    417   1.1       mrg {
    418  1.24   thorpej 	struct lwp *l;
    419   1.1       mrg #if 0
    420  1.20       chs 	struct vm_map_entry *	entry;
    421  1.20       chs 	struct vm_map *map;
    422   1.4       mrg 	int paging;
    423   1.1       mrg #endif
    424   1.1       mrg 
    425   1.7     perry 	memset(totalp, 0, sizeof *totalp);
    426   1.1       mrg 
    427   1.4       mrg 	/*
    428   1.4       mrg 	 * calculate process statistics
    429   1.4       mrg 	 */
    430   1.4       mrg 
    431  1.10   thorpej 	proclist_lock_read();
    432  1.30  junyoung 	    LIST_FOREACH(l, &alllwp, l_list) {
    433  1.24   thorpej 		if (l->l_proc->p_flag & P_SYSTEM)
    434   1.4       mrg 			continue;
    435  1.24   thorpej 		switch (l->l_stat) {
    436   1.4       mrg 		case 0:
    437   1.4       mrg 			continue;
    438   1.6       mrg 
    439  1.24   thorpej 		case LSSLEEP:
    440  1.24   thorpej 		case LSSTOP:
    441  1.24   thorpej 			if (l->l_flag & L_INMEM) {
    442  1.24   thorpej 				if (l->l_priority <= PZERO)
    443   1.4       mrg 					totalp->t_dw++;
    444  1.24   thorpej 				else if (l->l_slptime < maxslp)
    445   1.4       mrg 					totalp->t_sl++;
    446  1.24   thorpej 			} else if (l->l_slptime < maxslp)
    447   1.4       mrg 				totalp->t_sw++;
    448  1.24   thorpej 			if (l->l_slptime >= maxslp)
    449   1.4       mrg 				continue;
    450   1.4       mrg 			break;
    451   1.6       mrg 
    452  1.24   thorpej 		case LSRUN:
    453  1.24   thorpej 		case LSONPROC:
    454  1.24   thorpej 		case LSIDL:
    455  1.24   thorpej 			if (l->l_flag & L_INMEM)
    456   1.4       mrg 				totalp->t_rq++;
    457   1.4       mrg 			else
    458   1.4       mrg 				totalp->t_sw++;
    459  1.24   thorpej 			if (l->l_stat == LSIDL)
    460   1.4       mrg 				continue;
    461   1.4       mrg 			break;
    462   1.4       mrg 		}
    463   1.4       mrg 		/*
    464   1.4       mrg 		 * note active objects
    465   1.4       mrg 		 */
    466   1.1       mrg #if 0
    467   1.4       mrg 		/*
    468  1.36    simonb 		 * XXXCDC: BOGUS!  rethink this.  in the mean time
    469   1.5       mrg 		 * don't do it.
    470   1.4       mrg 		 */
    471   1.4       mrg 		paging = 0;
    472   1.5       mrg 		vm_map_lock(map);
    473   1.4       mrg 		for (map = &p->p_vmspace->vm_map, entry = map->header.next;
    474   1.4       mrg 		    entry != &map->header; entry = entry->next) {
    475   1.4       mrg 			if (entry->is_a_map || entry->is_sub_map ||
    476   1.5       mrg 			    entry->object.uvm_obj == NULL)
    477   1.4       mrg 				continue;
    478   1.5       mrg 			/* XXX how to do this with uvm */
    479   1.4       mrg 		}
    480   1.5       mrg 		vm_map_unlock(map);
    481   1.4       mrg 		if (paging)
    482   1.4       mrg 			totalp->t_pw++;
    483   1.1       mrg #endif
    484   1.4       mrg 	}
    485   1.9   thorpej 	proclist_unlock_read();
    486   1.4       mrg 	/*
    487   1.4       mrg 	 * Calculate object memory usage statistics.
    488   1.4       mrg 	 */
    489   1.5       mrg 	totalp->t_free = uvmexp.free;
    490   1.5       mrg 	totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
    491   1.5       mrg 	totalp->t_avm = uvmexp.active + uvmexp.swpginuse;	/* XXX */
    492   1.5       mrg 	totalp->t_rm = uvmexp.npages - uvmexp.free;
    493   1.5       mrg 	totalp->t_arm = uvmexp.active;
    494   1.5       mrg 	totalp->t_vmshr = 0;		/* XXX */
    495   1.5       mrg 	totalp->t_avmshr = 0;		/* XXX */
    496   1.5       mrg 	totalp->t_rmshr = 0;		/* XXX */
    497   1.5       mrg 	totalp->t_armshr = 0;		/* XXX */
    498   1.1       mrg }
    499