xref: /netbsd-src/sys/uvm/uvm_stat.c (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1 /*	$NetBSD: uvm_stat.c,v 1.43 2019/12/31 13:07:14 ad 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.43 2019/12/31 13:07:14 ad 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 #include <sys/pool.h>
50 
51 /*
52  * uvmexp_print: ddb hook to print interesting uvm counters
53  */
54 void
55 uvmexp_print(void (*pr)(const char *, ...)
56     __attribute__((__format__(__printf__,1,2))))
57 {
58 	int active, inactive;
59 	int poolpages;
60 
61 	uvm_estimatepageable(&active, &inactive);
62 	poolpages = pool_totalpages_locked();
63 
64 	cpu_count_sync_all();
65 	(*pr)("Current UVM status:\n");
66 	(*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d, ncolors=%d\n",
67 	    uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
68 	    uvmexp.pageshift, uvmexp.ncolors);
69 	(*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free\n",
70 	    uvmexp.npages, active, inactive, uvmexp.wired, uvm_availmem());
71 	(*pr)("  pages  %" PRId64 " anon, %" PRId64 " file, %" PRId64 " exec\n",
72 	    cpu_count_get(CPU_COUNT_ANONPAGES),
73 	    cpu_count_get(CPU_COUNT_FILEPAGES),
74 	    cpu_count_get(CPU_COUNT_EXECPAGES));
75 	(*pr)("  freemin=%d, free-target=%d, wired-max=%d\n",
76 	    uvmexp.freemin, uvmexp.freetarg, uvmexp.wiredmax);
77 	(*pr)("  resv-pg=%d, resv-kernel=%d, zeropages=%" PRId64 "\n",
78 	    uvmexp.reserve_pagedaemon, uvmexp.reserve_kernel,
79 	    cpu_count_get(CPU_COUNT_ZEROPAGES));
80 	(*pr)("  bootpages=%d, poolpages=%d\n",
81 	    uvmexp.bootpages, poolpages);
82 
83 	(*pr)("  faults=%" PRId64 ", traps=%" PRId64 ", "
84 	      "intrs=%" PRId64 ", ctxswitch=%" PRId64 "\n",
85 	    cpu_count_get(CPU_COUNT_NFAULT),
86 	    cpu_count_get(CPU_COUNT_NTRAP),
87 	    cpu_count_get(CPU_COUNT_NINTR),
88 	    cpu_count_get(CPU_COUNT_NSWTCH));
89 	(*pr)("   softint=%" PRId64 ", syscalls=%" PRId64 "\n",
90 	    cpu_count_get(CPU_COUNT_NSOFT),
91 	    cpu_count_get(CPU_COUNT_NSYSCALL));
92 
93 	(*pr)("  fault counts:\n");
94 	(*pr)("    noram=%" PRId64 ", noanon=%" PRId64 ", pgwait=%" PRId64
95 	    ", pgrele=%" PRId64 "\n",
96 	    cpu_count_get(CPU_COUNT_FLTNORAM),
97 	    cpu_count_get(CPU_COUNT_FLTNOANON),
98 	    cpu_count_get(CPU_COUNT_FLTPGWAIT),
99 	    cpu_count_get(CPU_COUNT_FLTPGRELE));
100 	(*pr)("    ok relocks(total)=%" PRId64 "(%" PRId64 "), "
101 	    "anget(retrys)=%" PRId64 "(%" PRId64 "), amapcopy=%" PRId64 "\n",
102 	    cpu_count_get(CPU_COUNT_FLTRELCKOK),
103 	    cpu_count_get(CPU_COUNT_FLTRELCK),
104 	    cpu_count_get(CPU_COUNT_FLTANGET),
105 	    cpu_count_get(CPU_COUNT_FLTANRETRY),
106 	    cpu_count_get(CPU_COUNT_FLTAMCOPY));
107 	(*pr)("    neighbor anon/obj pg=%" PRId64 "/%" PRId64
108 	    ", gets(lock/unlock)=%" PRId64 "/%" PRId64 "\n",
109 	    cpu_count_get(CPU_COUNT_FLTNAMAP),
110 	    cpu_count_get(CPU_COUNT_FLTNOMAP),
111 	    cpu_count_get(CPU_COUNT_FLTLGET),
112 	    cpu_count_get(CPU_COUNT_FLTGET));
113 	(*pr)("    cases: anon=%" PRId64 ", anoncow=%" PRId64 ", obj=%" PRId64
114 	    ", prcopy=%" PRId64 ", przero=%" PRId64 "\n",
115 	    cpu_count_get(CPU_COUNT_FLT_ANON),
116 	    cpu_count_get(CPU_COUNT_FLT_ACOW),
117 	    cpu_count_get(CPU_COUNT_FLT_OBJ),
118 	    cpu_count_get(CPU_COUNT_FLT_PRCOPY),
119 	    cpu_count_get(CPU_COUNT_FLT_PRZERO));
120 
121 	(*pr)("  daemon and swap counts:\n");
122 	(*pr)("    woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
123 	    uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
124 	    uvmexp.pdanscan);
125 	(*pr)("    busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
126 	    uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
127 	(*pr)("    pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
128 	    uvmexp.pdpending, uvmexp.nswget);
129 	(*pr)("    nswapdev=%d, swpgavail=%d\n",
130 	    uvmexp.nswapdev, uvmexp.swpgavail);
131 	(*pr)("    swpages=%d, swpginuse=%d, swpgonly=%d, paging=%d\n",
132 	    uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
133 }
134 #endif
135 
136 #if defined(READAHEAD_STATS)
137 
138 #define	UVM_RA_EVCNT_DEFINE(name) \
139 struct evcnt uvm_ra_##name = \
140 EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "readahead", #name); \
141 EVCNT_ATTACH_STATIC(uvm_ra_##name);
142 
143 UVM_RA_EVCNT_DEFINE(total);
144 UVM_RA_EVCNT_DEFINE(hit);
145 UVM_RA_EVCNT_DEFINE(miss);
146 
147 #endif /* defined(READAHEAD_STATS) */
148