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