]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/vmmeter.h
This commit was generated by cvs2svn to compensate for changes in r171366,
[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  * 4. 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$
31  */
32
33 #ifndef _SYS_VMMETER_H_
34 #define _SYS_VMMETER_H_
35
36 /*
37  * System wide statistics counters.
38  * Locking:
39  *      a - locked by atomic operations
40  *      c - constant after initialization
41  *      f - locked by vm_page_queue_free_mtx
42  *      p - locked by being in the PCPU and atomicity respect to interrupts
43  *      q - locked by vm_page_queue_mtx
44  */
45 struct vmmeter {
46         /*
47          * General system activity.
48          */
49         u_int v_swtch;          /* (p) context switches */
50         u_int v_trap;           /* (p) calls to trap */
51         u_int v_syscall;        /* (p) calls to syscall() */
52         u_int v_intr;           /* (p) device interrupts */
53         u_int v_soft;           /* (p) software interrupts */
54         /*
55          * Virtual memory activity.
56          */
57         u_int v_vm_faults;      /* (p) address memory faults */
58         u_int v_cow_faults;     /* (p) copy-on-writes faults */
59         u_int v_cow_optim;      /* (p) optimized copy-on-writes faults */
60         u_int v_zfod;           /* (p) pages zero filled on demand */
61         u_int v_ozfod;          /* (p) optimized zero fill pages */
62         u_int v_swapin;         /* (p) swap pager pageins */
63         u_int v_swapout;        /* (p) swap pager pageouts */
64         u_int v_swappgsin;      /* (p) swap pager pages paged in */
65         u_int v_swappgsout;     /* (p) swap pager pages paged out */
66         u_int v_vnodein;        /* (p) vnode pager pageins */
67         u_int v_vnodeout;       /* (p) vnode pager pageouts */
68         u_int v_vnodepgsin;     /* (p) vnode_pager pages paged in */
69         u_int v_vnodepgsout;    /* (p) vnode pager pages paged out */
70         u_int v_intrans;        /* (p) intransit blocking page faults */
71         u_int v_reactivated;    /* (q) pages reactivated from free list */
72         u_int v_pdwakeups;      /* (f) times daemon has awaken from sleep */
73         u_int v_pdpages;        /* (q) pages analyzed by daemon */
74
75         u_int v_dfree;          /* (q) pages freed by daemon */
76         u_int v_pfree;          /* (q) pages freed by exiting processes */
77         u_int v_tfree;          /* (p) total pages freed */
78         /*
79          * Distribution of page usages.
80          */
81         u_int v_page_size;      /* (c) page size in bytes */
82         u_int v_page_count;     /* (c) total number of pages in system */
83         u_int v_free_reserved;  /* (c) pages reserved for deadlock */
84         u_int v_free_target;    /* (c) pages desired free */
85         u_int v_free_min;       /* (c) pages desired free */
86         u_int v_free_count;     /* (f) pages free */
87         u_int v_wire_count;     /* (a) pages wired down */
88         u_int v_active_count;   /* (q) pages active */
89         u_int v_inactive_target; /* (c) pages desired inactive */
90         u_int v_inactive_count; /* (q) pages inactive */
91         u_int v_cache_count;    /* (q) pages on buffer cache queue */
92         u_int v_cache_min;      /* (c) min pages desired on cache queue */
93         u_int v_cache_max;      /* (c) max pages in cached obj */
94         u_int v_pageout_free_min;   /* (c) min pages reserved for kernel */
95         u_int v_interrupt_free_min; /* (c) reserved pages for int code */
96         u_int v_free_severe;    /* (c) severe page depletion point */
97         /*
98          * Fork/vfork/rfork activity.
99          */
100         u_int v_forks;          /* (p) fork() calls */
101         u_int v_vforks;         /* (p) vfork() calls */
102         u_int v_rforks;         /* (p) rfork() calls */
103         u_int v_kthreads;       /* (p) fork() calls by kernel */
104         u_int v_forkpages;      /* (p) VM pages affected by fork() */
105         u_int v_vforkpages;     /* (p) VM pages affected by vfork() */
106         u_int v_rforkpages;     /* (p) VM pages affected by rfork() */
107         u_int v_kthreadpages;   /* (p) VM pages affected by fork() by kernel */
108 };
109 #ifdef _KERNEL
110
111 extern struct vmmeter cnt;
112
113 /*
114  * Return TRUE if we are under our reserved low-free-pages threshold
115  */
116
117 static __inline 
118 int
119 vm_page_count_reserved(void)
120 {
121     return (cnt.v_free_reserved > (cnt.v_free_count + cnt.v_cache_count));
122 }
123
124 /*
125  * Return TRUE if we are under our severe low-free-pages threshold
126  *
127  * This routine is typically used at the user<->system interface to determine
128  * whether we need to block in order to avoid a low memory deadlock.
129  */
130
131 static __inline 
132 int
133 vm_page_count_severe(void)
134 {
135     return (cnt.v_free_severe > (cnt.v_free_count + cnt.v_cache_count));
136 }
137
138 /*
139  * Return TRUE if we are under our minimum low-free-pages threshold.
140  *
141  * This routine is typically used within the system to determine whether
142  * we can execute potentially very expensive code in terms of memory.  It
143  * is also used by the pageout daemon to calculate when to sleep, when
144  * to wake waiters up, and when (after making a pass) to become more
145  * desparate.
146  */
147
148 static __inline 
149 int
150 vm_page_count_min(void)
151 {
152     return (cnt.v_free_min > (cnt.v_free_count + cnt.v_cache_count));
153 }
154
155 /*
156  * Return TRUE if we have not reached our free page target during
157  * free page recovery operations.
158  */
159
160 static __inline 
161 int
162 vm_page_count_target(void)
163 {
164     return (cnt.v_free_target > (cnt.v_free_count + cnt.v_cache_count));
165 }
166
167 /*
168  * Return the number of pages we need to free-up or cache
169  * A positive number indicates that we do not have enough free pages.
170  */
171
172 static __inline 
173 int
174 vm_paging_target(void)
175 {
176     return (
177         (cnt.v_free_target + cnt.v_cache_min) -
178         (cnt.v_free_count + cnt.v_cache_count)
179     );
180 }
181
182 /*
183  * Returns TRUE if the pagedaemon needs to be woken up.
184  */
185
186 static __inline 
187 int
188 vm_paging_needed(void)
189 {
190     return (
191         (cnt.v_free_reserved + cnt.v_cache_min) >
192         (cnt.v_free_count + cnt.v_cache_count)
193     );
194 }
195
196 #endif
197
198 /* systemwide totals computed every five seconds */
199 struct vmtotal {
200         int16_t t_rq;           /* length of the run queue */
201         int16_t t_dw;           /* jobs in ``disk wait'' (neg priority) */
202         int16_t t_pw;           /* jobs in page wait */
203         int16_t t_sl;           /* jobs sleeping in core */
204         int16_t t_sw;           /* swapped out runnable/short block jobs */
205         int32_t t_vm;           /* total virtual memory */
206         int32_t t_avm;          /* active virtual memory */
207         int32_t t_rm;           /* total real memory in use */
208         int32_t t_arm;          /* active real memory */
209         int32_t t_vmshr;        /* shared virtual memory */
210         int32_t t_avmshr;       /* active shared virtual memory */
211         int32_t t_rmshr;        /* shared real memory */
212         int32_t t_armshr;       /* active shared real memory */
213         int32_t t_free;         /* free memory pages */
214 };
215
216 #endif