xref: /freebsd/sys/vm/vm_meter.c (revision 85732ac8)
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 __FBSDID("$FreeBSD$");
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/lock.h>
41 #include <sys/malloc.h>
42 #include <sys/mutex.h>
43 #include <sys/proc.h>
44 #include <sys/resource.h>
45 #include <sys/rwlock.h>
46 #include <sys/sx.h>
47 #include <sys/vmmeter.h>
48 #include <sys/smp.h>
49 
50 #include <vm/vm.h>
51 #include <vm/vm_page.h>
52 #include <vm/vm_extern.h>
53 #include <vm/vm_param.h>
54 #include <vm/vm_phys.h>
55 #include <vm/vm_pagequeue.h>
56 #include <vm/pmap.h>
57 #include <vm/vm_map.h>
58 #include <vm/vm_object.h>
59 #include <sys/sysctl.h>
60 
61 struct vmmeter __read_mostly vm_cnt = {
62 	.v_swtch = EARLY_COUNTER,
63 	.v_trap = EARLY_COUNTER,
64 	.v_syscall = EARLY_COUNTER,
65 	.v_intr = EARLY_COUNTER,
66 	.v_soft = EARLY_COUNTER,
67 	.v_vm_faults = EARLY_COUNTER,
68 	.v_io_faults = EARLY_COUNTER,
69 	.v_cow_faults = EARLY_COUNTER,
70 	.v_cow_optim = EARLY_COUNTER,
71 	.v_zfod = EARLY_COUNTER,
72 	.v_ozfod = EARLY_COUNTER,
73 	.v_swapin = EARLY_COUNTER,
74 	.v_swapout = EARLY_COUNTER,
75 	.v_swappgsin = EARLY_COUNTER,
76 	.v_swappgsout = EARLY_COUNTER,
77 	.v_vnodein = EARLY_COUNTER,
78 	.v_vnodeout = EARLY_COUNTER,
79 	.v_vnodepgsin = EARLY_COUNTER,
80 	.v_vnodepgsout = EARLY_COUNTER,
81 	.v_intrans = EARLY_COUNTER,
82 	.v_reactivated = EARLY_COUNTER,
83 	.v_pdwakeups = EARLY_COUNTER,
84 	.v_pdpages = EARLY_COUNTER,
85 	.v_pdshortfalls = EARLY_COUNTER,
86 	.v_dfree = EARLY_COUNTER,
87 	.v_pfree = EARLY_COUNTER,
88 	.v_tfree = EARLY_COUNTER,
89 	.v_forks = EARLY_COUNTER,
90 	.v_vforks = EARLY_COUNTER,
91 	.v_rforks = EARLY_COUNTER,
92 	.v_kthreads = EARLY_COUNTER,
93 	.v_forkpages = EARLY_COUNTER,
94 	.v_vforkpages = EARLY_COUNTER,
95 	.v_rforkpages = EARLY_COUNTER,
96 	.v_kthreadpages = EARLY_COUNTER,
97 	.v_wire_count = EARLY_COUNTER,
98 };
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 	u_int32_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 /*
144  * This function aims to determine if the object is mapped,
145  * specifically, if it is referenced by a vm_map_entry.  Because
146  * objects occasionally acquire transient references that do not
147  * represent a mapping, the method used here is inexact.  However, it
148  * has very low overhead and is good enough for the advisory
149  * vm.vmtotal sysctl.
150  */
151 static bool
152 is_object_active(vm_object_t obj)
153 {
154 
155 	return (obj->ref_count > obj->shadow_count);
156 }
157 
158 #if defined(COMPAT_FREEBSD11)
159 struct vmtotal11 {
160 	int16_t	t_rq;
161 	int16_t	t_dw;
162 	int16_t	t_pw;
163 	int16_t	t_sl;
164 	int16_t	t_sw;
165 	int32_t	t_vm;
166 	int32_t	t_avm;
167 	int32_t	t_rm;
168 	int32_t	t_arm;
169 	int32_t	t_vmshr;
170 	int32_t	t_avmshr;
171 	int32_t	t_rmshr;
172 	int32_t	t_armshr;
173 	int32_t	t_free;
174 };
175 #endif
176 
177 static int
178 vmtotal(SYSCTL_HANDLER_ARGS)
179 {
180 	struct vmtotal total;
181 #if defined(COMPAT_FREEBSD11)
182 	struct vmtotal11 total11;
183 #endif
184 	vm_object_t object;
185 	struct proc *p;
186 	struct thread *td;
187 
188 	if (req->oldptr == NULL) {
189 #if defined(COMPAT_FREEBSD11)
190 		if (curproc->p_osrel < P_OSREL_VMTOTAL64)
191 			return (SYSCTL_OUT(req, NULL, sizeof(total11)));
192 #endif
193 		return (SYSCTL_OUT(req, NULL, sizeof(total)));
194 	}
195 	bzero(&total, sizeof(total));
196 
197 	/*
198 	 * Calculate process statistics.
199 	 */
200 	sx_slock(&allproc_lock);
201 	FOREACH_PROC_IN_SYSTEM(p) {
202 		if ((p->p_flag & P_SYSTEM) != 0)
203 			continue;
204 		PROC_LOCK(p);
205 		if (p->p_state != PRS_NEW) {
206 			FOREACH_THREAD_IN_PROC(p, td) {
207 				thread_lock(td);
208 				switch (td->td_state) {
209 				case TDS_INHIBITED:
210 					if (TD_IS_SWAPPED(td))
211 						total.t_sw++;
212 					else if (TD_IS_SLEEPING(td)) {
213 						if (td->td_priority <= PZERO)
214 							total.t_dw++;
215 						else
216 							total.t_sl++;
217 					}
218 					break;
219 				case TDS_CAN_RUN:
220 					total.t_sw++;
221 					break;
222 				case TDS_RUNQ:
223 				case TDS_RUNNING:
224 					total.t_rq++;
225 					break;
226 				default:
227 					break;
228 				}
229 				thread_unlock(td);
230 			}
231 		}
232 		PROC_UNLOCK(p);
233 	}
234 	sx_sunlock(&allproc_lock);
235 	/*
236 	 * Calculate object memory usage statistics.
237 	 */
238 	mtx_lock(&vm_object_list_mtx);
239 	TAILQ_FOREACH(object, &vm_object_list, object_list) {
240 		/*
241 		 * Perform unsynchronized reads on the object.  In
242 		 * this case, the lack of synchronization should not
243 		 * impair the accuracy of the reported statistics.
244 		 */
245 		if ((object->flags & OBJ_FICTITIOUS) != 0) {
246 			/*
247 			 * Devices, like /dev/mem, will badly skew our totals.
248 			 */
249 			continue;
250 		}
251 		if (object->ref_count == 0) {
252 			/*
253 			 * Also skip unreferenced objects, including
254 			 * vnodes representing mounted file systems.
255 			 */
256 			continue;
257 		}
258 		if (object->ref_count == 1 &&
259 		    (object->flags & OBJ_NOSPLIT) != 0) {
260 			/*
261 			 * Also skip otherwise unreferenced swap
262 			 * objects backing tmpfs vnodes, and POSIX or
263 			 * SysV shared memory.
264 			 */
265 			continue;
266 		}
267 		total.t_vm += object->size;
268 		total.t_rm += object->resident_page_count;
269 		if (is_object_active(object)) {
270 			total.t_avm += object->size;
271 			total.t_arm += object->resident_page_count;
272 		}
273 		if (object->shadow_count > 1) {
274 			/* shared object */
275 			total.t_vmshr += object->size;
276 			total.t_rmshr += object->resident_page_count;
277 			if (is_object_active(object)) {
278 				total.t_avmshr += object->size;
279 				total.t_armshr += object->resident_page_count;
280 			}
281 		}
282 	}
283 	mtx_unlock(&vm_object_list_mtx);
284 	total.t_pw = vm_wait_count();
285 	total.t_free = vm_free_count();
286 #if defined(COMPAT_FREEBSD11)
287 	/* sysctl(8) allocates twice as much memory as reported by sysctl(3) */
288 	if (curproc->p_osrel < P_OSREL_VMTOTAL64 && (req->oldlen ==
289 	    sizeof(total11) || req->oldlen == 2 * sizeof(total11))) {
290 		bzero(&total11, sizeof(total11));
291 		total11.t_rq = total.t_rq;
292 		total11.t_dw = total.t_dw;
293 		total11.t_pw = total.t_pw;
294 		total11.t_sl = total.t_sl;
295 		total11.t_sw = total.t_sw;
296 		total11.t_vm = total.t_vm;	/* truncate */
297 		total11.t_avm = total.t_avm;	/* truncate */
298 		total11.t_rm = total.t_rm;	/* truncate */
299 		total11.t_arm = total.t_arm;	/* truncate */
300 		total11.t_vmshr = total.t_vmshr;	/* truncate */
301 		total11.t_avmshr = total.t_avmshr;	/* truncate */
302 		total11.t_rmshr = total.t_rmshr;	/* truncate */
303 		total11.t_armshr = total.t_armshr;	/* truncate */
304 		total11.t_free = total.t_free;		/* truncate */
305 		return (SYSCTL_OUT(req, &total11, sizeof(total11)));
306 	}
307 #endif
308 	return (SYSCTL_OUT(req, &total, sizeof(total)));
309 }
310 
311 SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE | CTLFLAG_RD |
312     CTLFLAG_MPSAFE, NULL, 0, vmtotal, "S,vmtotal",
313     "System virtual memory statistics");
314 SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
315 static SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0,
316 	"VM meter sys stats");
317 static SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0,
318 	"VM meter vm stats");
319 SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats");
320 
321 static int
322 sysctl_handle_vmstat(SYSCTL_HANDLER_ARGS)
323 {
324 	uint64_t val;
325 #ifdef COMPAT_FREEBSD11
326 	uint32_t val32;
327 #endif
328 
329 	val = counter_u64_fetch(*(counter_u64_t *)arg1);
330 #ifdef COMPAT_FREEBSD11
331 	if (req->oldlen == sizeof(val32)) {
332 		val32 = val;		/* truncate */
333 		return (SYSCTL_OUT(req, &val32, sizeof(val32)));
334 	}
335 #endif
336 	return (SYSCTL_OUT(req, &val, sizeof(val)));
337 }
338 
339 #define	VM_STATS(parent, var, descr) \
340     SYSCTL_OID(parent, OID_AUTO, var, CTLTYPE_U64 | CTLFLAG_MPSAFE | \
341     CTLFLAG_RD, &vm_cnt.var, 0, sysctl_handle_vmstat, "QU", descr)
342 #define	VM_STATS_VM(var, descr)		VM_STATS(_vm_stats_vm, var, descr)
343 #define	VM_STATS_SYS(var, descr)	VM_STATS(_vm_stats_sys, var, descr)
344 
345 VM_STATS_SYS(v_swtch, "Context switches");
346 VM_STATS_SYS(v_trap, "Traps");
347 VM_STATS_SYS(v_syscall, "System calls");
348 VM_STATS_SYS(v_intr, "Device interrupts");
349 VM_STATS_SYS(v_soft, "Software interrupts");
350 VM_STATS_VM(v_vm_faults, "Address memory faults");
351 VM_STATS_VM(v_io_faults, "Page faults requiring I/O");
352 VM_STATS_VM(v_cow_faults, "Copy-on-write faults");
353 VM_STATS_VM(v_cow_optim, "Optimized COW faults");
354 VM_STATS_VM(v_zfod, "Pages zero-filled on demand");
355 VM_STATS_VM(v_ozfod, "Optimized zero fill pages");
356 VM_STATS_VM(v_swapin, "Swap pager pageins");
357 VM_STATS_VM(v_swapout, "Swap pager pageouts");
358 VM_STATS_VM(v_swappgsin, "Swap pages swapped in");
359 VM_STATS_VM(v_swappgsout, "Swap pages swapped out");
360 VM_STATS_VM(v_vnodein, "Vnode pager pageins");
361 VM_STATS_VM(v_vnodeout, "Vnode pager pageouts");
362 VM_STATS_VM(v_vnodepgsin, "Vnode pages paged in");
363 VM_STATS_VM(v_vnodepgsout, "Vnode pages paged out");
364 VM_STATS_VM(v_intrans, "In transit page faults");
365 VM_STATS_VM(v_reactivated, "Pages reactivated by pagedaemon");
366 VM_STATS_VM(v_pdwakeups, "Pagedaemon wakeups");
367 VM_STATS_VM(v_pdshortfalls, "Page reclamation shortfalls");
368 VM_STATS_VM(v_dfree, "Pages freed by pagedaemon");
369 VM_STATS_VM(v_pfree, "Pages freed by exiting processes");
370 VM_STATS_VM(v_tfree, "Total pages freed");
371 VM_STATS_VM(v_forks, "Number of fork() calls");
372 VM_STATS_VM(v_vforks, "Number of vfork() calls");
373 VM_STATS_VM(v_rforks, "Number of rfork() calls");
374 VM_STATS_VM(v_kthreads, "Number of fork() calls by kernel");
375 VM_STATS_VM(v_forkpages, "VM pages affected by fork()");
376 VM_STATS_VM(v_vforkpages, "VM pages affected by vfork()");
377 VM_STATS_VM(v_rforkpages, "VM pages affected by rfork()");
378 VM_STATS_VM(v_kthreadpages, "VM pages affected by fork() by kernel");
379 
380 static int
381 sysctl_handle_vmstat_proc(SYSCTL_HANDLER_ARGS)
382 {
383 	u_int (*fn)(void);
384 	uint32_t val;
385 
386 	fn = arg1;
387 	val = fn();
388 	return (SYSCTL_OUT(req, &val, sizeof(val)));
389 }
390 
391 #define	VM_STATS_PROC(var, descr, fn) \
392     SYSCTL_OID(_vm_stats_vm, OID_AUTO, var, CTLTYPE_U32 | CTLFLAG_MPSAFE | \
393     CTLFLAG_RD, fn, 0, sysctl_handle_vmstat_proc, "IU", descr)
394 
395 #define	VM_STATS_UINT(var, descr)	\
396     SYSCTL_UINT(_vm_stats_vm, OID_AUTO, var, CTLFLAG_RD, &vm_cnt.var, 0, descr)
397 
398 VM_STATS_UINT(v_page_size, "Page size in bytes");
399 VM_STATS_UINT(v_page_count, "Total number of pages in system");
400 VM_STATS_UINT(v_free_reserved, "Pages reserved for deadlock");
401 VM_STATS_UINT(v_free_target, "Pages desired free");
402 VM_STATS_UINT(v_free_min, "Minimum low-free-pages threshold");
403 VM_STATS_PROC(v_free_count, "Free pages", vm_free_count);
404 VM_STATS_PROC(v_wire_count, "Wired pages", vm_wire_count);
405 VM_STATS_PROC(v_active_count, "Active pages", vm_active_count);
406 VM_STATS_UINT(v_inactive_target, "Desired inactive pages");
407 VM_STATS_PROC(v_inactive_count, "Inactive pages", vm_inactive_count);
408 VM_STATS_PROC(v_laundry_count, "Pages eligible for laundering",
409     vm_laundry_count);
410 VM_STATS_UINT(v_pageout_free_min, "Min pages reserved for kernel");
411 VM_STATS_UINT(v_interrupt_free_min, "Reserved pages for interrupt code");
412 VM_STATS_UINT(v_free_severe, "Severe page depletion point");
413 
414 #ifdef COMPAT_FREEBSD11
415 /*
416  * Provide compatibility sysctls for the benefit of old utilities which exit
417  * with an error if they cannot be found.
418  */
419 SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cache_count, CTLFLAG_RD,
420     SYSCTL_NULL_UINT_PTR, 0, "Dummy for compatibility");
421 SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_tcached, CTLFLAG_RD,
422     SYSCTL_NULL_UINT_PTR, 0, "Dummy for compatibility");
423 #endif
424 
425 u_int
426 vm_free_count(void)
427 {
428 	u_int v;
429 	int i;
430 
431 	v = 0;
432 	for (i = 0; i < vm_ndomains; i++)
433 		v += vm_dom[i].vmd_free_count;
434 
435 	return (v);
436 }
437 
438 static u_int
439 vm_pagequeue_count(int pq)
440 {
441 	u_int v;
442 	int i;
443 
444 	v = 0;
445 	for (i = 0; i < vm_ndomains; i++)
446 		v += vm_dom[i].vmd_pagequeues[pq].pq_cnt;
447 
448 	return (v);
449 }
450 
451 u_int
452 vm_active_count(void)
453 {
454 
455 	return (vm_pagequeue_count(PQ_ACTIVE));
456 }
457 
458 u_int
459 vm_inactive_count(void)
460 {
461 
462 	return (vm_pagequeue_count(PQ_INACTIVE));
463 }
464 
465 u_int
466 vm_laundry_count(void)
467 {
468 
469 	return (vm_pagequeue_count(PQ_LAUNDRY));
470 }
471 
472 static int
473 sysctl_vm_pdpages(SYSCTL_HANDLER_ARGS)
474 {
475 	struct vm_pagequeue *pq;
476 	uint64_t ret;
477 	int dom, i;
478 
479 	ret = counter_u64_fetch(vm_cnt.v_pdpages);
480 	for (dom = 0; dom < vm_ndomains; dom++)
481 		for (i = 0; i < PQ_COUNT; i++) {
482 			pq = &VM_DOMAIN(dom)->vmd_pagequeues[i];
483 			ret += pq->pq_pdpages;
484 		}
485 	return (SYSCTL_OUT(req, &ret, sizeof(ret)));
486 }
487 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdpages,
488     CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_RD, NULL, 0, sysctl_vm_pdpages, "QU",
489     "Pages analyzed by pagedaemon");
490 
491 static void
492 vm_domain_stats_init(struct vm_domain *vmd, struct sysctl_oid *parent)
493 {
494 	struct sysctl_oid *oid;
495 
496 	vmd->vmd_oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(parent), OID_AUTO,
497 	    vmd->vmd_name, CTLFLAG_RD, NULL, "");
498 	oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(vmd->vmd_oid), OID_AUTO,
499 	    "stats", CTLFLAG_RD, NULL, "");
500 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
501 	    "free_count", CTLFLAG_RD, &vmd->vmd_free_count, 0,
502 	    "Free pages");
503 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
504 	    "active", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_ACTIVE].pq_cnt, 0,
505 	    "Active pages");
506 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
507 	    "actpdpgs", CTLFLAG_RD,
508 	    &vmd->vmd_pagequeues[PQ_ACTIVE].pq_pdpages, 0,
509 	    "Active pages scanned by the page daemon");
510 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
511 	    "inactive", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_INACTIVE].pq_cnt, 0,
512 	    "Inactive pages");
513 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
514 	    "inactpdpgs", CTLFLAG_RD,
515 	    &vmd->vmd_pagequeues[PQ_INACTIVE].pq_pdpages, 0,
516 	    "Inactive pages scanned by the page daemon");
517 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
518 	    "laundry", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_LAUNDRY].pq_cnt, 0,
519 	    "laundry pages");
520 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
521 	    "laundpdpgs", CTLFLAG_RD,
522 	    &vmd->vmd_pagequeues[PQ_LAUNDRY].pq_pdpages, 0,
523 	    "Laundry pages scanned by the page daemon");
524 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO, "unswappable",
525 	    CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_UNSWAPPABLE].pq_cnt, 0,
526 	    "Unswappable pages");
527 	SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
528 	    "unswppdpgs", CTLFLAG_RD,
529 	    &vmd->vmd_pagequeues[PQ_UNSWAPPABLE].pq_pdpages, 0,
530 	    "Unswappable pages scanned by the page daemon");
531 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
532 	    "inactive_target", CTLFLAG_RD, &vmd->vmd_inactive_target, 0,
533 	    "Target inactive pages");
534 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
535 	    "free_target", CTLFLAG_RD, &vmd->vmd_free_target, 0,
536 	    "Target free pages");
537 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
538 	    "free_reserved", CTLFLAG_RD, &vmd->vmd_free_reserved, 0,
539 	    "Reserved free pages");
540 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
541 	    "free_min", CTLFLAG_RD, &vmd->vmd_free_min, 0,
542 	    "Minimum free pages");
543 	SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
544 	    "free_severe", CTLFLAG_RD, &vmd->vmd_free_severe, 0,
545 	    "Severe free pages");
546 
547 }
548 
549 static void
550 vm_stats_init(void *arg __unused)
551 {
552 	struct sysctl_oid *oid;
553 	int i;
554 
555 	oid = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_vm), OID_AUTO,
556 	    "domain", CTLFLAG_RD, NULL, "");
557 	for (i = 0; i < vm_ndomains; i++)
558 		vm_domain_stats_init(VM_DOMAIN(i), oid);
559 }
560 
561 SYSINIT(vmstats_init, SI_SUB_VM_CONF, SI_ORDER_FIRST, vm_stats_init, NULL);
562