]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/vmmeter.h
This commit was generated by cvs2svn to compensate for changes in r67615,
[FreeBSD/FreeBSD.git] / sys / sys / vmmeter.h
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. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      @(#)vmmeter.h   8.2 (Berkeley) 7/10/94
34  * $FreeBSD$
35  */
36
37 #ifndef _SYS_VMMETER_H_
38 #define _SYS_VMMETER_H_
39
40 /*
41  * System wide statistics counters.
42  */
43 struct vmmeter {
44         /*
45          * General system activity.
46          */
47         u_int v_swtch;          /* context switches */
48         u_int v_trap;           /* calls to trap */
49         u_int v_syscall;        /* calls to syscall() */
50         u_int v_intr;           /* device interrupts */
51         u_int v_soft;           /* software interrupts */
52         /*
53          * Virtual memory activity.
54          */
55         u_int v_vm_faults;      /* number of address memory faults */
56         u_int v_cow_faults;     /* number of copy-on-writes */
57         u_int v_cow_optim;      /* number of optimized copy-on-writes */
58         u_int v_zfod;           /* pages zero filled on demand */
59         u_int v_ozfod;          /* optimized zero fill pages */
60         u_int v_swapin;         /* swap pager pageins */
61         u_int v_swapout;        /* swap pager pageouts */
62         u_int v_swappgsin;      /* swap pager pages paged in */
63         u_int v_swappgsout;     /* swap pager pages paged out */
64         u_int v_vnodein;        /* vnode pager pageins */
65         u_int v_vnodeout;       /* vnode pager pageouts */
66         u_int v_vnodepgsin;     /* vnode_pager pages paged in */
67         u_int v_vnodepgsout;    /* vnode pager pages paged out */
68         u_int v_intrans;        /* intransit blocking page faults */
69         u_int v_reactivated;    /* number of pages reactivated from free list */
70         u_int v_pdwakeups;      /* number of times daemon has awaken from sleep */
71         u_int v_pdpages;        /* number of pages analyzed by daemon */
72
73         u_int v_dfree;          /* pages freed by daemon */
74         u_int v_pfree;          /* pages freed by exiting processes */
75         u_int v_tfree;          /* total pages freed */
76         /*
77          * Distribution of page usages.
78          */
79         u_int v_page_size;      /* page size in bytes */
80         u_int v_page_count;     /* total number of pages in system */
81         u_int v_free_reserved;  /* number of pages reserved for deadlock */
82         u_int v_free_target;    /* number of pages desired free */
83         u_int v_free_min;       /* minimum number of pages desired free */
84         u_int v_free_count;     /* number of pages free */
85         u_int v_wire_count;     /* number of pages wired down */
86         u_int v_active_count;   /* number of pages active */
87         u_int v_inactive_target; /* number of pages desired inactive */
88         u_int v_inactive_count; /* number of pages inactive */
89         u_int v_cache_count;    /* number of pages on buffer cache queue */
90         u_int v_cache_min;      /* min number of pages desired on cache queue */
91         u_int v_cache_max;      /* max number of pages in cached obj */
92         u_int v_pageout_free_min;   /* min number pages reserved for kernel */
93         u_int v_interrupt_free_min; /* reserved number of pages for int code */
94         u_int v_free_severe;    /* severe depletion of pages below this pt */
95 };
96 #ifdef _KERNEL
97
98 extern struct vmmeter cnt;
99
100 /*
101  * Return TRUE if we are under our reserved low-free-pages threshold
102  */
103
104 static __inline 
105 int
106 vm_page_count_reserved(void)
107 {
108     return (cnt.v_free_reserved > (cnt.v_free_count + cnt.v_cache_count));
109 }
110
111 /*
112  * Return TRUE if we are under our severe low-free-pages threshold
113  *
114  * This routine is typically used at the user<->system interface to determine
115  * whether we need to block in order to avoid a low memory deadlock.
116  */
117
118 static __inline 
119 int
120 vm_page_count_severe(void)
121 {
122     return (cnt.v_free_severe > (cnt.v_free_count + cnt.v_cache_count));
123 }
124
125 /*
126  * Return TRUE if we are under our minimum low-free-pages threshold.
127  *
128  * This routine is typically used within the system to determine whether
129  * we can execute potentially very expensive code in terms of memory.  It
130  * is also used by the pageout daemon to calculate when to sleep, when
131  * to wake waiters up, and when (after making a pass) to become more
132  * desparate.
133  */
134
135 static __inline 
136 int
137 vm_page_count_min(void)
138 {
139     return (cnt.v_free_min > (cnt.v_free_count + cnt.v_cache_count));
140 }
141
142 /*
143  * Return TRUE if we have not reached our free page target during
144  * free page recovery operations.
145  */
146
147 static __inline 
148 int
149 vm_page_count_target(void)
150 {
151     return (cnt.v_free_target > (cnt.v_free_count + cnt.v_cache_count));
152 }
153
154 /*
155  * Return the number of pages we need to free-up or cache
156  * A positive number indicates that we do not have enough free pages.
157  */
158
159 static __inline 
160 int
161 vm_paging_target(void)
162 {
163     return (
164         (cnt.v_free_target + cnt.v_cache_min) - 
165         (cnt.v_free_count + cnt.v_cache_count)
166     );
167 }
168
169 /*
170  * Return a positive number if the pagedaemon needs to be woken up.
171  */
172
173 static __inline 
174 int
175 vm_paging_needed(void)
176 {
177     return (
178         (cnt.v_free_reserved + cnt.v_cache_min) >
179         (cnt.v_free_count + cnt.v_cache_count)
180     );
181 }
182
183 #endif
184
185 /* systemwide totals computed every five seconds */
186 struct vmtotal
187 {
188         int16_t t_rq;           /* length of the run queue */
189         int16_t t_dw;           /* jobs in ``disk wait'' (neg priority) */
190         int16_t t_pw;           /* jobs in page wait */
191         int16_t t_sl;           /* jobs sleeping in core */
192         int16_t t_sw;           /* swapped out runnable/short block jobs */
193         int32_t t_vm;           /* total virtual memory */
194         int32_t t_avm;          /* active virtual memory */
195         int32_t t_rm;           /* total real memory in use */
196         int32_t t_arm;          /* active real memory */
197         int32_t t_vmshr;        /* shared virtual memory */
198         int32_t t_avmshr;       /* active shared virtual memory */
199         int32_t t_rmshr;        /* shared real memory */
200         int32_t t_armshr;       /* active shared real memory */
201         int32_t t_free;         /* free memory pages */
202 };
203
204 /*
205  * Optional instrumentation.
206  */
207 #ifdef PGINPROF
208
209 #define NDMON   128
210 #define NSMON   128
211
212 #define DRES    20
213 #define SRES    5
214
215 #define PMONMIN 20
216 #define PRES    50
217 #define NPMON   64
218
219 #define RMONMIN 130
220 #define RRES    5
221 #define NRMON   64
222
223 /* data and stack size distribution counters */
224 u_int   dmon[NDMON+1];
225 u_int   smon[NSMON+1];
226
227 /* page in time distribution counters */
228 u_int   pmon[NPMON+2];
229
230 /* reclaim time distribution counters */
231 u_int   rmon[NRMON+2];
232
233 int     pmonmin;
234 int     pres;
235 int     rmonmin;
236 int     rres;
237
238 u_int rectime;          /* accumulator for reclaim times */
239 u_int pgintime;         /* accumulator for page in times */
240 #endif
241
242 #endif