This source file includes following definitions.
- uvm_meter
- uvm_loadav
- uvm_sysctl
- uvm_total
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 #include <sys/param.h>
45 #include <sys/proc.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <uvm/uvm_extern.h>
49 #include <sys/sysctl.h>
50 #include <sys/exec.h>
51
52 #ifdef UVM_SWAP_ENCRYPT
53 #include <uvm/uvm_swap.h>
54 #include <uvm/uvm_swap_encrypt.h>
55 #endif
56
57
58
59
60
61 int maxslp = MAXSLP;
62 struct loadavg averunnable;
63
64
65
66
67
68
69 static fixpt_t cexp[3] = {
70 0.9200444146293232 * FSCALE,
71 0.9834714538216174 * FSCALE,
72 0.9944598480048967 * FSCALE,
73 };
74
75
76
77
78
79 static void uvm_loadav(struct loadavg *);
80
81
82
83
84 void
85 uvm_meter()
86 {
87 if ((time_second % 5) == 0)
88 uvm_loadav(&averunnable);
89 if (proc0.p_slptime > (maxslp / 2))
90 wakeup(&proc0);
91 }
92
93
94
95
96
97 static void
98 uvm_loadav(avg)
99 struct loadavg *avg;
100 {
101 int i, nrun;
102 struct proc *p;
103
104 nrun = 0;
105 LIST_FOREACH(p, &allproc, p_list) {
106 switch (p->p_stat) {
107 case SSLEEP:
108 if (p->p_priority > PZERO || p->p_slptime > 1)
109 continue;
110
111 case SRUN:
112 case SIDL:
113 case SONPROC:
114 nrun++;
115 }
116 }
117 for (i = 0; i < 3; i++)
118 avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
119 nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
120 }
121
122
123
124
125 int
126 uvm_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
127 int *name;
128 u_int namelen;
129 void *oldp;
130 size_t *oldlenp;
131 void *newp;
132 size_t newlen;
133 struct proc *p;
134 {
135 struct vmtotal vmtotals;
136 int rv, t;
137 struct _ps_strings _ps = { PS_STRINGS };
138
139 switch (name[0]) {
140 case VM_SWAPENCRYPT:
141 #ifdef UVM_SWAP_ENCRYPT
142 return (swap_encrypt_ctl(name + 1, namelen - 1, oldp, oldlenp,
143 newp, newlen, p));
144 #else
145 return (EOPNOTSUPP);
146 #endif
147 default:
148
149 if (namelen != 1)
150 return (ENOTDIR);
151 break;
152 }
153
154 switch (name[0]) {
155 case VM_LOADAVG:
156 return (sysctl_rdstruct(oldp, oldlenp, newp, &averunnable,
157 sizeof(averunnable)));
158
159 case VM_METER:
160 uvm_total(&vmtotals);
161 return (sysctl_rdstruct(oldp, oldlenp, newp, &vmtotals,
162 sizeof(vmtotals)));
163
164 case VM_UVMEXP:
165 return (sysctl_rdstruct(oldp, oldlenp, newp, &uvmexp,
166 sizeof(uvmexp)));
167
168 case VM_NKMEMPAGES:
169 return (sysctl_rdint(oldp, oldlenp, newp, nkmempages));
170
171 case VM_PSSTRINGS:
172 return (sysctl_rdstruct(oldp, oldlenp, newp, &_ps,
173 sizeof(_ps)));
174 case VM_ANONMIN:
175 t = uvmexp.anonminpct;
176 rv = sysctl_int(oldp, oldlenp, newp, newlen, &t);
177 if (rv) {
178 return rv;
179 }
180 if (t + uvmexp.vtextminpct + uvmexp.vnodeminpct > 95 || t < 0) {
181 return EINVAL;
182 }
183 uvmexp.anonminpct = t;
184 uvmexp.anonmin = t * 256 / 100;
185 return rv;
186
187 case VM_VTEXTMIN:
188 t = uvmexp.vtextminpct;
189 rv = sysctl_int(oldp, oldlenp, newp, newlen, &t);
190 if (rv) {
191 return rv;
192 }
193 if (uvmexp.anonminpct + t + uvmexp.vnodeminpct > 95 || t < 0) {
194 return EINVAL;
195 }
196 uvmexp.vtextminpct = t;
197 uvmexp.vtextmin = t * 256 / 100;
198 return rv;
199
200 case VM_VNODEMIN:
201 t = uvmexp.vnodeminpct;
202 rv = sysctl_int(oldp, oldlenp, newp, newlen, &t);
203 if (rv) {
204 return rv;
205 }
206 if (uvmexp.anonminpct + uvmexp.vtextminpct + t > 95 || t < 0) {
207 return EINVAL;
208 }
209 uvmexp.vnodeminpct = t;
210 uvmexp.vnodemin = t * 256 / 100;
211 return rv;
212
213 case VM_MAXSLP:
214 return (sysctl_rdint(oldp, oldlenp, newp, maxslp));
215
216 case VM_USPACE:
217 return (sysctl_rdint(oldp, oldlenp, newp, USPACE));
218
219 default:
220 return (EOPNOTSUPP);
221 }
222
223 }
224
225
226
227
228 void
229 uvm_total(totalp)
230 struct vmtotal *totalp;
231 {
232 struct proc *p;
233 #if 0
234 struct vm_map_entry * entry;
235 struct vm_map *map;
236 int paging;
237 #endif
238
239 memset(totalp, 0, sizeof *totalp);
240
241
242
243
244
245 LIST_FOREACH(p, &allproc, p_list) {
246 if (p->p_flag & P_SYSTEM)
247 continue;
248 switch (p->p_stat) {
249 case 0:
250 continue;
251
252 case SSLEEP:
253 case SSTOP:
254 if (p->p_priority <= PZERO)
255 totalp->t_dw++;
256 else if (p->p_slptime < maxslp)
257 totalp->t_sl++;
258 if (p->p_slptime >= maxslp)
259 continue;
260 break;
261
262 case SRUN:
263 case SIDL:
264 case SONPROC:
265 totalp->t_rq++;
266 if (p->p_stat == SIDL)
267 continue;
268 break;
269 }
270
271
272
273 #if 0
274
275
276
277
278 paging = 0;
279 vm_map_lock(map);
280 for (map = &p->p_vmspace->vm_map, entry = map->header.next;
281 entry != &map->header; entry = entry->next) {
282 if (entry->is_a_map || entry->is_sub_map ||
283 entry->object.uvm_obj == NULL)
284 continue;
285
286 }
287 vm_map_unlock(map);
288 if (paging)
289 totalp->t_pw++;
290 #endif
291 }
292
293
294
295 totalp->t_free = uvmexp.free;
296 totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
297 totalp->t_avm = uvmexp.active + uvmexp.swpginuse;
298 totalp->t_rm = uvmexp.npages - uvmexp.free;
299 totalp->t_arm = uvmexp.active;
300 totalp->t_vmshr = 0;
301 totalp->t_avmshr = 0;
302 totalp->t_rmshr = 0;
303 totalp->t_armshr = 0;
304 }