| 1 | /* |
| 2 | * (MPSAFE) |
| 3 | * |
| 4 | * Copyright (c) 1982, 1986, 1989, 1993 |
| 5 | * The Regents of the University of California. 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 | * 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. |
| 22 | * |
| 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. |
| 34 | * |
| 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 $ |
| 38 | */ |
| 39 | |
| 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> |
| 46 | |
| 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> |
| 56 | |
| 57 | struct vmstats vmstats; |
| 58 | |
| 59 | static int maxslp = MAXSLP; |
| 60 | |
| 61 | SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min, |
| 62 | CTLFLAG_RW, &vmstats.v_free_min, 0, ""); |
| 63 | SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target, |
| 64 | CTLFLAG_RW, &vmstats.v_free_target, 0, ""); |
| 65 | SYSCTL_UINT(_vm, VM_V_FREE_RESERVED, v_free_reserved, |
| 66 | CTLFLAG_RW, &vmstats.v_free_reserved, 0, ""); |
| 67 | SYSCTL_UINT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target, |
| 68 | CTLFLAG_RW, &vmstats.v_inactive_target, 0, ""); |
| 69 | SYSCTL_UINT(_vm, VM_V_CACHE_MIN, v_cache_min, |
| 70 | CTLFLAG_RW, &vmstats.v_cache_min, 0, ""); |
| 71 | SYSCTL_UINT(_vm, VM_V_CACHE_MAX, v_cache_max, |
| 72 | CTLFLAG_RW, &vmstats.v_cache_max, 0, ""); |
| 73 | SYSCTL_UINT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min, |
| 74 | CTLFLAG_RW, &vmstats.v_pageout_free_min, 0, ""); |
| 75 | SYSCTL_UINT(_vm, OID_AUTO, v_free_severe, |
| 76 | CTLFLAG_RW, &vmstats.v_free_severe, 0, ""); |
| 77 | |
| 78 | SYSCTL_STRUCT(_vm, VM_LOADAVG, loadavg, CTLFLAG_RD, |
| 79 | &averunnable, loadavg, "Machine loadaverage history"); |
| 80 | |
| 81 | static int do_vmtotal_callback(struct proc *p, void *data); |
| 82 | |
| 83 | /* |
| 84 | * No requirements. |
| 85 | */ |
| 86 | static int |
| 87 | do_vmtotal(SYSCTL_HANDLER_ARGS) |
| 88 | { |
| 89 | struct vmtotal total; |
| 90 | struct vmtotal *totalp; |
| 91 | vm_object_t object; |
| 92 | |
| 93 | bzero(&total, sizeof(total)); |
| 94 | totalp = &total; |
| 95 | |
| 96 | /* |
| 97 | * Mark all objects as inactive. |
| 98 | */ |
| 99 | lwkt_gettoken(&vmobj_token); |
| 100 | for (object = TAILQ_FIRST(&vm_object_list); |
| 101 | object != NULL; |
| 102 | object = TAILQ_NEXT(object,object_list)) { |
| 103 | if (object->type == OBJT_MARKER) |
| 104 | continue; |
| 105 | vm_object_clear_flag(object, OBJ_ACTIVE); |
| 106 | } |
| 107 | lwkt_reltoken(&vmobj_token); |
| 108 | |
| 109 | /* |
| 110 | * Calculate process statistics. |
| 111 | */ |
| 112 | allproc_scan(do_vmtotal_callback, totalp); |
| 113 | |
| 114 | /* |
| 115 | * Calculate object memory usage statistics. |
| 116 | */ |
| 117 | lwkt_gettoken(&vmobj_token); |
| 118 | for (object = TAILQ_FIRST(&vm_object_list); |
| 119 | object != NULL; |
| 120 | object = TAILQ_NEXT(object, object_list)) { |
| 121 | /* |
| 122 | * devices, like /dev/mem, will badly skew our totals. |
| 123 | * markers aren't real objects. |
| 124 | */ |
| 125 | if (object->type == OBJT_MARKER) |
| 126 | continue; |
| 127 | if (object->type == OBJT_DEVICE) |
| 128 | continue; |
| 129 | if (object->size >= 0x7FFFFFFF) { |
| 130 | /* |
| 131 | * Probably unbounded anonymous memory (really |
| 132 | * bounded by related vm_map_entry structures which |
| 133 | * we do not have access to in this loop). |
| 134 | */ |
| 135 | totalp->t_vm += object->resident_page_count; |
| 136 | } else { |
| 137 | /* |
| 138 | * It's questionable how useful this is but... |
| 139 | */ |
| 140 | totalp->t_vm += object->size; |
| 141 | } |
| 142 | totalp->t_rm += object->resident_page_count; |
| 143 | if (object->flags & OBJ_ACTIVE) { |
| 144 | totalp->t_avm += object->size; |
| 145 | totalp->t_arm += object->resident_page_count; |
| 146 | } |
| 147 | if (object->shadow_count > 1) { |
| 148 | /* shared object */ |
| 149 | totalp->t_vmshr += object->size; |
| 150 | totalp->t_rmshr += object->resident_page_count; |
| 151 | if (object->flags & OBJ_ACTIVE) { |
| 152 | totalp->t_avmshr += object->size; |
| 153 | totalp->t_armshr += object->resident_page_count; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | lwkt_reltoken(&vmobj_token); |
| 158 | totalp->t_free = vmstats.v_free_count + vmstats.v_cache_count; |
| 159 | |
| 160 | return (sysctl_handle_opaque(oidp, totalp, sizeof total, req)); |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * The caller must hold proc_token. |
| 165 | */ |
| 166 | static int |
| 167 | do_vmtotal_callback(struct proc *p, void *data) |
| 168 | { |
| 169 | struct vmtotal *totalp = data; |
| 170 | struct lwp *lp; |
| 171 | vm_map_entry_t entry; |
| 172 | vm_map_t map; |
| 173 | int paging; |
| 174 | |
| 175 | if (p->p_flag & P_SYSTEM) |
| 176 | return(0); |
| 177 | |
| 178 | FOREACH_LWP_IN_PROC(lp, p) { |
| 179 | switch (lp->lwp_stat) { |
| 180 | case LSSTOP: |
| 181 | case LSSLEEP: |
| 182 | if ((p->p_flag & P_SWAPPEDOUT) == 0) { |
| 183 | if ((lp->lwp_flag & LWP_SINTR) == 0) |
| 184 | totalp->t_dw++; |
| 185 | else if (lp->lwp_slptime < maxslp) |
| 186 | totalp->t_sl++; |
| 187 | } else if (lp->lwp_slptime < maxslp) { |
| 188 | totalp->t_sw++; |
| 189 | } |
| 190 | if (lp->lwp_slptime >= maxslp) |
| 191 | return(0); |
| 192 | break; |
| 193 | |
| 194 | case LSRUN: |
| 195 | if (p->p_flag & P_SWAPPEDOUT) |
| 196 | totalp->t_sw++; |
| 197 | else |
| 198 | totalp->t_rq++; |
| 199 | if (p->p_stat == SIDL) |
| 200 | return(0); |
| 201 | break; |
| 202 | |
| 203 | default: |
| 204 | return (0); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Note active objects. |
| 210 | */ |
| 211 | paging = 0; |
| 212 | lwkt_gettoken(&vm_token); |
| 213 | if (p->p_vmspace) { |
| 214 | map = &p->p_vmspace->vm_map; |
| 215 | vm_map_lock_read(map); |
| 216 | for (entry = map->header.next; |
| 217 | entry != &map->header; entry = entry->next) { |
| 218 | if (entry->maptype != VM_MAPTYPE_NORMAL && |
| 219 | entry->maptype != VM_MAPTYPE_VPAGETABLE) { |
| 220 | continue; |
| 221 | } |
| 222 | if (entry->object.vm_object == NULL) |
| 223 | continue; |
| 224 | vm_object_set_flag(entry->object.vm_object, OBJ_ACTIVE); |
| 225 | paging |= entry->object.vm_object->paging_in_progress; |
| 226 | } |
| 227 | vm_map_unlock_read(map); |
| 228 | } |
| 229 | lwkt_reltoken(&vm_token); |
| 230 | if (paging) |
| 231 | totalp->t_pw++; |
| 232 | return(0); |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * No requirements. |
| 237 | */ |
| 238 | static int |
| 239 | do_vmstats(SYSCTL_HANDLER_ARGS) |
| 240 | { |
| 241 | struct vmstats vms = vmstats; |
| 242 | return (sysctl_handle_opaque(oidp, &vms, sizeof(vms), req)); |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * No requirements. |
| 247 | */ |
| 248 | static int |
| 249 | do_vmmeter(SYSCTL_HANDLER_ARGS) |
| 250 | { |
| 251 | int boffset = offsetof(struct vmmeter, vmmeter_uint_begin); |
| 252 | int eoffset = offsetof(struct vmmeter, vmmeter_uint_end); |
| 253 | struct vmmeter vmm; |
| 254 | int i; |
| 255 | |
| 256 | bzero(&vmm, sizeof(vmm)); |
| 257 | for (i = 0; i < ncpus; ++i) { |
| 258 | int off; |
| 259 | struct globaldata *gd = globaldata_find(i); |
| 260 | |
| 261 | for (off = boffset; off <= eoffset; off += sizeof(u_int)) { |
| 262 | *(u_int *)((char *)&vmm + off) += |
| 263 | *(u_int *)((char *)&gd->gd_cnt + off); |
| 264 | } |
| 265 | |
| 266 | } |
| 267 | vmm.v_intr += vmm.v_ipi + vmm.v_timer; |
| 268 | return (sysctl_handle_opaque(oidp, &vmm, sizeof(vmm), req)); |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * vcnt() - accumulate statistics from the cnt structure for each cpu |
| 273 | * |
| 274 | * The vmmeter structure is now per-cpu as well as global. Those |
| 275 | * statistics which can be kept on a per-cpu basis (to avoid cache |
| 276 | * stalls between cpus) can be moved to the per-cpu vmmeter. Remaining |
| 277 | * statistics, such as v_free_reserved, are left in the global |
| 278 | * structure. |
| 279 | * |
| 280 | * (sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req) |
| 281 | * |
| 282 | * No requirements. |
| 283 | */ |
| 284 | static int |
| 285 | vcnt(SYSCTL_HANDLER_ARGS) |
| 286 | { |
| 287 | int i; |
| 288 | int count = 0; |
| 289 | int offset = arg2; |
| 290 | |
| 291 | for (i = 0; i < ncpus; ++i) { |
| 292 | struct globaldata *gd = globaldata_find(i); |
| 293 | count += *(int *)((char *)&gd->gd_cnt + offset); |
| 294 | } |
| 295 | return(SYSCTL_OUT(req, &count, sizeof(int))); |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * No requirements. |
| 300 | */ |
| 301 | static int |
| 302 | vcnt_intr(SYSCTL_HANDLER_ARGS) |
| 303 | { |
| 304 | int i; |
| 305 | int count = 0; |
| 306 | |
| 307 | for (i = 0; i < ncpus; ++i) { |
| 308 | struct globaldata *gd = globaldata_find(i); |
| 309 | |
| 310 | count += gd->gd_cnt.v_intr + gd->gd_cnt.v_ipi + |
| 311 | gd->gd_cnt.v_timer; |
| 312 | } |
| 313 | return(SYSCTL_OUT(req, &count, sizeof(int))); |
| 314 | } |
| 315 | |
| 316 | #define VMMETEROFF(var) offsetof(struct vmmeter, var) |
| 317 | |
| 318 | SYSCTL_PROC(_vm, OID_AUTO, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD, |
| 319 | 0, sizeof(struct vmtotal), do_vmtotal, "S,vmtotal", |
| 320 | "System virtual memory aggregate"); |
| 321 | SYSCTL_PROC(_vm, OID_AUTO, vmstats, CTLTYPE_OPAQUE|CTLFLAG_RD, |
| 322 | 0, sizeof(struct vmstats), do_vmstats, "S,vmstats", |
| 323 | "System virtual memory statistics"); |
| 324 | SYSCTL_PROC(_vm, OID_AUTO, vmmeter, CTLTYPE_OPAQUE|CTLFLAG_RD, |
| 325 | 0, sizeof(struct vmmeter), do_vmmeter, "S,vmmeter", |
| 326 | "System statistics"); |
| 327 | SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats"); |
| 328 | SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0, "VM meter sys stats"); |
| 329 | SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0, "VM meter vm stats"); |
| 330 | SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats"); |
| 331 | |
| 332 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_swtch, CTLTYPE_UINT|CTLFLAG_RD, |
| 333 | 0, VMMETEROFF(v_swtch), vcnt, "IU", "Context switches"); |
| 334 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intrans_coll, CTLTYPE_UINT|CTLFLAG_RD, |
| 335 | 0, VMMETEROFF(v_intrans_coll), vcnt, "IU", ""); |
| 336 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intrans_wait, CTLTYPE_UINT|CTLFLAG_RD, |
| 337 | 0, VMMETEROFF(v_intrans_wait), vcnt, "IU", ""); |
| 338 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_ints, CTLTYPE_UINT|CTLFLAG_RD, |
| 339 | 0, VMMETEROFF(v_forwarded_ints), vcnt, "IU", ""); |
| 340 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_hits, CTLTYPE_UINT|CTLFLAG_RD, |
| 341 | 0, VMMETEROFF(v_forwarded_hits), vcnt, "IU", ""); |
| 342 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_forwarded_misses, CTLTYPE_UINT|CTLFLAG_RD, |
| 343 | 0, VMMETEROFF(v_forwarded_misses), vcnt, "IU", ""); |
| 344 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_trap, CTLTYPE_UINT|CTLFLAG_RD, |
| 345 | 0, VMMETEROFF(v_trap), vcnt, "IU", "Traps"); |
| 346 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_syscall, CTLTYPE_UINT|CTLFLAG_RD, |
| 347 | 0, VMMETEROFF(v_syscall), vcnt, "IU", "Syscalls"); |
| 348 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_intr, CTLTYPE_UINT|CTLFLAG_RD, |
| 349 | 0, VMMETEROFF(v_intr), vcnt_intr, "IU", "Hardware interrupts"); |
| 350 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_ipi, CTLTYPE_UINT|CTLFLAG_RD, |
| 351 | 0, VMMETEROFF(v_ipi), vcnt, "IU", "Inter-processor interrupts"); |
| 352 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_timer, CTLTYPE_UINT|CTLFLAG_RD, |
| 353 | 0, VMMETEROFF(v_timer), vcnt, "IU", "LAPIC timer interrupts"); |
| 354 | SYSCTL_PROC(_vm_stats_sys, OID_AUTO, v_soft, CTLTYPE_UINT|CTLFLAG_RD, |
| 355 | 0, VMMETEROFF(v_soft), vcnt, "IU", "Software interrupts"); |
| 356 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vm_faults, CTLTYPE_UINT|CTLFLAG_RD, |
| 357 | 0, VMMETEROFF(v_vm_faults), vcnt, "IU", "VM faults"); |
| 358 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_cow_faults, CTLTYPE_UINT|CTLFLAG_RD, |
| 359 | 0, VMMETEROFF(v_cow_faults), vcnt, "IU", "COW faults"); |
| 360 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_cow_optim, CTLTYPE_UINT|CTLFLAG_RD, |
| 361 | 0, VMMETEROFF(v_cow_optim), vcnt, "IU", "Optimized COW faults"); |
| 362 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_zfod, CTLTYPE_UINT|CTLFLAG_RD, |
| 363 | 0, VMMETEROFF(v_zfod), vcnt, "IU", "Zero fill"); |
| 364 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_ozfod, CTLTYPE_UINT|CTLFLAG_RD, |
| 365 | 0, VMMETEROFF(v_ozfod), vcnt, "IU", "Optimized zero fill"); |
| 366 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swapin, CTLTYPE_UINT|CTLFLAG_RD, |
| 367 | 0, VMMETEROFF(v_swapin), vcnt, "IU", "Swapin operations"); |
| 368 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swapout, CTLTYPE_UINT|CTLFLAG_RD, |
| 369 | 0, VMMETEROFF(v_swapout), vcnt, "IU", "Swapout operations"); |
| 370 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swappgsin, CTLTYPE_UINT|CTLFLAG_RD, |
| 371 | 0, VMMETEROFF(v_swappgsin), vcnt, "IU", "Swapin pages"); |
| 372 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_swappgsout, CTLTYPE_UINT|CTLFLAG_RD, |
| 373 | 0, VMMETEROFF(v_swappgsout), vcnt, "IU", "Swapout pages"); |
| 374 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodein, CTLTYPE_UINT|CTLFLAG_RD, |
| 375 | 0, VMMETEROFF(v_vnodein), vcnt, "IU", "Vnodein operations"); |
| 376 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodeout, CTLTYPE_UINT|CTLFLAG_RD, |
| 377 | 0, VMMETEROFF(v_vnodeout), vcnt, "IU", "Vnodeout operations"); |
| 378 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodepgsin, CTLTYPE_UINT|CTLFLAG_RD, |
| 379 | 0, VMMETEROFF(v_vnodepgsin), vcnt, "IU", "Vnodein pages"); |
| 380 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vnodepgsout, CTLTYPE_UINT|CTLFLAG_RD, |
| 381 | 0, VMMETEROFF(v_vnodepgsout), vcnt, "IU", "Vnodeout pages"); |
| 382 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_intrans, CTLTYPE_UINT|CTLFLAG_RD, |
| 383 | 0, VMMETEROFF(v_intrans), vcnt, "IU", "In transit page blocking"); |
| 384 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_reactivated, CTLTYPE_UINT|CTLFLAG_RD, |
| 385 | 0, VMMETEROFF(v_reactivated), vcnt, "IU", "Reactivated pages"); |
| 386 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdwakeups, CTLTYPE_UINT|CTLFLAG_RD, |
| 387 | 0, VMMETEROFF(v_pdwakeups), vcnt, "IU", "Pagedaemon wakeups"); |
| 388 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdpages, CTLTYPE_UINT|CTLFLAG_RD, |
| 389 | 0, VMMETEROFF(v_pdpages), vcnt, "IU", "Pagedaemon page scans"); |
| 390 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_dfree, CTLTYPE_UINT|CTLFLAG_RD, |
| 391 | 0, VMMETEROFF(v_dfree), vcnt, "IU", ""); |
| 392 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pfree, CTLTYPE_UINT|CTLFLAG_RD, |
| 393 | 0, VMMETEROFF(v_pfree), vcnt, "IU", ""); |
| 394 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_tfree, CTLTYPE_UINT|CTLFLAG_RD, |
| 395 | 0, VMMETEROFF(v_tfree), vcnt, "IU", ""); |
| 396 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_forks, CTLTYPE_UINT|CTLFLAG_RD, |
| 397 | 0, VMMETEROFF(v_forks), vcnt, "IU", "Number of fork() calls"); |
| 398 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vforks, CTLTYPE_UINT|CTLFLAG_RD, |
| 399 | 0, VMMETEROFF(v_vforks), vcnt, "IU", "Number of vfork() calls"); |
| 400 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_rforks, CTLTYPE_UINT|CTLFLAG_RD, |
| 401 | 0, VMMETEROFF(v_rforks), vcnt, "IU", "Number of rfork() calls"); |
| 402 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_kthreads, CTLTYPE_UINT|CTLFLAG_RD, |
| 403 | 0, VMMETEROFF(v_kthreads), vcnt, "IU", "Number of fork() calls by kernel"); |
| 404 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_forkpages, CTLTYPE_UINT|CTLFLAG_RD, |
| 405 | 0, VMMETEROFF(v_forkpages), vcnt, "IU", "VM pages affected by fork()"); |
| 406 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_vforkpages, CTLTYPE_UINT|CTLFLAG_RD, |
| 407 | 0, VMMETEROFF(v_vforkpages), vcnt, "IU", "VM pages affected by vfork()"); |
| 408 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_rforkpages, CTLTYPE_UINT|CTLFLAG_RD, |
| 409 | 0, VMMETEROFF(v_rforkpages), vcnt, "IU", "VM pages affected by rfork()"); |
| 410 | SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_kthreadpages, CTLTYPE_UINT|CTLFLAG_RD, |
| 411 | 0, VMMETEROFF(v_kthreadpages), vcnt, "IU", "VM pages affected by fork() by kernel"); |
| 412 | |
| 413 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 414 | v_page_size, CTLFLAG_RD, &vmstats.v_page_size, 0, ""); |
| 415 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 416 | v_page_count, CTLFLAG_RD, &vmstats.v_page_count, 0, ""); |
| 417 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 418 | v_free_reserved, CTLFLAG_RD, &vmstats.v_free_reserved, 0, ""); |
| 419 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 420 | v_free_target, CTLFLAG_RD, &vmstats.v_free_target, 0, ""); |
| 421 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 422 | v_free_min, CTLFLAG_RD, &vmstats.v_free_min, 0, ""); |
| 423 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 424 | v_free_count, CTLFLAG_RD, &vmstats.v_free_count, 0, ""); |
| 425 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 426 | v_wire_count, CTLFLAG_RD, &vmstats.v_wire_count, 0, ""); |
| 427 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 428 | v_active_count, CTLFLAG_RD, &vmstats.v_active_count, 0, ""); |
| 429 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 430 | v_inactive_target, CTLFLAG_RD, &vmstats.v_inactive_target, 0, ""); |
| 431 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 432 | v_inactive_count, CTLFLAG_RD, &vmstats.v_inactive_count, 0, ""); |
| 433 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 434 | v_cache_count, CTLFLAG_RD, &vmstats.v_cache_count, 0, ""); |
| 435 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 436 | v_cache_min, CTLFLAG_RD, &vmstats.v_cache_min, 0, ""); |
| 437 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 438 | v_cache_max, CTLFLAG_RD, &vmstats.v_cache_max, 0, ""); |
| 439 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 440 | v_pageout_free_min, CTLFLAG_RD, &vmstats.v_pageout_free_min, 0, ""); |
| 441 | SYSCTL_UINT(_vm_stats_vm, OID_AUTO, |
| 442 | v_interrupt_free_min, CTLFLAG_RD, &vmstats.v_interrupt_free_min, 0, ""); |
| 443 | SYSCTL_INT(_vm_stats_misc, OID_AUTO, |
| 444 | zero_page_count, CTLFLAG_RD, &vm_page_zero_count, 0, ""); |
| 445 | |
| 446 | /* |
| 447 | * No requirements. |
| 448 | */ |
| 449 | static int |
| 450 | do_vmmeter_pcpu(SYSCTL_HANDLER_ARGS) |
| 451 | { |
| 452 | int boffset = offsetof(struct vmmeter, vmmeter_uint_begin); |
| 453 | int eoffset = offsetof(struct vmmeter, vmmeter_uint_end); |
| 454 | struct globaldata *gd = arg1; |
| 455 | struct vmmeter vmm; |
| 456 | int off; |
| 457 | |
| 458 | bzero(&vmm, sizeof(vmm)); |
| 459 | for (off = boffset; off <= eoffset; off += sizeof(u_int)) { |
| 460 | *(u_int *)((char *)&vmm + off) += |
| 461 | *(u_int *)((char *)&gd->gd_cnt + off); |
| 462 | } |
| 463 | vmm.v_intr += vmm.v_ipi + vmm.v_timer; |
| 464 | return (sysctl_handle_opaque(oidp, &vmm, sizeof(vmm), req)); |
| 465 | } |
| 466 | |
| 467 | /* |
| 468 | * Called from the low level boot code only. |
| 469 | */ |
| 470 | static void |
| 471 | vmmeter_init(void *dummy __unused) |
| 472 | { |
| 473 | int i; |
| 474 | |
| 475 | for (i = 0; i < ncpus; ++i) { |
| 476 | struct sysctl_ctx_list *ctx; |
| 477 | struct sysctl_oid *oid; |
| 478 | struct globaldata *gd; |
| 479 | char name[32]; |
| 480 | |
| 481 | ksnprintf(name, sizeof(name), "cpu%d", i); |
| 482 | |
| 483 | ctx = kmalloc(sizeof(*ctx), M_TEMP, M_WAITOK); |
| 484 | sysctl_ctx_init(ctx); |
| 485 | oid = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_vm), |
| 486 | OID_AUTO, name, CTLFLAG_RD, 0, ""); |
| 487 | |
| 488 | gd = globaldata_find(i); |
| 489 | SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, |
| 490 | "vmmeter", CTLTYPE_OPAQUE|CTLFLAG_RD, |
| 491 | gd, sizeof(struct vmmeter), do_vmmeter_pcpu, |
| 492 | "S,vmmeter", "System per-cpu statistics"); |
| 493 | } |
| 494 | } |
| 495 | SYSINIT(vmmeter, SI_SUB_PSEUDO, SI_ORDER_ANY, vmmeter_init, 0); |