sleep.9: Use .Fn instead of .Nm
[dragonfly.git] / sys / vm / vm_meter.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)vm_meter.c 8.4 (Berkeley) 1/4/94
34 * $FreeBSD: src/sys/vm/vm_meter.c,v 1.34.2.7 2002/10/10 19:28:22 dillon Exp $
75210f59 35 * $DragonFly: src/sys/vm/vm_meter.c,v 1.15 2008/04/28 18:04:08 dillon Exp $
984263bc
MD
36 */
37
38#include <sys/param.h>
39#include <sys/proc.h>
40#include <sys/systm.h>
41#include <sys/kernel.h>
42#include <sys/resource.h>
43#include <sys/vmmeter.h>
44
45#include <vm/vm.h>
46#include <vm/vm_page.h>
47#include <vm/vm_extern.h>
48#include <vm/vm_param.h>
49#include <sys/lock.h>
50#include <vm/pmap.h>
51#include <vm/vm_map.h>
52#include <vm/vm_object.h>
53#include <sys/sysctl.h>
54
12e4aaff 55struct vmstats vmstats;
984263bc
MD
56
57static int maxslp = MAXSLP;
58
59SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min,
12e4aaff 60 CTLFLAG_RW, &vmstats.v_free_min, 0, "");
984263bc 61SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target,
12e4aaff 62 CTLFLAG_RW, &vmstats.v_free_target, 0, "");
984263bc 63SYSCTL_UINT(_vm, VM_V_FREE_RESERVED, v_free_reserved,
12e4aaff 64 CTLFLAG_RW, &vmstats.v_free_reserved, 0, "");
984263bc 65SYSCTL_UINT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target,
12e4aaff 66 CTLFLAG_RW, &vmstats.v_inactive_target, 0, "");
984263bc 67SYSCTL_UINT(_vm, VM_V_CACHE_MIN, v_cache_min,
12e4aaff 68 CTLFLAG_RW, &vmstats.v_cache_min, 0, "");
984263bc 69SYSCTL_UINT(_vm, VM_V_CACHE_MAX, v_cache_max,
12e4aaff 70 CTLFLAG_RW, &vmstats.v_cache_max, 0, "");
984263bc 71SYSCTL_UINT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min,
12e4aaff 72 CTLFLAG_RW, &vmstats.v_pageout_free_min, 0, "");
984263bc 73SYSCTL_UINT(_vm, OID_AUTO, v_free_severe,
12e4aaff 74 CTLFLAG_RW, &vmstats.v_free_severe, 0, "");
984263bc
MD
75
76SYSCTL_STRUCT(_vm, VM_LOADAVG, loadavg, CTLFLAG_RD,
77 &averunnable, loadavg, "Machine loadaverage history");
78
8fa76237
MD
79static int do_vmtotal_callback(struct proc *p, void *data);
80
984263bc 81static int
6bdb32ed 82do_vmtotal(SYSCTL_HANDLER_ARGS)
984263bc 83{
8fa76237
MD
84 struct vmtotal total;
85 struct vmtotal *totalp;
984263bc 86 vm_object_t object;
984263bc
MD
87
88 totalp = &total;
89 bzero(totalp, sizeof *totalp);
8fa76237 90
984263bc
MD
91 /*
92 * Mark all objects as inactive.
93 */
94 for (object = TAILQ_FIRST(&vm_object_list);
95 object != NULL;
8fa76237 96 object = TAILQ_NEXT(object,object_list)) {
00a3fdca
MD
97 if (object->type == OBJT_MARKER)
98 continue;
984263bc 99 vm_object_clear_flag(object, OBJ_ACTIVE);
8fa76237
MD
100 }
101
984263bc
MD
102 /*
103 * Calculate process statistics.
104 */
8fa76237 105 allproc_scan(do_vmtotal_callback, totalp);
984263bc 106
984263bc
MD
107 /*
108 * Calculate object memory usage statistics.
109 */
110 for (object = TAILQ_FIRST(&vm_object_list);
111 object != NULL;
112 object = TAILQ_NEXT(object, object_list)) {
113 /*
00a3fdca
MD
114 * devices, like /dev/mem, will badly skew our totals.
115 * markers aren't real objects.
984263bc 116 */
00a3fdca
MD
117 if (object->type == OBJT_MARKER)
118 continue;
984263bc
MD
119 if (object->type == OBJT_DEVICE)
120 continue;
121 totalp->t_vm += object->size;
122 totalp->t_rm += object->resident_page_count;
123 if (object->flags & OBJ_ACTIVE) {
124 totalp->t_avm += object->size;
125 totalp->t_arm += object->resident_page_count;
126 }
127 if (object->shadow_count > 1) {
128 /* shared object */
129 totalp->t_vmshr += object->size;
130 totalp->t_rmshr += object->resident_page_count;
131 if (object->flags & OBJ_ACTIVE) {
132 totalp->t_avmshr += object->size;
133 totalp->t_armshr += object->resident_page_count;
134 }
135 }
136 }
12e4aaff 137 totalp->t_free = vmstats.v_free_count + vmstats.v_cache_count;
984263bc
MD
138 return (sysctl_handle_opaque(oidp, totalp, sizeof total, req));
139}
140
8fa76237
MD
141static int
142do_vmtotal_callback(struct proc *p, void *data)
143{
144 struct vmtotal *totalp = data;
08f2f1bb 145 struct lwp *lp;
8fa76237
MD
146 vm_map_entry_t entry;
147 vm_map_t map;
148 int paging;
149
150 if (p->p_flag & P_SYSTEM)
151 return(0);
152
c7e98b2f
SS
153 FOREACH_LWP_IN_PROC(lp, p) {
154 switch (lp->lwp_stat) {
155 case LSSTOP:
156 case LSSLEEP:
157 if ((p->p_flag & P_SWAPPEDOUT) == 0) {
158 if ((lp->lwp_flag & LWP_SINTR) == 0)
159 totalp->t_dw++;
160 else if (lp->lwp_slptime < maxslp)
161 totalp->t_sl++;
162 } else if (lp->lwp_slptime < maxslp) {
163 totalp->t_sw++;
164 }
165 if (lp->lwp_slptime >= maxslp)
166 return(0);
167 break;
168
169 case LSRUN:
170 if (p->p_flag & P_SWAPPEDOUT)
171 totalp->t_sw++;
172 else
173 totalp->t_rq++;
174 if (p->p_stat == SIDL)
175 return(0);
176 break;
177
178 default:
179 return (0);
8fa76237 180 }
8fa76237
MD
181 }
182 /*
183 * Note active objects.
184 */
185 paging = 0;
75210f59
MD
186 if (p->p_vmspace) {
187 for (map = &p->p_vmspace->vm_map, entry = map->header.next;
188 entry != &map->header; entry = entry->next) {
189 if (entry->maptype != VM_MAPTYPE_NORMAL &&
190 entry->maptype != VM_MAPTYPE_VPAGETABLE) {
191 continue;
192 }
193 if (entry->object.vm_object == NULL)
194 continue;
195 vm_object_set_flag(entry->object.vm_object, OBJ_ACTIVE);
196 paging |= entry->object.vm_object->paging_in_progress;
1b874851 197 }
8fa76237
MD
198 }
199 if (paging)
200 totalp->t_pw++;
201 return(0);
202}
203
204
6bdb32ed
MD
205static int
206do_vmstats(SYSCTL_HANDLER_ARGS)
207{
208 struct vmstats vms = vmstats;
209 return (sysctl_handle_opaque(oidp, &vms, sizeof(vms), req));
210}
211
212static int
213do_vmmeter(SYSCTL_HANDLER_ARGS)
214{
215 int boffset = offsetof(struct vmmeter, vmmeter_uint_begin);
216 int eoffset = offsetof(struct vmmeter, vmmeter_uint_end);
217 struct vmmeter vmm;
218 int i;
219
220 bzero(&vmm, sizeof(vmm));
221 for (i = 0; i < ncpus; ++i) {
222 int off;
223 struct globaldata *gd = globaldata_find(i);
224
225 for (off = boffset; off <= eoffset; off += sizeof(u_int)) {
226 *(u_int *)((char *)&vmm + off) +=
227 *(u_int *)((char *)&gd->gd_cnt + off);
228 }
229
230 }
b785701b 231 vmm.v_intr += vmm.v_ipi + vmm.v_timer;
6bdb32ed
MD
232 return (sysctl_handle_opaque(oidp, &vmm, sizeof(vmm), req));
233}
234
12e4aaff
MD
235/*
236 * vcnt() - accumulate statistics from the cnt structure for each cpu
237 *
238 * The vmmeter structure is now per-cpu as well as global. Those
239 * statistics which can be kept on a per-cpu basis (to avoid cache
240 * stalls between cpus) can be moved to the per-cpu vmmeter. Remaining
241 * statistics, such as v_free_reserved, are left in the global
242 * structure.
243 *
244 * (sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req)
245 */
246static int
247vcnt(SYSCTL_HANDLER_ARGS)
248{
249 int i;
250 int count = 0;
6bdb32ed 251 int offset = arg2;
12e4aaff
MD
252
253 for (i = 0; i < ncpus; ++i) {
254 struct globaldata *gd = globaldata_find(i);
255 count += *(int *)((char *)&gd->gd_cnt + offset);
256 }
257 return(SYSCTL_OUT(req, &count, sizeof(int)));
258}
259
b785701b
SZ
260static int
261vcnt_intr(SYSCTL_HANDLER_ARGS)
262{
263 int i;
264 int count = 0;
265
266 for (i = 0; i < ncpus; ++i) {
267 struct globaldata *gd = globaldata_find(i);
268
269 count += gd->gd_cnt.v_intr + gd->gd_cnt.v_ipi +
270 gd->gd_cnt.v_timer;
271 }
272 return(SYSCTL_OUT(req, &count, sizeof(int)));
273}
274
6bdb32ed 275#define VMMETEROFF(var) offsetof(struct vmmeter, var)
12e4aaff 276
6bdb32ed
MD
277SYSCTL_PROC(_vm, OID_AUTO, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD,
278 0, sizeof(struct vmtotal), do_vmtotal, "S,vmtotal",
279 "System virtual memory aggregate");
280SYSCTL_PROC(_vm, OID_AUTO, vmstats, CTLTYPE_OPAQUE|CTLFLAG_RD,
281 0, sizeof(struct vmstats), do_vmstats, "S,vmstats",
984263bc 282 "System virtual memory statistics");
6bdb32ed
MD
283SYSCTL_PROC(_vm, OID_AUTO, vmmeter, CTLTYPE_OPAQUE|CTLFLAG_RD,
284 0, sizeof(struct vmmeter), do_vmmeter, "S,vmmeter",
b785701b 285 "System statistics");
984263bc
MD
286SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
287SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0, "VM meter sys stats");
288SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0, "VM meter vm stats");
289SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats");
12e4aaff
MD
290
291SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_swtch, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed
MD
292 0, VMMETEROFF(v_swtch), vcnt, "IU", "Context switches");
293SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intrans_coll, CTLTYPE_UINT|CTLFLAG_RD,
294 0, VMMETEROFF(v_intrans_coll), vcnt, "IU", "");
295SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intrans_wait, CTLTYPE_UINT|CTLFLAG_RD,
296 0, VMMETEROFF(v_intrans_wait), vcnt, "IU", "");
545a1cd3
MD
297SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_ints, CTLTYPE_UINT|CTLFLAG_RD,
298 0, VMMETEROFF(v_forwarded_ints), vcnt, "IU", "");
299SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_hits, CTLTYPE_UINT|CTLFLAG_RD,
300 0, VMMETEROFF(v_forwarded_hits), vcnt, "IU", "");
301SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_misses, CTLTYPE_UINT|CTLFLAG_RD,
302 0, VMMETEROFF(v_forwarded_misses), vcnt, "IU", "");
12e4aaff 303SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_trap, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 304 0, VMMETEROFF(v_trap), vcnt, "IU", "Traps");
12e4aaff 305SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_syscall, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 306 0, VMMETEROFF(v_syscall), vcnt, "IU", "Syscalls");
12e4aaff 307SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intr, CTLTYPE_UINT|CTLFLAG_RD,
b785701b
SZ
308 0, VMMETEROFF(v_intr), vcnt_intr, "IU", "Hardware interrupts");
309SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_ipi, CTLTYPE_UINT|CTLFLAG_RD,
310 0, VMMETEROFF(v_ipi), vcnt, "IU", "Inter-processor interrupts");
311SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_timer, CTLTYPE_UINT|CTLFLAG_RD,
312 0, VMMETEROFF(v_timer), vcnt, "IU", "LAPIC timer interrupts");
12e4aaff 313SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_soft, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 314 0, VMMETEROFF(v_soft), vcnt, "IU", "Software interrupts");
12e4aaff 315SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vm_faults, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 316 0, VMMETEROFF(v_vm_faults), vcnt, "IU", "VM faults");
12e4aaff 317SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_cow_faults, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 318 0, VMMETEROFF(v_cow_faults), vcnt, "IU", "COW faults");
12e4aaff 319SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_cow_optim, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 320 0, VMMETEROFF(v_cow_optim), vcnt, "IU", "Optimized COW faults");
12e4aaff 321SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_zfod, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 322 0, VMMETEROFF(v_zfod), vcnt, "IU", "Zero fill");
12e4aaff 323SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_ozfod, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 324 0, VMMETEROFF(v_ozfod), vcnt, "IU", "Optimized zero fill");
12e4aaff 325SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swapin, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 326 0, VMMETEROFF(v_swapin), vcnt, "IU", "Swapin operations");
12e4aaff 327SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swapout, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 328 0, VMMETEROFF(v_swapout), vcnt, "IU", "Swapout operations");
12e4aaff 329SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swappgsin, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 330 0, VMMETEROFF(v_swappgsin), vcnt, "IU", "Swapin pages");
12e4aaff 331SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swappgsout, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 332 0, VMMETEROFF(v_swappgsout), vcnt, "IU", "Swapout pages");
12e4aaff 333SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodein, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 334 0, VMMETEROFF(v_vnodein), vcnt, "IU", "Vnodein operations");
12e4aaff 335SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodeout, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 336 0, VMMETEROFF(v_vnodeout), vcnt, "IU", "Vnodeout operations");
12e4aaff 337SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodepgsin, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 338 0, VMMETEROFF(v_vnodepgsin), vcnt, "IU", "Vnodein pages");
12e4aaff 339SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodepgsout, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 340 0, VMMETEROFF(v_vnodepgsout), vcnt, "IU", "Vnodeout pages");
12e4aaff 341SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_intrans, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 342 0, VMMETEROFF(v_intrans), vcnt, "IU", "In transit page blocking");
12e4aaff 343SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_reactivated, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 344 0, VMMETEROFF(v_reactivated), vcnt, "IU", "Reactivated pages");
12e4aaff 345SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdwakeups, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 346 0, VMMETEROFF(v_pdwakeups), vcnt, "IU", "Pagedaemon wakeups");
12e4aaff 347SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdpages, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 348 0, VMMETEROFF(v_pdpages), vcnt, "IU", "Pagedaemon page scans");
12e4aaff 349SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_dfree, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 350 0, VMMETEROFF(v_dfree), vcnt, "IU", "");
12e4aaff 351SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pfree, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 352 0, VMMETEROFF(v_pfree), vcnt, "IU", "");
12e4aaff 353SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_tfree, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 354 0, VMMETEROFF(v_tfree), vcnt, "IU", "");
12e4aaff 355SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_forks, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 356 0, VMMETEROFF(v_forks), vcnt, "IU", "Number of fork() calls");
12e4aaff 357SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vforks, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 358 0, VMMETEROFF(v_vforks), vcnt, "IU", "Number of vfork() calls");
12e4aaff 359SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_rforks, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 360 0, VMMETEROFF(v_rforks), vcnt, "IU", "Number of rfork() calls");
12e4aaff 361SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_kthreads, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 362 0, VMMETEROFF(v_kthreads), vcnt, "IU", "Number of fork() calls by kernel");
12e4aaff 363SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_forkpages, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 364 0, VMMETEROFF(v_forkpages), vcnt, "IU", "VM pages affected by fork()");
12e4aaff 365SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vforkpages, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 366 0, VMMETEROFF(v_vforkpages), vcnt, "IU", "VM pages affected by vfork()");
12e4aaff 367SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_rforkpages, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 368 0, VMMETEROFF(v_rforkpages), vcnt, "IU", "VM pages affected by rfork()");
12e4aaff 369SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_kthreadpages, CTLTYPE_UINT|CTLFLAG_RD,
6bdb32ed 370 0, VMMETEROFF(v_kthreadpages), vcnt, "IU", "VM pages affected by fork() by kernel");
12e4aaff 371
984263bc 372SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 373 v_page_size, CTLFLAG_RD, &vmstats.v_page_size, 0, "");
984263bc 374SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 375 v_page_count, CTLFLAG_RD, &vmstats.v_page_count, 0, "");
984263bc 376SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 377 v_free_reserved, CTLFLAG_RD, &vmstats.v_free_reserved, 0, "");
984263bc 378SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 379 v_free_target, CTLFLAG_RD, &vmstats.v_free_target, 0, "");
984263bc 380SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 381 v_free_min, CTLFLAG_RD, &vmstats.v_free_min, 0, "");
984263bc 382SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 383 v_free_count, CTLFLAG_RD, &vmstats.v_free_count, 0, "");
984263bc 384SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 385 v_wire_count, CTLFLAG_RD, &vmstats.v_wire_count, 0, "");
984263bc 386SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 387 v_active_count, CTLFLAG_RD, &vmstats.v_active_count, 0, "");
984263bc 388SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 389 v_inactive_target, CTLFLAG_RD, &vmstats.v_inactive_target, 0, "");
984263bc 390SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 391 v_inactive_count, CTLFLAG_RD, &vmstats.v_inactive_count, 0, "");
984263bc 392SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 393 v_cache_count, CTLFLAG_RD, &vmstats.v_cache_count, 0, "");
984263bc 394SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 395 v_cache_min, CTLFLAG_RD, &vmstats.v_cache_min, 0, "");
984263bc 396SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 397 v_cache_max, CTLFLAG_RD, &vmstats.v_cache_max, 0, "");
984263bc 398SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 399 v_pageout_free_min, CTLFLAG_RD, &vmstats.v_pageout_free_min, 0, "");
984263bc 400SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
12e4aaff 401 v_interrupt_free_min, CTLFLAG_RD, &vmstats.v_interrupt_free_min, 0, "");
984263bc
MD
402SYSCTL_INT(_vm_stats_misc, OID_AUTO,
403 zero_page_count, CTLFLAG_RD, &vm_page_zero_count, 0, "");
015ffe3f
SZ
404
405static int
406do_vmmeter_pcpu(SYSCTL_HANDLER_ARGS)
407{
408 int boffset = offsetof(struct vmmeter, vmmeter_uint_begin);
409 int eoffset = offsetof(struct vmmeter, vmmeter_uint_end);
410 struct globaldata *gd = arg1;
411 struct vmmeter vmm;
412 int off;
413
414 bzero(&vmm, sizeof(vmm));
415 for (off = boffset; off <= eoffset; off += sizeof(u_int)) {
416 *(u_int *)((char *)&vmm + off) +=
417 *(u_int *)((char *)&gd->gd_cnt + off);
418 }
419 vmm.v_intr += vmm.v_ipi + vmm.v_timer;
420 return (sysctl_handle_opaque(oidp, &vmm, sizeof(vmm), req));
421}
422
423static void
424vmmeter_init(void *dummy __unused)
425{
426 int i;
427
428 for (i = 0; i < ncpus; ++i) {
429 struct sysctl_ctx_list *ctx;
430 struct sysctl_oid *oid;
431 struct globaldata *gd;
432 char name[32];
433
434 ksnprintf(name, sizeof(name), "cpu%d", i);
435
436 ctx = kmalloc(sizeof(*ctx), M_TEMP, M_WAITOK);
12db4c33 437 sysctl_ctx_init(ctx);
015ffe3f
SZ
438 oid = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_vm),
439 OID_AUTO, name, CTLFLAG_RD, 0, "");
440
441 gd = globaldata_find(i);
442 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
443 "vmmeter", CTLTYPE_OPAQUE|CTLFLAG_RD,
444 gd, sizeof(struct vmmeter), do_vmmeter_pcpu,
445 "S,vmmeter", "System per-cpu statistics");
446 }
447}
448SYSINIT(vmmeter, SI_SUB_PSEUDO, SI_ORDER_ANY, vmmeter_init, 0);