DRM from FreeBSD current, tested for r600
[dragonfly.git] / sys / vm / vm_meter.c
blob4e87866bb8546f4a57a5a7655d739801e2ce72f2
1 /*
2 * (MPSAFE)
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 * @(#)vm_meter.c 8.4 (Berkeley) 1/4/94
36 * $FreeBSD: src/sys/vm/vm_meter.c,v 1.34.2.7 2002/10/10 19:28:22 dillon Exp $
37 * $DragonFly: src/sys/vm/vm_meter.c,v 1.15 2008/04/28 18:04:08 dillon Exp $
40 #include <sys/param.h>
41 #include <sys/proc.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/resource.h>
45 #include <sys/vmmeter.h>
47 #include <vm/vm.h>
48 #include <vm/vm_page.h>
49 #include <vm/vm_extern.h>
50 #include <vm/vm_param.h>
51 #include <sys/lock.h>
52 #include <vm/pmap.h>
53 #include <vm/vm_map.h>
54 #include <vm/vm_object.h>
55 #include <sys/sysctl.h>
57 struct vmstats vmstats;
59 static int maxslp = MAXSLP;
61 SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min,
62 CTLFLAG_RW, &vmstats.v_free_min, 0,
63 "Minimum number of pages desired free");
64 SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target,
65 CTLFLAG_RW, &vmstats.v_free_target, 0,
66 "Number of pages desired free");
67 SYSCTL_UINT(_vm, VM_V_FREE_RESERVED, v_free_reserved,
68 CTLFLAG_RW, &vmstats.v_free_reserved, 0,
69 "Number of pages reserved for deadlock");
70 SYSCTL_UINT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target,
71 CTLFLAG_RW, &vmstats.v_inactive_target, 0,
72 "Number of pages desired inactive");
73 SYSCTL_UINT(_vm, VM_V_CACHE_MIN, v_cache_min,
74 CTLFLAG_RW, &vmstats.v_cache_min, 0,
75 "Min number of pages desired on cache queue");
76 SYSCTL_UINT(_vm, VM_V_CACHE_MAX, v_cache_max,
77 CTLFLAG_RW, &vmstats.v_cache_max, 0,
78 "Max number of pages in cached obj");
79 SYSCTL_UINT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min,
80 CTLFLAG_RW, &vmstats.v_pageout_free_min, 0,
81 "Min number pages reserved for kernel");
82 SYSCTL_UINT(_vm, OID_AUTO, v_free_severe,
83 CTLFLAG_RW, &vmstats.v_free_severe, 0, "");
85 SYSCTL_STRUCT(_vm, VM_LOADAVG, loadavg, CTLFLAG_RD,
86 &averunnable, loadavg, "Machine loadaverage history");
88 static int do_vmtotal_callback(struct proc *p, void *data);
91 * No requirements.
93 static int
94 do_vmtotal(SYSCTL_HANDLER_ARGS)
96 struct vmtotal total;
97 struct vmtotal *totalp;
98 vm_object_t object;
100 bzero(&total, sizeof(total));
101 totalp = &total;
104 * Mark all objects as inactive.
106 lwkt_gettoken(&vmobj_token);
107 for (object = TAILQ_FIRST(&vm_object_list);
108 object != NULL;
109 object = TAILQ_NEXT(object,object_list)) {
110 if (object->type == OBJT_MARKER)
111 continue;
112 vm_object_clear_flag(object, OBJ_ACTIVE);
114 lwkt_reltoken(&vmobj_token);
117 * Calculate process statistics.
119 allproc_scan(do_vmtotal_callback, totalp);
122 * Calculate object memory usage statistics.
124 lwkt_gettoken(&vmobj_token);
125 for (object = TAILQ_FIRST(&vm_object_list);
126 object != NULL;
127 object = TAILQ_NEXT(object, object_list)) {
129 * devices, like /dev/mem, will badly skew our totals.
130 * markers aren't real objects.
132 if (object->type == OBJT_MARKER)
133 continue;
134 if (object->type == OBJT_DEVICE)
135 continue;
136 if (object->size >= 0x7FFFFFFF) {
138 * Probably unbounded anonymous memory (really
139 * bounded by related vm_map_entry structures which
140 * we do not have access to in this loop).
142 totalp->t_vm += object->resident_page_count;
143 } else {
145 * It's questionable how useful this is but...
147 totalp->t_vm += object->size;
149 totalp->t_rm += object->resident_page_count;
150 if (object->flags & OBJ_ACTIVE) {
151 totalp->t_avm += object->size;
152 totalp->t_arm += object->resident_page_count;
154 if (object->shadow_count > 1) {
155 /* shared object */
156 totalp->t_vmshr += object->size;
157 totalp->t_rmshr += object->resident_page_count;
158 if (object->flags & OBJ_ACTIVE) {
159 totalp->t_avmshr += object->size;
160 totalp->t_armshr += object->resident_page_count;
164 lwkt_reltoken(&vmobj_token);
165 totalp->t_free = vmstats.v_free_count + vmstats.v_cache_count;
167 return (sysctl_handle_opaque(oidp, totalp, sizeof total, req));
171 * The caller must hold proc_token.
173 static int
174 do_vmtotal_callback(struct proc *p, void *data)
176 struct vmtotal *totalp = data;
177 struct lwp *lp;
178 vm_map_entry_t entry;
179 vm_map_t map;
180 int paging;
182 if (p->p_flag & P_SYSTEM)
183 return(0);
185 FOREACH_LWP_IN_PROC(lp, p) {
186 switch (lp->lwp_stat) {
187 case LSSTOP:
188 case LSSLEEP:
189 if ((p->p_flag & P_SWAPPEDOUT) == 0) {
190 if ((lp->lwp_flag & LWP_SINTR) == 0)
191 totalp->t_dw++;
192 else if (lp->lwp_slptime < maxslp)
193 totalp->t_sl++;
194 } else if (lp->lwp_slptime < maxslp) {
195 totalp->t_sw++;
197 if (lp->lwp_slptime >= maxslp)
198 return(0);
199 break;
201 case LSRUN:
202 if (p->p_flag & P_SWAPPEDOUT)
203 totalp->t_sw++;
204 else
205 totalp->t_rq++;
206 if (p->p_stat == SIDL)
207 return(0);
208 break;
210 default:
211 return (0);
216 * Note active objects.
218 paging = 0;
219 lwkt_gettoken(&p->p_token);
220 if (p->p_vmspace) {
221 map = &p->p_vmspace->vm_map;
222 vm_map_lock_read(map);
223 for (entry = map->header.next;
224 entry != &map->header; entry = entry->next) {
225 if (entry->maptype != VM_MAPTYPE_NORMAL &&
226 entry->maptype != VM_MAPTYPE_VPAGETABLE) {
227 continue;
229 if (entry->object.vm_object == NULL)
230 continue;
231 vm_object_set_flag(entry->object.vm_object, OBJ_ACTIVE);
232 paging |= entry->object.vm_object->paging_in_progress;
234 vm_map_unlock_read(map);
236 lwkt_reltoken(&p->p_token);
237 if (paging)
238 totalp->t_pw++;
239 return(0);
243 * No requirements.
245 static int
246 do_vmstats(SYSCTL_HANDLER_ARGS)
248 struct vmstats vms = vmstats;
249 return (sysctl_handle_opaque(oidp, &vms, sizeof(vms), req));
253 * No requirements.
255 static int
256 do_vmmeter(SYSCTL_HANDLER_ARGS)
258 int boffset = offsetof(struct vmmeter, vmmeter_uint_begin);
259 int eoffset = offsetof(struct vmmeter, vmmeter_uint_end);
260 struct vmmeter vmm;
261 int i;
263 bzero(&vmm, sizeof(vmm));
264 for (i = 0; i < ncpus; ++i) {
265 int off;
266 struct globaldata *gd = globaldata_find(i);
268 for (off = boffset; off <= eoffset; off += sizeof(u_int)) {
269 *(u_int *)((char *)&vmm + off) +=
270 *(u_int *)((char *)&gd->gd_cnt + off);
274 vmm.v_intr += vmm.v_ipi + vmm.v_timer;
275 return (sysctl_handle_opaque(oidp, &vmm, sizeof(vmm), req));
279 * vcnt() - accumulate statistics from the cnt structure for each cpu
281 * The vmmeter structure is now per-cpu as well as global. Those
282 * statistics which can be kept on a per-cpu basis (to avoid cache
283 * stalls between cpus) can be moved to the per-cpu vmmeter. Remaining
284 * statistics, such as v_free_reserved, are left in the global
285 * structure.
287 * (sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req)
289 * No requirements.
291 static int
292 vcnt(SYSCTL_HANDLER_ARGS)
294 int i;
295 int count = 0;
296 int offset = arg2;
298 for (i = 0; i < ncpus; ++i) {
299 struct globaldata *gd = globaldata_find(i);
300 count += *(int *)((char *)&gd->gd_cnt + offset);
302 return(SYSCTL_OUT(req, &count, sizeof(int)));
306 * No requirements.
308 static int
309 vcnt_intr(SYSCTL_HANDLER_ARGS)
311 int i;
312 int count = 0;
314 for (i = 0; i < ncpus; ++i) {
315 struct globaldata *gd = globaldata_find(i);
317 count += gd->gd_cnt.v_intr + gd->gd_cnt.v_ipi +
318 gd->gd_cnt.v_timer;
320 return(SYSCTL_OUT(req, &count, sizeof(int)));
323 #define VMMETEROFF(var) offsetof(struct vmmeter, var)
325 SYSCTL_PROC(_vm, OID_AUTO, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD,
326 0, sizeof(struct vmtotal), do_vmtotal, "S,vmtotal",
327 "System virtual memory aggregate");
328 SYSCTL_PROC(_vm, OID_AUTO, vmstats, CTLTYPE_OPAQUE|CTLFLAG_RD,
329 0, sizeof(struct vmstats), do_vmstats, "S,vmstats",
330 "System virtual memory statistics");
331 SYSCTL_PROC(_vm, OID_AUTO, vmmeter, CTLTYPE_OPAQUE|CTLFLAG_RD,
332 0, sizeof(struct vmmeter), do_vmmeter, "S,vmmeter",
333 "System statistics");
334 SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
335 SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0, "VM meter sys stats");
336 SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0, "VM meter vm stats");
337 SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats");
339 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_swtch, CTLTYPE_UINT|CTLFLAG_RD,
340 0, VMMETEROFF(v_swtch), vcnt, "IU", "Context switches");
341 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intrans_coll, CTLTYPE_UINT|CTLFLAG_RD,
342 0, VMMETEROFF(v_intrans_coll), vcnt, "IU", "Intransit map collisions (total)");
343 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intrans_wait, CTLTYPE_UINT|CTLFLAG_RD,
344 0, VMMETEROFF(v_intrans_wait), vcnt, "IU", "Intransit map collisions which blocked");
345 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_ints, CTLTYPE_UINT|CTLFLAG_RD,
346 0, VMMETEROFF(v_forwarded_ints), vcnt, "IU", "Forwarded interrupts due to MP lock");
347 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_hits, CTLTYPE_UINT|CTLFLAG_RD,
348 0, VMMETEROFF(v_forwarded_hits), vcnt, "IU", "Forwarded hits due to MP lock");
349 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_misses, CTLTYPE_UINT|CTLFLAG_RD,
350 0, VMMETEROFF(v_forwarded_misses), vcnt, "IU", "Forwarded misses due to MP lock");
351 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_trap, CTLTYPE_UINT|CTLFLAG_RD,
352 0, VMMETEROFF(v_trap), vcnt, "IU", "Traps");
353 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_syscall, CTLTYPE_UINT|CTLFLAG_RD,
354 0, VMMETEROFF(v_syscall), vcnt, "IU", "Syscalls");
355 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intr, CTLTYPE_UINT|CTLFLAG_RD,
356 0, VMMETEROFF(v_intr), vcnt_intr, "IU", "Hardware interrupts");
357 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_ipi, CTLTYPE_UINT|CTLFLAG_RD,
358 0, VMMETEROFF(v_ipi), vcnt, "IU", "Inter-processor interrupts");
359 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_timer, CTLTYPE_UINT|CTLFLAG_RD,
360 0, VMMETEROFF(v_timer), vcnt, "IU", "LAPIC timer interrupts");
361 SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_soft, CTLTYPE_UINT|CTLFLAG_RD,
362 0, VMMETEROFF(v_soft), vcnt, "IU", "Software interrupts");
363 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vm_faults, CTLTYPE_UINT|CTLFLAG_RD,
364 0, VMMETEROFF(v_vm_faults), vcnt, "IU", "VM faults");
365 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_cow_faults, CTLTYPE_UINT|CTLFLAG_RD,
366 0, VMMETEROFF(v_cow_faults), vcnt, "IU", "COW faults");
367 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_cow_optim, CTLTYPE_UINT|CTLFLAG_RD,
368 0, VMMETEROFF(v_cow_optim), vcnt, "IU", "Optimized COW faults");
369 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_zfod, CTLTYPE_UINT|CTLFLAG_RD,
370 0, VMMETEROFF(v_zfod), vcnt, "IU", "Zero fill");
371 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_ozfod, CTLTYPE_UINT|CTLFLAG_RD,
372 0, VMMETEROFF(v_ozfod), vcnt, "IU", "Optimized zero fill");
373 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swapin, CTLTYPE_UINT|CTLFLAG_RD,
374 0, VMMETEROFF(v_swapin), vcnt, "IU", "Swapin operations");
375 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swapout, CTLTYPE_UINT|CTLFLAG_RD,
376 0, VMMETEROFF(v_swapout), vcnt, "IU", "Swapout operations");
377 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swappgsin, CTLTYPE_UINT|CTLFLAG_RD,
378 0, VMMETEROFF(v_swappgsin), vcnt, "IU", "Swapin pages");
379 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swappgsout, CTLTYPE_UINT|CTLFLAG_RD,
380 0, VMMETEROFF(v_swappgsout), vcnt, "IU", "Swapout pages");
381 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodein, CTLTYPE_UINT|CTLFLAG_RD,
382 0, VMMETEROFF(v_vnodein), vcnt, "IU", "Vnodein operations");
383 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodeout, CTLTYPE_UINT|CTLFLAG_RD,
384 0, VMMETEROFF(v_vnodeout), vcnt, "IU", "Vnodeout operations");
385 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodepgsin, CTLTYPE_UINT|CTLFLAG_RD,
386 0, VMMETEROFF(v_vnodepgsin), vcnt, "IU", "Vnodein pages");
387 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodepgsout, CTLTYPE_UINT|CTLFLAG_RD,
388 0, VMMETEROFF(v_vnodepgsout), vcnt, "IU", "Vnodeout pages");
389 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_intrans, CTLTYPE_UINT|CTLFLAG_RD,
390 0, VMMETEROFF(v_intrans), vcnt, "IU", "In transit page blocking");
391 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_reactivated, CTLTYPE_UINT|CTLFLAG_RD,
392 0, VMMETEROFF(v_reactivated), vcnt, "IU", "Reactivated pages");
393 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdwakeups, CTLTYPE_UINT|CTLFLAG_RD,
394 0, VMMETEROFF(v_pdwakeups), vcnt, "IU", "Pagedaemon wakeups");
395 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_ppwakeups, CTLTYPE_UINT|CTLFLAG_RD,
396 0, VMMETEROFF(v_ppwakeups), vcnt, "IU", "vm_wait wakeups");
397 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdpages, CTLTYPE_UINT|CTLFLAG_RD,
398 0, VMMETEROFF(v_pdpages), vcnt, "IU", "Pagedaemon page scans");
399 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_dfree, CTLTYPE_UINT|CTLFLAG_RD,
400 0, VMMETEROFF(v_dfree), vcnt, "IU", "Pages freed by daemon");
401 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pfree, CTLTYPE_UINT|CTLFLAG_RD,
402 0, VMMETEROFF(v_pfree), vcnt, "IU", "Pages freed by exiting processes");
403 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_tfree, CTLTYPE_UINT|CTLFLAG_RD,
404 0, VMMETEROFF(v_tfree), vcnt, "IU", "Total pages freed");
405 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_forks, CTLTYPE_UINT|CTLFLAG_RD,
406 0, VMMETEROFF(v_forks), vcnt, "IU", "Number of fork() calls");
407 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vforks, CTLTYPE_UINT|CTLFLAG_RD,
408 0, VMMETEROFF(v_vforks), vcnt, "IU", "Number of vfork() calls");
409 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_rforks, CTLTYPE_UINT|CTLFLAG_RD,
410 0, VMMETEROFF(v_rforks), vcnt, "IU", "Number of rfork() calls");
411 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_kthreads, CTLTYPE_UINT|CTLFLAG_RD,
412 0, VMMETEROFF(v_kthreads), vcnt, "IU", "Number of fork() calls by kernel");
413 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_forkpages, CTLTYPE_UINT|CTLFLAG_RD,
414 0, VMMETEROFF(v_forkpages), vcnt, "IU", "VM pages affected by fork()");
415 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vforkpages, CTLTYPE_UINT|CTLFLAG_RD,
416 0, VMMETEROFF(v_vforkpages), vcnt, "IU", "VM pages affected by vfork()");
417 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_rforkpages, CTLTYPE_UINT|CTLFLAG_RD,
418 0, VMMETEROFF(v_rforkpages), vcnt, "IU", "VM pages affected by rfork()");
419 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_kthreadpages, CTLTYPE_UINT|CTLFLAG_RD,
420 0, VMMETEROFF(v_kthreadpages), vcnt, "IU", "VM pages affected by fork() by kernel");
422 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
423 v_page_size, CTLFLAG_RD, &vmstats.v_page_size, 0,
424 "Page size in bytes");
425 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
426 v_page_count, CTLFLAG_RD, &vmstats.v_page_count, 0,
427 "Total number of pages in system");
428 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
429 v_free_reserved, CTLFLAG_RD, &vmstats.v_free_reserved, 0,
430 "Number of pages reserved for deadlock");
431 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
432 v_free_target, CTLFLAG_RD, &vmstats.v_free_target, 0,
433 "Number of pages desired free");
434 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
435 v_free_min, CTLFLAG_RD, &vmstats.v_free_min, 0,
436 "Minimum number of pages desired free");
437 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
438 v_free_count, CTLFLAG_RD, &vmstats.v_free_count, 0,
439 "Number of pages free");
440 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
441 v_wire_count, CTLFLAG_RD, &vmstats.v_wire_count, 0,
442 "Number of pages wired down");
443 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
444 v_active_count, CTLFLAG_RD, &vmstats.v_active_count, 0,
445 "Number of pages active");
446 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
447 v_inactive_target, CTLFLAG_RD, &vmstats.v_inactive_target, 0,
448 "Number of pages desired inactive");
449 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
450 v_inactive_count, CTLFLAG_RD, &vmstats.v_inactive_count, 0,
451 "Number of pages inactive");
452 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
453 v_cache_count, CTLFLAG_RD, &vmstats.v_cache_count, 0,
454 "Number of pages on buffer cache queue");
455 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
456 v_cache_min, CTLFLAG_RD, &vmstats.v_cache_min, 0,
457 "Min number of pages desired on cache queue");
458 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
459 v_cache_max, CTLFLAG_RD, &vmstats.v_cache_max, 0,
460 "Max number of pages in cached obj");
461 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
462 v_pageout_free_min, CTLFLAG_RD, &vmstats.v_pageout_free_min, 0,
463 "Min number pages reserved for kernel");
464 SYSCTL_UINT(_vm_stats_vm, OID_AUTO,
465 v_interrupt_free_min, CTLFLAG_RD, &vmstats.v_interrupt_free_min, 0,
466 "Reserved number of pages for int code");
467 SYSCTL_INT(_vm_stats_misc, OID_AUTO,
468 zero_page_count, CTLFLAG_RD, &vm_page_zero_count, 0,
469 "Number of zeroing pages");
472 * No requirements.
474 static int
475 do_vmmeter_pcpu(SYSCTL_HANDLER_ARGS)
477 int boffset = offsetof(struct vmmeter, vmmeter_uint_begin);
478 int eoffset = offsetof(struct vmmeter, vmmeter_uint_end);
479 struct globaldata *gd = arg1;
480 struct vmmeter vmm;
481 int off;
483 bzero(&vmm, sizeof(vmm));
484 for (off = boffset; off <= eoffset; off += sizeof(u_int)) {
485 *(u_int *)((char *)&vmm + off) +=
486 *(u_int *)((char *)&gd->gd_cnt + off);
488 vmm.v_intr += vmm.v_ipi + vmm.v_timer;
489 return (sysctl_handle_opaque(oidp, &vmm, sizeof(vmm), req));
493 * Called from the low level boot code only.
495 static void
496 vmmeter_init(void *dummy __unused)
498 int i;
500 for (i = 0; i < ncpus; ++i) {
501 struct sysctl_ctx_list *ctx;
502 struct sysctl_oid *oid;
503 struct globaldata *gd;
504 char name[32];
506 ksnprintf(name, sizeof(name), "cpu%d", i);
508 ctx = kmalloc(sizeof(*ctx), M_TEMP, M_WAITOK);
509 sysctl_ctx_init(ctx);
510 oid = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_vm),
511 OID_AUTO, name, CTLFLAG_RD, 0, "");
513 gd = globaldata_find(i);
514 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
515 "vmmeter", CTLTYPE_OPAQUE|CTLFLAG_RD,
516 gd, sizeof(struct vmmeter), do_vmmeter_pcpu,
517 "S,vmmeter", "System per-cpu statistics");
520 SYSINIT(vmmeter, SI_SUB_PSEUDO, SI_ORDER_ANY, vmmeter_init, 0);