xref: /freebsd/sys/vm/vm_meter.c (revision 401ab69cff8fa2320a9f8ea4baa114a6da6c952b)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
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. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)vm_meter.c	8.4 (Berkeley) 1/4/94
32  */
33 
34 #include <sys/cdefs.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/lock.h>
39 #include <sys/malloc.h>
40 #include <sys/mutex.h>
41 #include <sys/proc.h>
42 #include <sys/resource.h>
43 #include <sys/rwlock.h>
44 #include <sys/sx.h>
45 #include <sys/vmmeter.h>
46 #include <sys/smp.h>
47 
48 #include <vm/vm.h>
49 #include <vm/vm_page.h>
50 #include <vm/vm_extern.h>
51 #include <vm/vm_param.h>
52 #include <vm/vm_phys.h>
53 #include <vm/vm_pagequeue.h>
54 #include <vm/pmap.h>
55 #include <vm/vm_map.h>
56 #include <vm/vm_object.h>
57 #include <sys/sysctl.h>
58 
59 struct vmmeter __read_mostly vm_cnt = {
60 	.v_swtch = EARLY_COUNTER,
61 	.v_trap = EARLY_COUNTER,
62 	.v_syscall = EARLY_COUNTER,
63 	.v_intr = EARLY_COUNTER,
64 	.v_soft = EARLY_COUNTER,
65 	.v_vm_faults = EARLY_COUNTER,
66 	.v_io_faults = EARLY_COUNTER,
67 	.v_cow_faults = EARLY_COUNTER,
68 	.v_cow_optim = EARLY_COUNTER,
69 	.v_zfod = EARLY_COUNTER,
70 	.v_ozfod = EARLY_COUNTER,
71 	.v_swapin = EARLY_COUNTER,
72 	.v_swapout = EARLY_COUNTER,
73 	.v_swappgsin = EARLY_COUNTER,
74 	.v_swappgsout = EARLY_COUNTER,
75 	.v_vnodein = EARLY_COUNTER,
76 	.v_vnodeout = EARLY_COUNTER,
77 	.v_vnodepgsin = EARLY_COUNTER,
78 	.v_vnodepgsout = EARLY_COUNTER,
79 	.v_intrans = EARLY_COUNTER,
80 	.v_reactivated = EARLY_COUNTER,
81 	.v_pdwakeups = EARLY_COUNTER,
82 	.v_pdpages = EARLY_COUNTER,
83 	.v_pdshortfalls = EARLY_COUNTER,
84 	.v_dfree = EARLY_COUNTER,
85 	.v_pfree = EARLY_COUNTER,
86 	.v_tfree = EARLY_COUNTER,
87 	.v_forks = EARLY_COUNTER,
88 	.v_vforks = EARLY_COUNTER,
89 	.v_rforks = EARLY_COUNTER,
90 	.v_kthreads = EARLY_COUNTER,
91 	.v_forkpages = EARLY_COUNTER,
92 	.v_vforkpages = EARLY_COUNTER,
93 	.v_rforkpages = EARLY_COUNTER,
94 	.v_kthreadpages = EARLY_COUNTER,
95 	.v_wire_count = EARLY_COUNTER,
96 };
97 
98 u_long __exclusive_cache_line vm_user_wire_count;
99 
100 static void
101 vmcounter_startup(void)
102 {
103 	counter_u64_t *cnt = (counter_u64_t *)&vm_cnt;
104 
105 	COUNTER_ARRAY_ALLOC(cnt, VM_METER_NCOUNTERS, M_WAITOK);
106 }
107 SYSINIT(counter, SI_SUB_KMEM, SI_ORDER_FIRST, vmcounter_startup, NULL);
108 
109 SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min,
110 	CTLFLAG_RW, &vm_cnt.v_free_min, 0, "Minimum low-free-pages threshold");
111 SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target,
112 	CTLFLAG_RW, &vm_cnt.v_free_target, 0, "Desired free pages");
113 SYSCTL_UINT(_vm, VM_V_FREE_RESERVED, v_free_reserved,
114 	CTLFLAG_RW, &vm_cnt.v_free_reserved, 0, "Pages reserved for deadlock");
115 SYSCTL_UINT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target,
116 	CTLFLAG_RW, &vm_cnt.v_inactive_target, 0, "Pages desired inactive");
117 SYSCTL_UINT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min,
118 	CTLFLAG_RW, &vm_cnt.v_pageout_free_min, 0, "Min pages reserved for kernel");
119 SYSCTL_UINT(_vm, OID_AUTO, v_free_severe,
120 	CTLFLAG_RW, &vm_cnt.v_free_severe, 0, "Severe page depletion point");
121 
122 static int
123 sysctl_vm_loadavg(SYSCTL_HANDLER_ARGS)
124 {
125 
126 #ifdef SCTL_MASK32
127 	uint32_t la[4];
128 
129 	if (req->flags & SCTL_MASK32) {
130 		la[0] = averunnable.ldavg[0];
131 		la[1] = averunnable.ldavg[1];
132 		la[2] = averunnable.ldavg[2];
133 		la[3] = averunnable.fscale;
134 		return SYSCTL_OUT(req, la, sizeof(la));
135 	} else
136 #endif
137 		return SYSCTL_OUT(req, &averunnable, sizeof(averunnable));
138 }
139 SYSCTL_PROC(_vm, VM_LOADAVG, loadavg, CTLTYPE_STRUCT | CTLFLAG_RD |
140     CTLFLAG_MPSAFE, NULL, 0, sysctl_vm_loadavg, "S,loadavg",
141     "Machine loadaverage history");
142 
143 #if defined(COMPAT_FREEBSD11)
144 struct vmtotal11 {
145 	int16_t	t_rq;
146 	int16_t	t_dw;
147 	int16_t	t_pw;
148 	int16_t	t_sl;
149 	int16_t	t_sw;
150 	int32_t	t_vm;
151 	int32_t	t_avm;
152 	int32_t	t_rm;
153 	int32_t	t_arm;
154 	int32_t	t_vmshr;
155 	int32_t	t_avmshr;
156 	int32_t	t_rmshr;
157 	int32_t	t_armshr;
158 	int32_t	t_free;
159 };
160 #endif
161 
162 static int
163 vmtotal(SYSCTL_HANDLER_ARGS)
164 {
165 	struct vmtotal total;
166 #if defined(COMPAT_FREEBSD11)
167 	struct vmtotal11 total11;
168 #endif
169 	vm_object_t object;
170 	struct proc *p;
171 	struct thread *td;
172 
173 	if (req->oldptr == NULL) {
174 #if defined(COMPAT_FREEBSD11)
175 		if (curproc->p_osrel < P_OSREL_VMTOTAL64)
176 			return (SYSCTL_OUT(req, NULL, sizeof(total11)));
177 #endif
178 		return (SYSCTL_OUT(req, NULL, sizeof(total)));
179 	}
180 	bzero(&total, sizeof(total));
181 
182 	/*
183 	 * Calculate process statistics.
184 	 */
185 	sx_slock(&allproc_lock);
186 	FOREACH_PROC_IN_SYSTEM(p) {
187 		if ((p->p_flag & P_SYSTEM) != 0)
188 			continue;
189 		PROC_LOCK(p);
190 		if (p->p_state != PRS_NEW) {
191 			FOREACH_THREAD_IN_PROC(p, td) {
192 				thread_lock(td);
193 				switch (TD_GET_STATE(td)) {
194 				case TDS_INHIBITED:
195 					if (TD_IS_SWAPPED(td))
196 						total.t_sw++;
197 					else if (TD_IS_SLEEPING(td)) {
198 						if (td->td_priority <= PZERO)
199 							total.t_dw++;
200 						else
201 							total.t_sl++;
202 					}
203 					break;
204 				case TDS_CAN_RUN:
205 					total.t_sw++;
206 					break;
207 				case TDS_RUNQ:
208 				case TDS_RUNNING:
209 					total.t_rq++;
210 					break;
211 				default:
212 					break;
213 				}
214 				thread_unlock(td);
215 			}
216 		}
217 		PROC_UNLOCK(p);
218 	}
219 	sx_sunlock(&allproc_lock);
220 	/*
221 	 * Calculate object memory usage statistics.
222 	 */
223 	mtx_lock(&vm_object_list_mtx);
224 	TAILQ_FOREACH(object, &vm_object_list, object_list) {
225 		/*
226 		 * Perform unsynchronized reads on the object.  In
227 		 * this case, the lack of synchronization should not
228 		 * impair the accuracy of the reported statistics.
229 		 */
230 		if ((object->flags & OBJ_FICTITIOUS) != 0) {
231 			/*
232 			 * Devices, like /dev/mem, will badly skew our totals.
233 			 */
234 			continue;
235 		}
236 		if (object->ref_count == 0) {
237 			/*
238 			 * Also skip unreferenced objects, including
239 			 * vnodes representing mounted file systems.
240 			 */
241 			continue;
242 		}
243 		if (object->ref_count == 1 &&
244 		    (object->flags & (OBJ_ANON | OBJ_SWAP)) == OBJ_SWAP) {
245 			/*
246 			 * Also skip otherwise unreferenced swap
247 			 * objects backing tmpfs vnodes, and POSIX or
248 			 * SysV shared memory.
249 			 */
250 			continue;
251 		}
252 		total.t_vm += object->size;
253 		total.t_rm += object->resident_page_count;
254 		if (vm_object_is_active(object)) {
255 			total.t_avm += object->size;
256 			total.t_arm += object->resident_page_count;
257 		}
258 		if (object->shadow_count > 1) {
259 			/* shared object */
260 			total.t_vmshr += object->size;
261 			total.t_rmshr += object->resident_page_count;
262 			if (vm_object_is_active(object)) {
263 				total.t_avmshr += object->size;
264 				total.t_armshr += object->resident_page_count;
265 			}
266 		}
267 	}
268 	mtx_unlock(&vm_object_list_mtx);
269 	total.t_pw = vm_wait_count();
270 	total.t_free = vm_free_count();
271 #if defined(COMPAT_FREEBSD11)
272 	/* sysctl(8) allocates twice as much memory as reported by sysctl(3) */
273 	if (curproc->p_osrel < P_OSREL_VMTOTAL64 && (req->oldlen ==
274 	    sizeof(total11) || req->oldlen == 2 * sizeof(total11))) {
275 		bzero(&total11, sizeof(total11));
276 		total11.t_rq = total.t_rq;
277 		total11.t_dw = total.t_dw;
278 		total11.t_pw = total.t_pw;
279 		total11.t_sl = total.t_sl;
280 		total11.t_sw = total.t_sw;
281 		total11.t_vm = total.t_vm;	/* truncate */
282 		total11.t_avm = total.t_avm;	/* truncate */
283 		total11.t_rm = total.t_rm;	/* truncate */
284 		total11.t_arm = total.t_arm;	/* truncate */
285 		total11.t_vmshr = total.t_vmshr;	/* truncate */
286 		total11.t_avmshr = total.t_avmshr;	/* truncate */
287 		total11.t_rmshr = total.t_rmshr;	/* truncate */
288 		total11.t_armshr = total.t_armshr;	/* truncate */
289 		total11.t_free = total.t_free;		/* truncate */
290 		return (SYSCTL_OUT(req, &total11, sizeof(total11)));
291 	}
292 #endif
293 	return (SYSCTL_OUT(req, &total, sizeof(total)));
294 }
295 
296 SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE | CTLFLAG_RD |
297     CTLFLAG_MPSAFE, NULL, 0, vmtotal, "S,vmtotal",
298     "System virtual memory statistics");
299 SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
300     "VM meter stats");
301 static SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
302     "VM meter sys stats");
303 static SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
304     "VM meter vm stats");
305 SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
306     "VM meter misc stats");
307 
308 static int
309 sysctl_handle_vmstat(SYSCTL_HANDLER_ARGS)
310 {
311 	uint64_t val;
312 #ifdef COMPAT_FREEBSD11
313 	uint32_t val32;
314 #endif
315 
316 	val = counter_u64_fetch(*(counter_u64_t *)arg1);
317 #ifdef COMPAT_FREEBSD11
318 	if (req->oldlen == sizeof(val32)) {
319 		val32 = val;		/* truncate */
320 		return (SYSCTL_OUT(req, &val32, sizeof(val32)));
321 	}
322 #endif
323 	return (SYSCTL_OUT(req, &val, sizeof(val)));
324 }
325 
326 #define	VM_STATS(parent, var, descr) \
327     SYSCTL_OID(parent, OID_AUTO, var, CTLTYPE_U64 | CTLFLAG_MPSAFE | \
328     CTLFLAG_RD, &vm_cnt.var, 0, sysctl_handle_vmstat, "QU", descr)
329 #define	VM_STATS_VM(var, descr)		VM_STATS(_vm_stats_vm, var, descr)
330 #define	VM_STATS_SYS(var, descr)	VM_STATS(_vm_stats_sys, var, descr)
331 
332 VM_STATS_SYS(v_swtch, "Context switches");
333 VM_STATS_SYS(v_trap, "Traps");
334 VM_STATS_SYS(v_syscall, "System calls");
335 VM_STATS_SYS(v_intr, "Device interrupts");
336 VM_STATS_SYS(v_soft, "Software interrupts");
337 VM_STATS_VM(v_vm_faults, "Address memory faults");
338 VM_STATS_VM(v_io_faults, "Page faults requiring I/O");
339 VM_STATS_VM(v_cow_faults, "Copy-on-write faults");
340 VM_STATS_VM(v_cow_optim, "Optimized COW faults");
341 VM_STATS_VM(v_zfod, "Pages zero-filled on demand");
342 VM_STATS_VM(v_ozfod, "Optimized zero fill pages");
343 VM_STATS_VM(v_swapin, "Swap pager pageins");
344 VM_STATS_VM(v_swapout, "Swap pager pageouts");
345 VM_STATS_VM(v_swappgsin, "Swap pages swapped in");
346 VM_STATS_VM(v_swappgsout, "Swap pages swapped out");
347 VM_STATS_VM(v_vnodein, "Vnode pager pageins");
348 VM_STATS_VM(v_vnodeout, "Vnode pager pageouts");
349 VM_STATS_VM(v_vnodepgsin, "Vnode pages paged in");
350 VM_STATS_VM(v_vnodepgsout, "Vnode pages paged out");
351 VM_STATS_VM(v_intrans, "In transit page faults");
352 VM_STATS_VM(v_reactivated, "Pages reactivated by pagedaemon");
353 VM_STATS_VM(v_pdwakeups, "Pagedaemon wakeups");
354 VM_STATS_VM(v_pdshortfalls, "Page reclamation shortfalls");
355 VM_STATS_VM(v_dfree, "Pages freed by pagedaemon");
356 VM_STATS_VM(v_pfree, "Pages freed by exiting processes");
357 VM_STATS_VM(v_tfree, "Total pages freed");
358 VM_STATS_VM(v_forks, "Number of fork() calls");
359 VM_STATS_VM(v_vforks, "Number of vfork() calls");
360 VM_STATS_VM(v_rforks, "Number of rfork() calls");
361 VM_STATS_VM(v_kthreads, "Number of fork() calls by kernel");
362 VM_STATS_VM(v_forkpages, "VM pages affected by fork()");
363 VM_STATS_VM(v_vforkpages, "VM pages affected by vfork()");
364 VM_STATS_VM(v_rforkpages, "VM pages affected by rfork()");
365 VM_STATS_VM(v_kthreadpages, "VM pages affected by fork() by kernel");
366 
367 static int
368 sysctl_handle_vmstat_proc(SYSCTL_HANDLER_ARGS)
369 {
370 	u_int (*fn)(void);
371 	uint32_t val;
372 
373 	fn = arg1;
374 	val = fn();
375 	return (SYSCTL_OUT(req, &val, sizeof(val)));
376 }
377 
378 #define	VM_STATS_PROC(var, descr, fn) \
379     SYSCTL_OID(_vm_stats_vm, OID_AUTO, var, CTLTYPE_U32 | CTLFLAG_MPSAFE | \
380     CTLFLAG_RD, fn, 0, sysctl_handle_vmstat_proc, "IU", descr)
381 
382 #define	VM_STATS_UINT(var, descr)	\
383     SYSCTL_UINT(_vm_stats_vm, OID_AUTO, var, CTLFLAG_RD, &vm_cnt.var, 0, descr)
384 #define	VM_STATS_ULONG(var, descr)	\
385     SYSCTL_ULONG(_vm_stats_vm, OID_AUTO, var, CTLFLAG_RD, &vm_cnt.var, 0, descr)
386 
387 VM_STATS_UINT(v_page_size, "Page size in bytes");
388 VM_STATS_UINT(v_page_count, "Total number of pages in system");
389 VM_STATS_UINT(v_free_reserved, "Pages reserved for deadlock");
390 VM_STATS_UINT(v_free_target, "Pages desired free");
391 VM_STATS_UINT(v_free_min, "Minimum low-free-pages threshold");
392 VM_STATS_PROC(v_free_count, "Free pages", vm_free_count);
393 VM_STATS_PROC(v_wire_count, "Wired pages", vm_wire_count);
394 VM_STATS_PROC(v_active_count, "Active pages", vm_active_count);
395 VM_STATS_UINT(v_inactive_target, "Desired inactive pages");
396 VM_STATS_PROC(v_inactive_count, "Inactive pages", vm_inactive_count);
397 VM_STATS_PROC(v_laundry_count, "Pages eligible for laundering",
398     vm_laundry_count);
399 VM_STATS_UINT(v_pageout_free_min, "Min pages reserved for kernel");
400 VM_STATS_UINT(v_interrupt_free_min, "Reserved pages for interrupt code");
401 VM_STATS_UINT(v_free_severe, "Severe page depletion point");
402 
403 SYSCTL_ULONG(_vm_stats_vm, OID_AUTO, v_user_wire_count, CTLFLAG_RD,
404     &vm_user_wire_count, 0, "User-wired virtual memory");
405 
406 #ifdef COMPAT_FREEBSD11
407 /*
408  * Provide compatibility sysctls for the benefit of old utilities which exit
409  * with an error if they cannot be found.
410  */
411 SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cache_count, CTLFLAG_RD,
412     SYSCTL_NULL_UINT_PTR, 0, "Dummy for compatibility");
413 SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_tcached, CTLFLAG_RD,
414     SYSCTL_NULL_UINT_PTR, 0, "Dummy for compatibility");
415 #endif
416 
417 u_int
418 vm_free_count(void)
419 {
420 	u_int v;
421 	int i;
422 
423 	v = 0;
424 	for (i = 0; i < vm_ndomains; i++)
425 		v += vm_dom[i].vmd_free_count;
426 
427 	return (v);
428 }
429 
430 static u_int
431 vm_pagequeue_count(int pq)
432 {
433 	u_int v;
434 	int i;
435 
436 	v = 0;
437 	for (i = 0; i < vm_ndomains; i++)
438 		v += vm_dom[i].vmd_pagequeues[pq].pq_cnt;
439 
440 	return (v);
441 }
442 
443 u_int
444 vm_active_count(void)
445 {
446 
447 	return (vm_pagequeue_count(PQ_ACTIVE));
448 }
449 
450 u_int
451 vm_inactive_count(void)
452 {
453 
454 	return (vm_pagequeue_count(PQ_INACTIVE));
455 }
456 
457 u_int
458 vm_laundry_count(void)
459 {
460 
461 	return (vm_pagequeue_count(PQ_LAUNDRY));
462 }
463 
464 static int
465 sysctl_vm_pdpages(SYSCTL_HANDLER_ARGS)
466 {
467 	struct vm_pagequeue *pq;
468 	uint64_t ret;
469 	int dom, i;
470 
471 	ret = counter_u64_fetch(vm_cnt.v_pdpages);
472 	for (dom = 0; dom < vm_ndomains; dom++)
473 		for (i = 0; i < PQ_COUNT; i++) {
474 			pq = &VM_DOMAIN(dom)->vmd_pagequeues[i];
475 			ret += pq->pq_pdpages;
476 		}
477 	return (SYSCTL_OUT(req, &ret, sizeof(ret)));
478 }
479 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdpages,
480     CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_RD, NULL, 0, sysctl_vm_pdpages, "QU",
481     "Pages analyzed by pagedaemon");
482 
483 static void
484 vm_domain_stats_init(struct vm_domain *vmd, struct sysctl_oid *parent)
485 {
486 	struct sysctl_oid *oid;
487 
488 	vmd->vmd_oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(parent), OID_AUTO,
489 	    vmd->vmd_name, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "");
490 	oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(vmd->vmd_oid), OID_AUTO,
491 	    "stats", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "");
492 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
493 	    "free_count", CTLFLAG_RD, &vmd->vmd_free_count, 0,
494 	    "Free pages");
495 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
496 	    "active", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_ACTIVE].pq_cnt, 0,
497 	    "Active pages");
498 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
499 	    "actpdpgs", CTLFLAG_RD,
500 	    &vmd->vmd_pagequeues[PQ_ACTIVE].pq_pdpages, 0,
501 	    "Active pages scanned by the page daemon");
502 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
503 	    "inactive", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_INACTIVE].pq_cnt, 0,
504 	    "Inactive pages");
505 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
506 	    "inactpdpgs", CTLFLAG_RD,
507 	    &vmd->vmd_pagequeues[PQ_INACTIVE].pq_pdpages, 0,
508 	    "Inactive pages scanned by the page daemon");
509 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
510 	    "laundry", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_LAUNDRY].pq_cnt, 0,
511 	    "laundry pages");
512 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
513 	    "laundpdpgs", CTLFLAG_RD,
514 	    &vmd->vmd_pagequeues[PQ_LAUNDRY].pq_pdpages, 0,
515 	    "Laundry pages scanned by the page daemon");
516 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO, "unswappable",
517 	    CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_UNSWAPPABLE].pq_cnt, 0,
518 	    "Unswappable pages");
519 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
520 	    "unswppdpgs", CTLFLAG_RD,
521 	    &vmd->vmd_pagequeues[PQ_UNSWAPPABLE].pq_pdpages, 0,
522 	    "Unswappable pages scanned by the page daemon");
523 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
524 	    "inactive_target", CTLFLAG_RD, &vmd->vmd_inactive_target, 0,
525 	    "Target inactive pages");
526 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
527 	    "free_target", CTLFLAG_RD, &vmd->vmd_free_target, 0,
528 	    "Target free pages");
529 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
530 	    "free_reserved", CTLFLAG_RD, &vmd->vmd_free_reserved, 0,
531 	    "Reserved free pages");
532 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
533 	    "free_min", CTLFLAG_RD, &vmd->vmd_free_min, 0,
534 	    "Minimum free pages");
535 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
536 	    "free_severe", CTLFLAG_RD, &vmd->vmd_free_severe, 0,
537 	    "Severe free pages");
538 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
539 	    "inactive_pps", CTLFLAG_RD, &vmd->vmd_inactive_pps, 0,
540 	    "inactive pages freed/second");
541 
542 }
543 
544 static void
545 vm_stats_init(void *arg __unused)
546 {
547 	struct sysctl_oid *oid;
548 	int i;
549 
550 	oid = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_vm), OID_AUTO,
551 	    "domain", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "");
552 	for (i = 0; i < vm_ndomains; i++)
553 		vm_domain_stats_init(VM_DOMAIN(i), oid);
554 }
555 
556 SYSINIT(vmstats_init, SI_SUB_VM_CONF, SI_ORDER_FIRST, vm_stats_init, NULL);
557