xref: /dragonfly/sys/sys/vmmeter.h (revision 7d84b73d)
1 /*-
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	@(#)vmmeter.h	8.2 (Berkeley) 7/10/94
30  * $FreeBSD: src/sys/sys/vmmeter.h,v 1.21.2.2 2002/10/10 19:28:21 dillon Exp $
31  */
32 
33 #ifndef _SYS_VMMETER_H_
34 #define _SYS_VMMETER_H_
35 
36 #ifndef _SYS_TYPES_H_
37 #include <sys/types.h>
38 #endif
39 
40 struct globaldata;
41 
42 /*
43  * System wide statistics counters.
44  */
45 struct vmmeter {
46 	/*
47 	 * General system activity.
48 	 */
49 #define vmmeter_uint_begin	v_swtch
50 	u_int v_swtch;		/* context switches */
51 	u_int v_trap;		/* calls to trap */
52 	u_int v_syscall;	/* calls to syscall() */
53 	u_int v_intr;		/* device interrupts */
54 	u_int v_ipi;		/* inter processor interrupts */
55 	u_int v_timer;		/* LAPIC timer interrupts */
56 	u_int v_soft;		/* software interrupts */
57 	/*
58 	 * Virtual memory activity.
59 	 */
60 	u_int v_vm_faults;	/* number of address memory faults */
61 	u_int v_cow_faults;	/* number of copy-on-writes */
62 	u_int v_cow_optim;	/* number of optimized copy-on-writes */
63 	u_int v_zfod;		/* pages zero filled on demand */
64 	u_int v_ozfod;		/* optimized zero fill pages */
65 	u_int v_swapin;		/* swap pager pageins */
66 	u_int v_swapout;	/* swap pager pageouts */
67 	u_int v_swappgsin;	/* swap pager pages paged in */
68 	u_int v_swappgsout;	/* swap pager pages paged out */
69 	u_int v_vnodein;	/* vnode pager pageins */
70 	u_int v_vnodeout;	/* vnode pager pageouts */
71 	u_int v_vnodepgsin;	/* vnode_pager pages paged in */
72 	u_int v_vnodepgsout;	/* vnode pager pages paged out */
73 	u_int v_intrans;	/* intransit blocking page faults */
74 	u_int v_reactivated;	/* number of pages reactivated from free list */
75 	u_int v_pdwakeups;	/* number of times daemon has awaken from sleep */
76 	u_int v_pdpages;	/* number of pages analyzed by daemon */
77 
78 	u_int v_dfree;		/* pages freed by daemon */
79 	u_int v_pfree;		/* pages freed by exiting processes */
80 	u_int v_tfree;		/* total pages freed */
81 	/*
82 	 * Fork/vfork/rfork activity.
83 	 */
84 	u_int v_forks;		/* number of fork() calls */
85 	u_int v_vforks;		/* number of vfork() calls */
86 	u_int v_rforks;		/* number of rfork() calls */
87 	u_int v_exec;		/* number of exec() calls */
88 	u_int v_kthreads;	/* number of fork() calls by kernel */
89 	u_int v_forkpages;	/* number of VM pages affected by fork() */
90 	u_int v_vforkpages;	/* number of VM pages affected by vfork() */
91 	u_int v_rforkpages;	/* number of VM pages affected by rfork() */
92 	u_int v_kthreadpages;	/* number of VM pages affected by fork() by kernel */
93 	u_int v_intrans_coll;	/* intransit map collisions (total) */
94 	u_int v_intrans_wait;	/* intransit map collisions which blocked */
95 	u_int v_forwarded_ints; /* forwarded interrupts due to MP lock */
96 	u_int v_forwarded_hits;
97 	u_int v_forwarded_misses;
98 	u_int v_smpinvltlb;	/* nasty global invltlbs */
99 	u_int v_ppwakeups;	/* wakeups on processes stalled on VM */
100 	u_int v_lock_colls;	/* # of token, lock, or spin collisions */
101 	u_int v_wakeup_colls;	/* possible spurious wakeup IPIs */
102 	u_int v_reserved7;
103 #define vmmeter_uint_end	v_reserved7
104 	char  v_lock_name[32];	/* last-colliding token, lock, or spin name */
105 	void  *v_lock_addr;	/* last-colliding lock address */
106 };
107 
108 /*
109  * vmstats structure, global vmstats is the rollup, pcpu vmstats keeps
110  * track of minor (generally positive) adjustments.  For moving targets,
111  * the global vmstats structure represents the smallest likely value.
112  *
113  * This structure is cache sensitive, separate nominal read-only elements
114  * from variable elements.
115  */
116 struct vmstats {
117 	/*
118 	 * Distribution of page usages.
119 	 */
120 	u_int v_page_size;	/* page size in bytes */
121 	u_int v_unused01;
122 	long v_page_count;	/* total number of pages in system */
123 	long v_free_severe;	/* severe depletion of pages below this pt */
124 	long v_free_reserved;	/* number of pages reserved for deadlock */
125 
126 	/*
127 	 * Free page queues, pageout daemon starts below when v_free_count
128 	 * goes below v_free_min.
129 	 */
130 	long v_free_min;	/* minimum free pages to maintain */
131 	long v_free_target;	/* pageout daemon loop target */
132 
133 	/*
134 	 * While operating, the pageout daemon pipelines up to N pages per
135 	 * loop, relooping as needed until all targets are achieved.
136 	 *
137 	 * active   -> inactive
138 	 * inactive -> cache	(1/4 of v_inactive_target)
139 	 */
140 	long v_inactive_target;	/* active -> inactive */
141 
142 	/*
143 	 * The pageout daemon also starts when (v_free_count + v_cache_count)
144 	 * goes below v_paging_start, and generally continues until it
145 	 * goes above v_paging_target2.
146 	 */
147 	long v_paging_wait;	/* vs (free + cache), stall user-land */
148 	long v_paging_start;	/* vs (free + cache), start paging */
149 	long v_paging_target1;	/* vs (free + cache), slow down paging */
150 	long v_paging_target2;	/* vs (free + cache), stop paging */
151 
152 	long v_pageout_free_min; /* min number pages reserved for kernel */
153 	long v_interrupt_free_min; /* reserved number of pages for int code */
154 	long v_dma_pages;	/* total dma-reserved pages */
155 
156 	long v_unused_fixed01;
157 	long v_unused_fixed02;
158 	long v_unused_fixed03;
159 
160 	long v_free_count;	/* number of pages free */
161 	long v_wire_count;	/* number of pages wired down */
162 	long v_active_count;	/* number of pages active */
163 	long v_inactive_count;	/* number of pages inactive */
164 	long v_cache_count;	/* number of pages on buffer cache queue */
165 	long v_dma_avail;	/* free dma-reserved pages */
166 
167 	long v_unused_variable[9];
168 };
169 
170 #ifdef _KERNEL
171 
172 /* note: vmmeter 'cnt' structure is now per-cpu */
173 extern struct vmstats vmstats;
174 
175 #endif
176 
177 /* systemwide totals computed every five seconds */
178 struct vmtotal {
179 	long	t_rq;		/* length of the run queue */
180 	long	t_dw;		/* jobs in ``disk wait'' (neg priority) */
181 	long	t_pw;		/* jobs in page wait */
182 	long	t_sl;		/* jobs sleeping in core */
183 	long	t_sw;		/* swapped out runnable/short block jobs */
184 	int64_t	t_vm;		/* total virtual memory */
185 	int64_t	t_avm;		/* active virtual memory */
186 	long	t_rm;		/* total real memory in use */
187 	long	t_arm;		/* active real memory */
188 	int64_t	t_vmshr;	/* shared virtual memory */
189 	int64_t	t_avmshr;	/* active shared virtual memory */
190 	long	t_rmshr;	/* shared real memory */
191 	long	t_armshr;	/* active shared real memory */
192 	long	t_free;		/* free memory pages */
193 };
194 
195 #ifdef PGINPROF
196 /*
197  * Optional instrumentation.
198  */
199 
200 #define	NDMON	128
201 #define	NSMON	128
202 
203 #define	DRES	20
204 #define	SRES	5
205 
206 #define	PMONMIN	20
207 #define	PRES	50
208 #define	NPMON	64
209 
210 #define	RMONMIN	130
211 #define	RRES	5
212 #define	NRMON	64
213 
214 /* data and stack size distribution counters */
215 u_int	dmon[NDMON+1];
216 u_int	smon[NSMON+1];
217 
218 /* page in time distribution counters */
219 u_int	pmon[NPMON+2];
220 
221 /* reclaim time distribution counters */
222 u_int	rmon[NRMON+2];
223 
224 int	pmonmin;
225 int	pres;
226 int	rmonmin;
227 int	rres;
228 
229 u_int rectime;		/* accumulator for reclaim times */
230 u_int pgintime;		/* accumulator for page in times */
231 
232 #endif	/* PGINPROF */
233 
234 #ifdef _KERNEL
235 
236 void vmstats_rollup(void);
237 void vmstats_rollup_cpu(struct globaldata *gd);
238 
239 #endif
240 #endif
241