xref: /netbsd-src/sys/uvm/uvm_stat.c (revision e89934bbf778a6d6d6894877c4da59d0c7835b0f)
1 /*	$NetBSD: uvm_stat.c,v 1.38 2016/12/01 01:59:17 mrg Exp $	 */
2 
3 /*
4  * Copyright (c) 1997 Charles D. Cranor and Washington University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * from: Id: uvm_stat.c,v 1.1.2.3 1997/12/19 15:01:00 mrg Exp
28  */
29 
30 /*
31  * uvm_stat.c
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: uvm_stat.c,v 1.38 2016/12/01 01:59:17 mrg Exp $");
36 
37 #include "opt_readahead.h"
38 #include "opt_ddb.h"
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/cpu.h>
43 
44 #include <uvm/uvm.h>
45 #include <uvm/uvm_ddb.h>
46 
47 #ifdef DDB
48 
49 /*
50  * uvmexp_print: ddb hook to print interesting uvm counters
51  */
52 void
53 uvmexp_print(void (*pr)(const char *, ...)
54     __attribute__((__format__(__printf__,1,2))))
55 {
56 	int active, inactive;
57 	CPU_INFO_ITERATOR cii;
58 	struct cpu_info *ci;
59 
60 	uvm_estimatepageable(&active, &inactive);
61 
62 	(*pr)("Current UVM status:\n");
63 	(*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d, ncolors=%d\n",
64 	    uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
65 	    uvmexp.pageshift, uvmexp.ncolors);
66 	(*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free\n",
67 	    uvmexp.npages, active, inactive, uvmexp.wired,
68 	    uvmexp.free);
69 	(*pr)("  pages  %d anon, %d file, %d exec\n",
70 	    uvmexp.anonpages, uvmexp.filepages, uvmexp.execpages);
71 	(*pr)("  freemin=%d, free-target=%d, wired-max=%d\n",
72 	    uvmexp.freemin, uvmexp.freetarg, uvmexp.wiredmax);
73 	(*pr)("  resv-pg=%d, resv-kernel=%d, zeropages=%d\n",
74 	    uvmexp.reserve_pagedaemon, uvmexp.reserve_kernel, uvmexp.zeropages);
75 
76 	for (CPU_INFO_FOREACH(cii, ci)) {
77 		(*pr)("  cpu%u:\n", cpu_index(ci));
78 		(*pr)("    faults=%" PRIu64 ", traps=%" PRIu64 ", "
79 		    "intrs=%" PRIu64 ", ctxswitch=%" PRIu64 "\n",
80 		    ci->ci_data.cpu_nfault, ci->ci_data.cpu_ntrap,
81 		    ci->ci_data.cpu_nintr, ci->ci_data.cpu_nswtch);
82 		(*pr)("    softint=%" PRIu64 ", syscalls=%" PRIu64 "\n",
83 		    ci->ci_data.cpu_nsoft, ci->ci_data.cpu_nsyscall);
84 	}
85 
86 	(*pr)("  fault counts:\n");
87 	(*pr)("    noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n",
88 	    uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait,
89 	    uvmexp.fltpgrele);
90 	(*pr)("    ok relocks(total)=%d(%d), anget(retrys)=%d(%d), "
91 	    "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck,
92 	    uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy);
93 	(*pr)("    neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
94 	    uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget);
95 	(*pr)("    cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
96 	    uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy,
97 	    uvmexp.flt_przero);
98 
99 	(*pr)("  daemon and swap counts:\n");
100 	(*pr)("    woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
101 	    uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
102 	    uvmexp.pdanscan);
103 	(*pr)("    busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
104 	    uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
105 	(*pr)("    pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
106 	    uvmexp.pdpending, uvmexp.nswget);
107 	(*pr)("    nswapdev=%d, swpgavail=%d\n",
108 	    uvmexp.nswapdev, uvmexp.swpgavail);
109 	(*pr)("    swpages=%d, swpginuse=%d, swpgonly=%d, paging=%d\n",
110 	    uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
111 }
112 #endif
113 
114 #if defined(READAHEAD_STATS)
115 
116 #define	UVM_RA_EVCNT_DEFINE(name) \
117 struct evcnt uvm_ra_##name = \
118 EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "readahead", #name); \
119 EVCNT_ATTACH_STATIC(uvm_ra_##name);
120 
121 UVM_RA_EVCNT_DEFINE(total);
122 UVM_RA_EVCNT_DEFINE(hit);
123 UVM_RA_EVCNT_DEFINE(miss);
124 
125 #endif /* defined(READAHEAD_STATS) */
126