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