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