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
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
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>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/resource.h>
45 #include <sys/vmmeter.h>
48 #include <vm/vm_page.h>
49 #include <vm/vm_extern.h>
50 #include <vm/vm_param.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
);
94 do_vmtotal(SYSCTL_HANDLER_ARGS
)
97 struct vmtotal
*totalp
;
100 bzero(&total
, sizeof(total
));
104 * Mark all objects as inactive.
106 lwkt_gettoken(&vmobj_token
);
107 for (object
= TAILQ_FIRST(&vm_object_list
);
109 object
= TAILQ_NEXT(object
,object_list
)) {
110 if (object
->type
== OBJT_MARKER
)
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
);
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
)
134 if (object
->type
== OBJT_DEVICE
)
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
;
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) {
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.
174 do_vmtotal_callback(struct proc
*p
, void *data
)
176 struct vmtotal
*totalp
= data
;
179 if (p
->p_flags
& P_SYSTEM
)
182 FOREACH_LWP_IN_PROC(lp
, p
) {
183 switch (lp
->lwp_stat
) {
186 if ((p
->p_flags
& P_SWAPPEDOUT
) == 0) {
187 if ((lp
->lwp_flags
& LWP_SINTR
) == 0)
189 else if (lp
->lwp_slptime
< maxslp
)
191 } else if (lp
->lwp_slptime
< maxslp
) {
194 if (lp
->lwp_slptime
>= maxslp
)
199 if (p
->p_flags
& P_SWAPPEDOUT
)
203 if (p
->p_stat
== SIDL
)
212 * Set while in vm_fault()
214 if (lp
->lwp_flags
& LWP_PAGING
)
224 do_vmstats(SYSCTL_HANDLER_ARGS
)
226 struct vmstats vms
= vmstats
;
227 return (sysctl_handle_opaque(oidp
, &vms
, sizeof(vms
), req
));
234 do_vmmeter(SYSCTL_HANDLER_ARGS
)
236 int boffset
= offsetof(struct vmmeter
, vmmeter_uint_begin
);
237 int eoffset
= offsetof(struct vmmeter
, vmmeter_uint_end
);
241 bzero(&vmm
, sizeof(vmm
));
242 for (i
= 0; i
< ncpus
; ++i
) {
244 struct globaldata
*gd
= globaldata_find(i
);
246 for (off
= boffset
; off
<= eoffset
; off
+= sizeof(u_int
)) {
247 *(u_int
*)((char *)&vmm
+ off
) +=
248 *(u_int
*)((char *)&gd
->gd_cnt
+ off
);
252 vmm
.v_intr
+= vmm
.v_ipi
+ vmm
.v_timer
;
253 return (sysctl_handle_opaque(oidp
, &vmm
, sizeof(vmm
), req
));
257 * vcnt() - accumulate statistics from the cnt structure for each cpu
259 * The vmmeter structure is now per-cpu as well as global. Those
260 * statistics which can be kept on a per-cpu basis (to avoid cache
261 * stalls between cpus) can be moved to the per-cpu vmmeter. Remaining
262 * statistics, such as v_free_reserved, are left in the global
265 * (sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req)
270 vcnt(SYSCTL_HANDLER_ARGS
)
276 for (i
= 0; i
< ncpus
; ++i
) {
277 struct globaldata
*gd
= globaldata_find(i
);
278 count
+= *(int *)((char *)&gd
->gd_cnt
+ offset
);
280 return(SYSCTL_OUT(req
, &count
, sizeof(int)));
287 vcnt_intr(SYSCTL_HANDLER_ARGS
)
292 for (i
= 0; i
< ncpus
; ++i
) {
293 struct globaldata
*gd
= globaldata_find(i
);
295 count
+= gd
->gd_cnt
.v_intr
+ gd
->gd_cnt
.v_ipi
+
298 return(SYSCTL_OUT(req
, &count
, sizeof(int)));
301 #define VMMETEROFF(var) offsetof(struct vmmeter, var)
303 SYSCTL_PROC(_vm
, OID_AUTO
, vmtotal
, CTLTYPE_OPAQUE
|CTLFLAG_RD
,
304 0, sizeof(struct vmtotal
), do_vmtotal
, "S,vmtotal",
305 "System virtual memory aggregate");
306 SYSCTL_PROC(_vm
, OID_AUTO
, vmstats
, CTLTYPE_OPAQUE
|CTLFLAG_RD
,
307 0, sizeof(struct vmstats
), do_vmstats
, "S,vmstats",
308 "System virtual memory statistics");
309 SYSCTL_PROC(_vm
, OID_AUTO
, vmmeter
, CTLTYPE_OPAQUE
|CTLFLAG_RD
,
310 0, sizeof(struct vmmeter
), do_vmmeter
, "S,vmmeter",
311 "System statistics");
312 SYSCTL_NODE(_vm
, OID_AUTO
, stats
, CTLFLAG_RW
, 0, "VM meter stats");
313 SYSCTL_NODE(_vm_stats
, OID_AUTO
, sys
, CTLFLAG_RW
, 0, "VM meter sys stats");
314 SYSCTL_NODE(_vm_stats
, OID_AUTO
, vm
, CTLFLAG_RW
, 0, "VM meter vm stats");
315 SYSCTL_NODE(_vm_stats
, OID_AUTO
, misc
, CTLFLAG_RW
, 0, "VM meter misc stats");
317 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_swtch
, CTLTYPE_UINT
|CTLFLAG_RD
,
318 0, VMMETEROFF(v_swtch
), vcnt
, "IU", "Context switches");
319 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_intrans_coll
, CTLTYPE_UINT
|CTLFLAG_RD
,
320 0, VMMETEROFF(v_intrans_coll
), vcnt
, "IU", "Intransit map collisions (total)");
321 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_intrans_wait
, CTLTYPE_UINT
|CTLFLAG_RD
,
322 0, VMMETEROFF(v_intrans_wait
), vcnt
, "IU", "Intransit map collisions which blocked");
323 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_forwarded_ints
, CTLTYPE_UINT
|CTLFLAG_RD
,
324 0, VMMETEROFF(v_forwarded_ints
), vcnt
, "IU", "Forwarded interrupts due to MP lock");
325 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_forwarded_hits
, CTLTYPE_UINT
|CTLFLAG_RD
,
326 0, VMMETEROFF(v_forwarded_hits
), vcnt
, "IU", "Forwarded hits due to MP lock");
327 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_forwarded_misses
, CTLTYPE_UINT
|CTLFLAG_RD
,
328 0, VMMETEROFF(v_forwarded_misses
), vcnt
, "IU", "Forwarded misses due to MP lock");
329 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_trap
, CTLTYPE_UINT
|CTLFLAG_RD
,
330 0, VMMETEROFF(v_trap
), vcnt
, "IU", "Traps");
331 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_syscall
, CTLTYPE_UINT
|CTLFLAG_RD
,
332 0, VMMETEROFF(v_syscall
), vcnt
, "IU", "Syscalls");
333 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_intr
, CTLTYPE_UINT
|CTLFLAG_RD
,
334 0, VMMETEROFF(v_intr
), vcnt_intr
, "IU", "Hardware interrupts");
335 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_ipi
, CTLTYPE_UINT
|CTLFLAG_RD
,
336 0, VMMETEROFF(v_ipi
), vcnt
, "IU", "Inter-processor interrupts");
337 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_timer
, CTLTYPE_UINT
|CTLFLAG_RD
,
338 0, VMMETEROFF(v_timer
), vcnt
, "IU", "LAPIC timer interrupts");
339 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_soft
, CTLTYPE_UINT
|CTLFLAG_RD
,
340 0, VMMETEROFF(v_soft
), vcnt
, "IU", "Software interrupts");
341 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vm_faults
, CTLTYPE_UINT
|CTLFLAG_RD
,
342 0, VMMETEROFF(v_vm_faults
), vcnt
, "IU", "VM faults");
343 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_cow_faults
, CTLTYPE_UINT
|CTLFLAG_RD
,
344 0, VMMETEROFF(v_cow_faults
), vcnt
, "IU", "COW faults");
345 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_cow_optim
, CTLTYPE_UINT
|CTLFLAG_RD
,
346 0, VMMETEROFF(v_cow_optim
), vcnt
, "IU", "Optimized COW faults");
347 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_zfod
, CTLTYPE_UINT
|CTLFLAG_RD
,
348 0, VMMETEROFF(v_zfod
), vcnt
, "IU", "Zero fill");
349 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_ozfod
, CTLTYPE_UINT
|CTLFLAG_RD
,
350 0, VMMETEROFF(v_ozfod
), vcnt
, "IU", "Optimized zero fill");
351 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swapin
, CTLTYPE_UINT
|CTLFLAG_RD
,
352 0, VMMETEROFF(v_swapin
), vcnt
, "IU", "Swapin operations");
353 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swapout
, CTLTYPE_UINT
|CTLFLAG_RD
,
354 0, VMMETEROFF(v_swapout
), vcnt
, "IU", "Swapout operations");
355 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swappgsin
, CTLTYPE_UINT
|CTLFLAG_RD
,
356 0, VMMETEROFF(v_swappgsin
), vcnt
, "IU", "Swapin pages");
357 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swappgsout
, CTLTYPE_UINT
|CTLFLAG_RD
,
358 0, VMMETEROFF(v_swappgsout
), vcnt
, "IU", "Swapout pages");
359 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodein
, CTLTYPE_UINT
|CTLFLAG_RD
,
360 0, VMMETEROFF(v_vnodein
), vcnt
, "IU", "Vnodein operations");
361 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodeout
, CTLTYPE_UINT
|CTLFLAG_RD
,
362 0, VMMETEROFF(v_vnodeout
), vcnt
, "IU", "Vnodeout operations");
363 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodepgsin
, CTLTYPE_UINT
|CTLFLAG_RD
,
364 0, VMMETEROFF(v_vnodepgsin
), vcnt
, "IU", "Vnodein pages");
365 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodepgsout
, CTLTYPE_UINT
|CTLFLAG_RD
,
366 0, VMMETEROFF(v_vnodepgsout
), vcnt
, "IU", "Vnodeout pages");
367 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_intrans
, CTLTYPE_UINT
|CTLFLAG_RD
,
368 0, VMMETEROFF(v_intrans
), vcnt
, "IU", "In transit page blocking");
369 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_reactivated
, CTLTYPE_UINT
|CTLFLAG_RD
,
370 0, VMMETEROFF(v_reactivated
), vcnt
, "IU", "Reactivated pages");
371 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_pdwakeups
, CTLTYPE_UINT
|CTLFLAG_RD
,
372 0, VMMETEROFF(v_pdwakeups
), vcnt
, "IU", "Pagedaemon wakeups");
373 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_ppwakeups
, CTLTYPE_UINT
|CTLFLAG_RD
,
374 0, VMMETEROFF(v_ppwakeups
), vcnt
, "IU", "vm_wait wakeups");
375 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_pdpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
376 0, VMMETEROFF(v_pdpages
), vcnt
, "IU", "Pagedaemon page scans");
377 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_dfree
, CTLTYPE_UINT
|CTLFLAG_RD
,
378 0, VMMETEROFF(v_dfree
), vcnt
, "IU", "Pages freed by daemon");
379 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_pfree
, CTLTYPE_UINT
|CTLFLAG_RD
,
380 0, VMMETEROFF(v_pfree
), vcnt
, "IU", "Pages freed by exiting processes");
381 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_tfree
, CTLTYPE_UINT
|CTLFLAG_RD
,
382 0, VMMETEROFF(v_tfree
), vcnt
, "IU", "Total pages freed");
383 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_forks
, CTLTYPE_UINT
|CTLFLAG_RD
,
384 0, VMMETEROFF(v_forks
), vcnt
, "IU", "Number of fork() calls");
385 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vforks
, CTLTYPE_UINT
|CTLFLAG_RD
,
386 0, VMMETEROFF(v_vforks
), vcnt
, "IU", "Number of vfork() calls");
387 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_rforks
, CTLTYPE_UINT
|CTLFLAG_RD
,
388 0, VMMETEROFF(v_rforks
), vcnt
, "IU", "Number of rfork() calls");
389 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_kthreads
, CTLTYPE_UINT
|CTLFLAG_RD
,
390 0, VMMETEROFF(v_kthreads
), vcnt
, "IU", "Number of fork() calls by kernel");
391 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_forkpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
392 0, VMMETEROFF(v_forkpages
), vcnt
, "IU", "VM pages affected by fork()");
393 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vforkpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
394 0, VMMETEROFF(v_vforkpages
), vcnt
, "IU", "VM pages affected by vfork()");
395 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_rforkpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
396 0, VMMETEROFF(v_rforkpages
), vcnt
, "IU", "VM pages affected by rfork()");
397 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_kthreadpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
398 0, VMMETEROFF(v_kthreadpages
), vcnt
, "IU", "VM pages affected by fork() by kernel");
400 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
401 v_page_size
, CTLFLAG_RD
, &vmstats
.v_page_size
, 0,
402 "Page size in bytes");
403 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
404 v_page_count
, CTLFLAG_RD
, &vmstats
.v_page_count
, 0,
405 "Total number of pages in system");
406 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
407 v_free_reserved
, CTLFLAG_RD
, &vmstats
.v_free_reserved
, 0,
408 "Number of pages reserved for deadlock");
409 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
410 v_free_target
, CTLFLAG_RD
, &vmstats
.v_free_target
, 0,
411 "Number of pages desired free");
412 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
413 v_free_min
, CTLFLAG_RD
, &vmstats
.v_free_min
, 0,
414 "Minimum number of pages desired free");
415 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
416 v_free_count
, CTLFLAG_RD
, &vmstats
.v_free_count
, 0,
417 "Number of pages free");
418 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
419 v_wire_count
, CTLFLAG_RD
, &vmstats
.v_wire_count
, 0,
420 "Number of pages wired down");
421 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
422 v_active_count
, CTLFLAG_RD
, &vmstats
.v_active_count
, 0,
423 "Number of pages active");
424 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
425 v_inactive_target
, CTLFLAG_RD
, &vmstats
.v_inactive_target
, 0,
426 "Number of pages desired inactive");
427 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
428 v_inactive_count
, CTLFLAG_RD
, &vmstats
.v_inactive_count
, 0,
429 "Number of pages inactive");
430 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
431 v_cache_count
, CTLFLAG_RD
, &vmstats
.v_cache_count
, 0,
432 "Number of pages on buffer cache queue");
433 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
434 v_cache_min
, CTLFLAG_RD
, &vmstats
.v_cache_min
, 0,
435 "Min number of pages desired on cache queue");
436 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
437 v_cache_max
, CTLFLAG_RD
, &vmstats
.v_cache_max
, 0,
438 "Max number of pages in cached obj");
439 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
440 v_pageout_free_min
, CTLFLAG_RD
, &vmstats
.v_pageout_free_min
, 0,
441 "Min number pages reserved for kernel");
442 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
443 v_interrupt_free_min
, CTLFLAG_RD
, &vmstats
.v_interrupt_free_min
, 0,
444 "Reserved number of pages for int code");
445 SYSCTL_INT(_vm_stats_misc
, OID_AUTO
,
446 zero_page_count
, CTLFLAG_RD
, &vm_page_zero_count
, 0,
447 "Number of zeroing pages");
453 do_vmmeter_pcpu(SYSCTL_HANDLER_ARGS
)
455 int boffset
= offsetof(struct vmmeter
, vmmeter_uint_begin
);
456 int eoffset
= offsetof(struct vmmeter
, vmmeter_uint_end
);
457 struct globaldata
*gd
= arg1
;
461 bzero(&vmm
, sizeof(vmm
));
462 for (off
= boffset
; off
<= eoffset
; off
+= sizeof(u_int
)) {
463 *(u_int
*)((char *)&vmm
+ off
) +=
464 *(u_int
*)((char *)&gd
->gd_cnt
+ off
);
466 vmm
.v_intr
+= vmm
.v_ipi
+ vmm
.v_timer
;
467 return (sysctl_handle_opaque(oidp
, &vmm
, sizeof(vmm
), req
));
471 * Called from the low level boot code only.
474 vmmeter_init(void *dummy __unused
)
478 for (i
= 0; i
< ncpus
; ++i
) {
479 struct sysctl_ctx_list
*ctx
;
480 struct sysctl_oid
*oid
;
481 struct globaldata
*gd
;
484 ksnprintf(name
, sizeof(name
), "cpu%d", i
);
486 ctx
= kmalloc(sizeof(*ctx
), M_TEMP
, M_WAITOK
);
487 sysctl_ctx_init(ctx
);
488 oid
= SYSCTL_ADD_NODE(ctx
, SYSCTL_STATIC_CHILDREN(_vm
),
489 OID_AUTO
, name
, CTLFLAG_RD
, 0, "");
491 gd
= globaldata_find(i
);
492 SYSCTL_ADD_PROC(ctx
, SYSCTL_CHILDREN(oid
), OID_AUTO
,
493 "vmmeter", CTLTYPE_OPAQUE
|CTLFLAG_RD
,
494 gd
, sizeof(struct vmmeter
), do_vmmeter_pcpu
,
495 "S,vmmeter", "System per-cpu statistics");
498 SYSINIT(vmmeter
, SI_SUB_PSEUDO
, SI_ORDER_ANY
, vmmeter_init
, 0);