2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94
35 #ifndef _SYS_VMMETER_H_
36 #define _SYS_VMMETER_H_
39 * This value is used by ps(1) to change sleep state flag from 'S' to
40 * 'I' and by the sched process to set the alarm clock.
44 /* Systemwide totals computed every five seconds. */
46 uint64_t t_vm; /* total virtual memory */
47 uint64_t t_avm; /* active virtual memory */
48 uint64_t t_rm; /* total real memory in use */
49 uint64_t t_arm; /* active real memory */
50 uint64_t t_vmshr; /* shared virtual memory */
51 uint64_t t_avmshr; /* active shared virtual memory */
52 uint64_t t_rmshr; /* shared real memory */
53 uint64_t t_armshr; /* active shared real memory */
54 uint64_t t_free; /* free memory pages */
55 int16_t t_rq; /* length of the run queue */
56 int16_t t_dw; /* jobs in ``disk wait'' (neg
58 int16_t t_pw; /* jobs in page wait */
59 int16_t t_sl; /* jobs sleeping in core */
60 int16_t t_sw; /* swapped out runnable/short
65 #if defined(_KERNEL) || defined(_WANT_VMMETER)
66 #include <sys/counter.h>
69 #define VMMETER_ALIGNED __aligned(CACHE_LINE_SIZE)
71 #define VMMETER_ALIGNED
75 * System wide statistics counters.
77 * a - locked by atomic operations
78 * c - constant after initialization
79 * f - locked by vm_page_queue_free_mtx
81 * q - changes are synchronized by the corresponding vm_pagequeue lock
85 * General system activity.
87 counter_u64_t v_swtch; /* (p) context switches */
88 counter_u64_t v_trap; /* (p) calls to trap */
89 counter_u64_t v_syscall; /* (p) calls to syscall() */
90 counter_u64_t v_intr; /* (p) device interrupts */
91 counter_u64_t v_soft; /* (p) software interrupts */
93 * Virtual memory activity.
95 counter_u64_t v_vm_faults; /* (p) address memory faults */
96 counter_u64_t v_io_faults; /* (p) page faults requiring I/O */
97 counter_u64_t v_cow_faults; /* (p) copy-on-writes faults */
98 counter_u64_t v_cow_optim; /* (p) optimized COW faults */
99 counter_u64_t v_zfod; /* (p) pages zero filled on demand */
100 counter_u64_t v_ozfod; /* (p) optimized zero fill pages */
101 counter_u64_t v_swapin; /* (p) swap pager pageins */
102 counter_u64_t v_swapout; /* (p) swap pager pageouts */
103 counter_u64_t v_swappgsin; /* (p) swap pager pages paged in */
104 counter_u64_t v_swappgsout; /* (p) swap pager pages paged out */
105 counter_u64_t v_vnodein; /* (p) vnode pager pageins */
106 counter_u64_t v_vnodeout; /* (p) vnode pager pageouts */
107 counter_u64_t v_vnodepgsin; /* (p) vnode_pager pages paged in */
108 counter_u64_t v_vnodepgsout; /* (p) vnode pager pages paged out */
109 counter_u64_t v_intrans; /* (p) intransit blocking page faults */
110 counter_u64_t v_reactivated; /* (p) reactivated by the pagedaemon */
111 counter_u64_t v_pdwakeups; /* (p) times daemon has awaken */
112 counter_u64_t v_pdpages; /* (p) pages analyzed by daemon */
113 counter_u64_t v_pdshortfalls; /* (p) page reclamation shortfalls */
115 counter_u64_t v_dfree; /* (p) pages freed by daemon */
116 counter_u64_t v_pfree; /* (p) pages freed by processes */
117 counter_u64_t v_tfree; /* (p) total pages freed */
119 * Fork/vfork/rfork activity.
121 counter_u64_t v_forks; /* (p) fork() calls */
122 counter_u64_t v_vforks; /* (p) vfork() calls */
123 counter_u64_t v_rforks; /* (p) rfork() calls */
124 counter_u64_t v_kthreads; /* (p) fork() calls by kernel */
125 counter_u64_t v_forkpages; /* (p) pages affected by fork() */
126 counter_u64_t v_vforkpages; /* (p) pages affected by vfork() */
127 counter_u64_t v_rforkpages; /* (p) pages affected by rfork() */
128 counter_u64_t v_kthreadpages; /* (p) ... and by kernel fork() */
129 #define VM_METER_NCOUNTERS \
130 (offsetof(struct vmmeter, v_page_size) / sizeof(counter_u64_t))
132 * Distribution of page usages.
134 u_int v_page_size; /* (c) page size in bytes */
135 u_int v_page_count; /* (c) total number of pages in system */
136 u_int v_free_reserved; /* (c) pages reserved for deadlock */
137 u_int v_free_target; /* (c) pages desired free */
138 u_int v_free_min; /* (c) pages desired free */
139 u_int v_inactive_target; /* (c) pages desired inactive */
140 u_int v_pageout_free_min; /* (c) min pages reserved for kernel */
141 u_int v_interrupt_free_min; /* (c) reserved pages for int code */
142 u_int v_free_severe; /* (c) severe page depletion point */
143 u_int v_wire_count VMMETER_ALIGNED; /* (a) pages wired down */
144 u_int v_active_count VMMETER_ALIGNED; /* (a) pages active */
145 u_int v_inactive_count VMMETER_ALIGNED; /* (a) pages inactive */
146 u_int v_laundry_count VMMETER_ALIGNED; /* (a) pages eligible for
148 u_int v_free_count VMMETER_ALIGNED; /* (f) pages free */
150 #endif /* _KERNEL || _WANT_VMMETER */
154 extern struct vmmeter vm_cnt;
155 extern u_int vm_pageout_wakeup_thresh;
157 #define VM_CNT_ADD(var, x) counter_u64_add(vm_cnt.var, x)
158 #define VM_CNT_INC(var) VM_CNT_ADD(var, 1)
159 #define VM_CNT_FETCH(var) counter_u64_fetch(vm_cnt.var)
162 * Return TRUE if we are under our severe low-free-pages threshold
164 * This routine is typically used at the user<->system interface to determine
165 * whether we need to block in order to avoid a low memory deadlock.
168 vm_page_count_severe(void)
171 return (vm_cnt.v_free_severe > vm_cnt.v_free_count);
175 * Return TRUE if we are under our minimum low-free-pages threshold.
177 * This routine is typically used within the system to determine whether
178 * we can execute potentially very expensive code in terms of memory. It
179 * is also used by the pageout daemon to calculate when to sleep, when
180 * to wake waiters up, and when (after making a pass) to become more
184 vm_page_count_min(void)
187 return (vm_cnt.v_free_min > vm_cnt.v_free_count);
191 * Return TRUE if we have not reached our free page target during
192 * free page recovery operations.
195 vm_page_count_target(void)
198 return (vm_cnt.v_free_target > vm_cnt.v_free_count);
202 * Return the number of pages we need to free-up or cache
203 * A positive number indicates that we do not have enough free pages.
206 vm_paging_target(void)
209 return (vm_cnt.v_free_target - vm_cnt.v_free_count);
213 * Returns TRUE if the pagedaemon needs to be woken up.
216 vm_paging_needed(u_int free_count)
219 return (free_count < vm_pageout_wakeup_thresh);
223 * Return the number of pages we need to launder.
224 * A positive number indicates that we have a shortfall of clean pages.
227 vm_laundry_target(void)
230 return (vm_paging_target());
233 #endif /* _SYS_VMMETER_H_ */