uvm_meter.c revision 1.49 1 1.49 ad /* $NetBSD: uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 1.1 mrg * Copyright (c) 1982, 1986, 1989, 1993
6 1.19 chs * The Regents of the University of California.
7 1.1 mrg *
8 1.1 mrg * All rights reserved.
9 1.1 mrg *
10 1.1 mrg * Redistribution and use in source and binary forms, with or without
11 1.1 mrg * modification, are permitted provided that the following conditions
12 1.1 mrg * are met:
13 1.1 mrg * 1. Redistributions of source code must retain the above copyright
14 1.1 mrg * notice, this list of conditions and the following disclaimer.
15 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mrg * notice, this list of conditions and the following disclaimer in the
17 1.1 mrg * documentation and/or other materials provided with the distribution.
18 1.1 mrg * 3. All advertising materials mentioning features or use of this software
19 1.1 mrg * must display the following acknowledgement:
20 1.1 mrg * This product includes software developed by Charles D. Cranor,
21 1.19 chs * Washington University, and the University of California, Berkeley
22 1.1 mrg * and its contributors.
23 1.1 mrg * 4. Neither the name of the University nor the names of its contributors
24 1.1 mrg * may be used to endorse or promote products derived from this software
25 1.1 mrg * without specific prior written permission.
26 1.1 mrg *
27 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 mrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 mrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 mrg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 mrg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 mrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 mrg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 mrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 mrg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 mrg * SUCH DAMAGE.
38 1.1 mrg *
39 1.1 mrg * @(#)vm_meter.c 8.4 (Berkeley) 1/4/94
40 1.3 mrg * from: Id: uvm_meter.c,v 1.1.2.1 1997/08/14 19:10:35 chuck Exp
41 1.1 mrg */
42 1.22 lukem
43 1.22 lukem #include <sys/cdefs.h>
44 1.49 ad __KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp $");
45 1.1 mrg
46 1.1 mrg #include <sys/param.h>
47 1.1 mrg #include <sys/proc.h>
48 1.1 mrg #include <sys/systm.h>
49 1.1 mrg #include <sys/kernel.h>
50 1.41 yamt #include <sys/sysctl.h>
51 1.41 yamt
52 1.13 mrg #include <uvm/uvm_extern.h>
53 1.41 yamt #include <uvm/uvm_pdpolicy.h>
54 1.1 mrg
55 1.1 mrg /*
56 1.1 mrg * maxslp: ???? XXXCDC
57 1.1 mrg */
58 1.1 mrg
59 1.1 mrg int maxslp = MAXSLP; /* patchable ... */
60 1.14 chs struct loadavg averunnable;
61 1.1 mrg
62 1.1 mrg /*
63 1.19 chs * constants for averages over 1, 5, and 15 minutes when sampling at
64 1.1 mrg * 5 second intervals.
65 1.1 mrg */
66 1.1 mrg
67 1.35 thorpej static const fixpt_t cexp[3] = {
68 1.1 mrg 0.9200444146293232 * FSCALE, /* exp(-1/12) */
69 1.1 mrg 0.9834714538216174 * FSCALE, /* exp(-1/60) */
70 1.1 mrg 0.9944598480048967 * FSCALE, /* exp(-1/180) */
71 1.1 mrg };
72 1.1 mrg
73 1.1 mrg /*
74 1.1 mrg * prototypes
75 1.1 mrg */
76 1.1 mrg
77 1.30 junyoung static void uvm_loadav(struct loadavg *);
78 1.30 junyoung static void uvm_total(struct vmtotal *);
79 1.1 mrg
80 1.1 mrg /*
81 1.1 mrg * uvm_meter: calculate load average and wake up the swapper (if needed)
82 1.1 mrg */
83 1.4 mrg void
84 1.35 thorpej uvm_meter(void)
85 1.1 mrg {
86 1.45 ad static int count;
87 1.45 ad
88 1.45 ad if (++count >= 5) {
89 1.45 ad count = 0;
90 1.4 mrg uvm_loadav(&averunnable);
91 1.45 ad }
92 1.24 thorpej if (lwp0.l_slptime > (maxslp / 2))
93 1.45 ad uvm_kick_scheduler();
94 1.1 mrg }
95 1.1 mrg
96 1.1 mrg /*
97 1.19 chs * uvm_loadav: compute a tenex style load average of a quantity on
98 1.45 ad * 1, 5, and 15 minute intervals.
99 1.45 ad */
100 1.4 mrg static void
101 1.35 thorpej uvm_loadav(struct loadavg *avg)
102 1.1 mrg {
103 1.4 mrg int i, nrun;
104 1.24 thorpej struct lwp *l;
105 1.1 mrg
106 1.45 ad nrun = 0;
107 1.45 ad
108 1.48 ad mutex_enter(proc_lock);
109 1.24 thorpej LIST_FOREACH(l, &alllwp, l_list) {
110 1.46 pavel if ((l->l_flag & (LW_SINTR | LW_SYSTEM)) != 0)
111 1.45 ad continue;
112 1.24 thorpej switch (l->l_stat) {
113 1.24 thorpej case LSSLEEP:
114 1.45 ad if (l->l_slptime > 1)
115 1.4 mrg continue;
116 1.4 mrg /* fall through */
117 1.24 thorpej case LSRUN:
118 1.24 thorpej case LSONPROC:
119 1.24 thorpej case LSIDL:
120 1.4 mrg nrun++;
121 1.4 mrg }
122 1.4 mrg }
123 1.48 ad mutex_exit(proc_lock);
124 1.45 ad
125 1.4 mrg for (i = 0; i < 3; i++)
126 1.4 mrg avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
127 1.4 mrg nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
128 1.1 mrg }
129 1.1 mrg
130 1.1 mrg /*
131 1.27 atatat * sysctl helper routine for the vm.vmmeter node.
132 1.1 mrg */
133 1.27 atatat static int
134 1.27 atatat sysctl_vm_meter(SYSCTLFN_ARGS)
135 1.1 mrg {
136 1.27 atatat struct sysctlnode node;
137 1.4 mrg struct vmtotal vmtotals;
138 1.1 mrg
139 1.27 atatat node = *rnode;
140 1.27 atatat node.sysctl_data = &vmtotals;
141 1.27 atatat uvm_total(&vmtotals);
142 1.23 chs
143 1.27 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
144 1.27 atatat }
145 1.23 chs
146 1.27 atatat /*
147 1.27 atatat * sysctl helper routine for the vm.uvmexp node.
148 1.27 atatat */
149 1.27 atatat static int
150 1.27 atatat sysctl_vm_uvmexp(SYSCTLFN_ARGS)
151 1.27 atatat {
152 1.27 atatat struct sysctlnode node;
153 1.23 chs
154 1.27 atatat node = *rnode;
155 1.27 atatat if (oldp)
156 1.27 atatat node.sysctl_size = min(*oldlenp, node.sysctl_size);
157 1.23 chs
158 1.27 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
159 1.15 simonb }
160 1.15 simonb
161 1.15 simonb static int
162 1.27 atatat sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
163 1.15 simonb {
164 1.27 atatat struct sysctlnode node;
165 1.15 simonb struct uvmexp_sysctl u;
166 1.41 yamt int active, inactive;
167 1.41 yamt
168 1.41 yamt uvm_estimatepageable(&active, &inactive);
169 1.15 simonb
170 1.16 simonb memset(&u, 0, sizeof(u));
171 1.16 simonb
172 1.16 simonb /* Entries here are in order of uvmexp_sysctl, not uvmexp */
173 1.15 simonb u.pagesize = uvmexp.pagesize;
174 1.15 simonb u.pagemask = uvmexp.pagemask;
175 1.15 simonb u.pageshift = uvmexp.pageshift;
176 1.15 simonb u.npages = uvmexp.npages;
177 1.15 simonb u.free = uvmexp.free;
178 1.41 yamt u.active = active;
179 1.41 yamt u.inactive = inactive;
180 1.15 simonb u.paging = uvmexp.paging;
181 1.15 simonb u.wired = uvmexp.wired;
182 1.15 simonb u.zeropages = uvmexp.zeropages;
183 1.15 simonb u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
184 1.15 simonb u.reserve_kernel = uvmexp.reserve_kernel;
185 1.15 simonb u.freemin = uvmexp.freemin;
186 1.15 simonb u.freetarg = uvmexp.freetarg;
187 1.41 yamt u.inactarg = 0; /* unused */
188 1.15 simonb u.wiredmax = uvmexp.wiredmax;
189 1.15 simonb u.nswapdev = uvmexp.nswapdev;
190 1.15 simonb u.swpages = uvmexp.swpages;
191 1.15 simonb u.swpginuse = uvmexp.swpginuse;
192 1.15 simonb u.swpgonly = uvmexp.swpgonly;
193 1.15 simonb u.nswget = uvmexp.nswget;
194 1.15 simonb u.faults = uvmexp.faults;
195 1.15 simonb u.traps = uvmexp.traps;
196 1.15 simonb u.intrs = uvmexp.intrs;
197 1.15 simonb u.swtch = uvmexp.swtch;
198 1.15 simonb u.softs = uvmexp.softs;
199 1.15 simonb u.syscalls = uvmexp.syscalls;
200 1.15 simonb u.pageins = uvmexp.pageins;
201 1.15 simonb u.swapins = uvmexp.swapins;
202 1.15 simonb u.swapouts = uvmexp.swapouts;
203 1.15 simonb u.pgswapin = uvmexp.pgswapin;
204 1.15 simonb u.pgswapout = uvmexp.pgswapout;
205 1.15 simonb u.forks = uvmexp.forks;
206 1.15 simonb u.forks_ppwait = uvmexp.forks_ppwait;
207 1.15 simonb u.forks_sharevm = uvmexp.forks_sharevm;
208 1.15 simonb u.pga_zerohit = uvmexp.pga_zerohit;
209 1.15 simonb u.pga_zeromiss = uvmexp.pga_zeromiss;
210 1.15 simonb u.zeroaborts = uvmexp.zeroaborts;
211 1.15 simonb u.fltnoram = uvmexp.fltnoram;
212 1.15 simonb u.fltnoanon = uvmexp.fltnoanon;
213 1.15 simonb u.fltpgwait = uvmexp.fltpgwait;
214 1.15 simonb u.fltpgrele = uvmexp.fltpgrele;
215 1.15 simonb u.fltrelck = uvmexp.fltrelck;
216 1.15 simonb u.fltrelckok = uvmexp.fltrelckok;
217 1.15 simonb u.fltanget = uvmexp.fltanget;
218 1.15 simonb u.fltanretry = uvmexp.fltanretry;
219 1.15 simonb u.fltamcopy = uvmexp.fltamcopy;
220 1.15 simonb u.fltnamap = uvmexp.fltnamap;
221 1.15 simonb u.fltnomap = uvmexp.fltnomap;
222 1.15 simonb u.fltlget = uvmexp.fltlget;
223 1.15 simonb u.fltget = uvmexp.fltget;
224 1.15 simonb u.flt_anon = uvmexp.flt_anon;
225 1.15 simonb u.flt_acow = uvmexp.flt_acow;
226 1.15 simonb u.flt_obj = uvmexp.flt_obj;
227 1.15 simonb u.flt_prcopy = uvmexp.flt_prcopy;
228 1.15 simonb u.flt_przero = uvmexp.flt_przero;
229 1.15 simonb u.pdwoke = uvmexp.pdwoke;
230 1.15 simonb u.pdrevs = uvmexp.pdrevs;
231 1.15 simonb u.pdswout = uvmexp.pdswout;
232 1.15 simonb u.pdfreed = uvmexp.pdfreed;
233 1.15 simonb u.pdscans = uvmexp.pdscans;
234 1.15 simonb u.pdanscan = uvmexp.pdanscan;
235 1.15 simonb u.pdobscan = uvmexp.pdobscan;
236 1.15 simonb u.pdreact = uvmexp.pdreact;
237 1.15 simonb u.pdbusy = uvmexp.pdbusy;
238 1.15 simonb u.pdpageouts = uvmexp.pdpageouts;
239 1.15 simonb u.pdpending = uvmexp.pdpending;
240 1.15 simonb u.pddeact = uvmexp.pddeact;
241 1.16 simonb u.anonpages = uvmexp.anonpages;
242 1.23 chs u.filepages = uvmexp.filepages;
243 1.23 chs u.execpages = uvmexp.execpages;
244 1.18 thorpej u.colorhit = uvmexp.colorhit;
245 1.18 thorpej u.colormiss = uvmexp.colormiss;
246 1.49 ad u.cpuhit = uvmexp.cpuhit;
247 1.49 ad u.cpumiss = uvmexp.cpumiss;
248 1.15 simonb
249 1.27 atatat node = *rnode;
250 1.27 atatat node.sysctl_data = &u;
251 1.27 atatat node.sysctl_size = sizeof(u);
252 1.27 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
253 1.27 atatat }
254 1.27 atatat
255 1.27 atatat /*
256 1.38 yamt * sysctl helper routine for uvm_pctparam.
257 1.38 yamt */
258 1.38 yamt static int
259 1.41 yamt uvm_sysctlpctparam(SYSCTLFN_ARGS)
260 1.38 yamt {
261 1.38 yamt int t, error;
262 1.38 yamt struct sysctlnode node;
263 1.38 yamt struct uvm_pctparam *pct;
264 1.38 yamt
265 1.38 yamt pct = rnode->sysctl_data;
266 1.38 yamt t = pct->pct_pct;
267 1.38 yamt
268 1.38 yamt node = *rnode;
269 1.38 yamt node.sysctl_data = &t;
270 1.38 yamt error = sysctl_lookup(SYSCTLFN_CALL(&node));
271 1.38 yamt if (error || newp == NULL)
272 1.38 yamt return error;
273 1.38 yamt
274 1.38 yamt if (t < 0 || t > 100)
275 1.38 yamt return EINVAL;
276 1.38 yamt
277 1.41 yamt error = uvm_pctparam_check(pct, t);
278 1.41 yamt if (error) {
279 1.41 yamt return error;
280 1.41 yamt }
281 1.38 yamt uvm_pctparam_set(pct, t);
282 1.38 yamt
283 1.38 yamt return (0);
284 1.38 yamt }
285 1.38 yamt
286 1.38 yamt /*
287 1.27 atatat * uvm_sysctl: sysctl hook into UVM system.
288 1.27 atatat */
289 1.27 atatat SYSCTL_SETUP(sysctl_vm_setup, "sysctl vm subtree setup")
290 1.27 atatat {
291 1.27 atatat
292 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
293 1.31 atatat CTLFLAG_PERMANENT,
294 1.27 atatat CTLTYPE_NODE, "vm", NULL,
295 1.27 atatat NULL, 0, NULL, 0,
296 1.27 atatat CTL_VM, CTL_EOL);
297 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
298 1.31 atatat CTLFLAG_PERMANENT,
299 1.32 atatat CTLTYPE_STRUCT, "vmmeter",
300 1.32 atatat SYSCTL_DESCR("Simple system-wide virtual memory "
301 1.32 atatat "statistics"),
302 1.27 atatat sysctl_vm_meter, 0, NULL, sizeof(struct vmtotal),
303 1.27 atatat CTL_VM, VM_METER, CTL_EOL);
304 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
305 1.31 atatat CTLFLAG_PERMANENT,
306 1.32 atatat CTLTYPE_STRUCT, "loadavg",
307 1.32 atatat SYSCTL_DESCR("System load average history"),
308 1.27 atatat NULL, 0, &averunnable, sizeof(averunnable),
309 1.27 atatat CTL_VM, VM_LOADAVG, CTL_EOL);
310 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
311 1.31 atatat CTLFLAG_PERMANENT,
312 1.32 atatat CTLTYPE_STRUCT, "uvmexp",
313 1.32 atatat SYSCTL_DESCR("Detailed system-wide virtual memory "
314 1.32 atatat "statistics"),
315 1.27 atatat sysctl_vm_uvmexp, 0, &uvmexp, sizeof(uvmexp),
316 1.27 atatat CTL_VM, VM_UVMEXP, CTL_EOL);
317 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
318 1.31 atatat CTLFLAG_PERMANENT,
319 1.32 atatat CTLTYPE_INT, "nkmempages",
320 1.32 atatat SYSCTL_DESCR("Default number of pages in kmem_map"),
321 1.27 atatat NULL, 0, &nkmempages, 0,
322 1.27 atatat CTL_VM, VM_NKMEMPAGES, CTL_EOL);
323 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
324 1.31 atatat CTLFLAG_PERMANENT,
325 1.32 atatat CTLTYPE_STRUCT, "uvmexp2",
326 1.32 atatat SYSCTL_DESCR("Detailed system-wide virtual memory "
327 1.32 atatat "statistics (MI)"),
328 1.27 atatat sysctl_vm_uvmexp2, 0, NULL, 0,
329 1.27 atatat CTL_VM, VM_UVMEXP2, CTL_EOL);
330 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
331 1.32 atatat CTLFLAG_PERMANENT, CTLTYPE_INT, "maxslp",
332 1.32 atatat SYSCTL_DESCR("Maximum process sleep time before being "
333 1.32 atatat "swapped"),
334 1.27 atatat NULL, 0, &maxslp, 0,
335 1.27 atatat CTL_VM, VM_MAXSLP, CTL_EOL);
336 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
337 1.31 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
338 1.32 atatat CTLTYPE_INT, "uspace",
339 1.32 atatat SYSCTL_DESCR("Number of bytes allocated for a kernel "
340 1.32 atatat "stack"),
341 1.27 atatat NULL, USPACE, NULL, 0,
342 1.27 atatat CTL_VM, VM_USPACE, CTL_EOL);
343 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
344 1.31 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
345 1.33 yamt CTLTYPE_INT, "idlezero",
346 1.33 yamt SYSCTL_DESCR("Whether try to zero pages in idle loop"),
347 1.33 yamt NULL, 0, &vm_page_zero_enable, 0,
348 1.33 yamt CTL_VM, CTL_CREATE, CTL_EOL);
349 1.41 yamt
350 1.41 yamt uvmpdpol_sysctlsetup();
351 1.1 mrg }
352 1.1 mrg
353 1.1 mrg /*
354 1.1 mrg * uvm_total: calculate the current state of the system.
355 1.1 mrg */
356 1.4 mrg static void
357 1.35 thorpej uvm_total(struct vmtotal *totalp)
358 1.1 mrg {
359 1.24 thorpej struct lwp *l;
360 1.1 mrg #if 0
361 1.20 chs struct vm_map_entry * entry;
362 1.20 chs struct vm_map *map;
363 1.4 mrg int paging;
364 1.1 mrg #endif
365 1.41 yamt int active;
366 1.1 mrg
367 1.7 perry memset(totalp, 0, sizeof *totalp);
368 1.1 mrg
369 1.4 mrg /*
370 1.4 mrg * calculate process statistics
371 1.4 mrg */
372 1.48 ad mutex_enter(proc_lock);
373 1.44 ad LIST_FOREACH(l, &alllwp, l_list) {
374 1.46 pavel if (l->l_proc->p_flag & PK_SYSTEM)
375 1.4 mrg continue;
376 1.24 thorpej switch (l->l_stat) {
377 1.4 mrg case 0:
378 1.4 mrg continue;
379 1.6 mrg
380 1.24 thorpej case LSSLEEP:
381 1.24 thorpej case LSSTOP:
382 1.46 pavel if (l->l_flag & LW_INMEM) {
383 1.47 yamt if (lwp_eprio(l) <= PZERO)
384 1.4 mrg totalp->t_dw++;
385 1.24 thorpej else if (l->l_slptime < maxslp)
386 1.4 mrg totalp->t_sl++;
387 1.24 thorpej } else if (l->l_slptime < maxslp)
388 1.4 mrg totalp->t_sw++;
389 1.24 thorpej if (l->l_slptime >= maxslp)
390 1.4 mrg continue;
391 1.4 mrg break;
392 1.6 mrg
393 1.24 thorpej case LSRUN:
394 1.24 thorpej case LSONPROC:
395 1.24 thorpej case LSIDL:
396 1.46 pavel if (l->l_flag & LW_INMEM)
397 1.4 mrg totalp->t_rq++;
398 1.4 mrg else
399 1.4 mrg totalp->t_sw++;
400 1.24 thorpej if (l->l_stat == LSIDL)
401 1.4 mrg continue;
402 1.4 mrg break;
403 1.4 mrg }
404 1.4 mrg /*
405 1.4 mrg * note active objects
406 1.4 mrg */
407 1.1 mrg #if 0
408 1.4 mrg /*
409 1.36 simonb * XXXCDC: BOGUS! rethink this. in the mean time
410 1.5 mrg * don't do it.
411 1.4 mrg */
412 1.4 mrg paging = 0;
413 1.5 mrg vm_map_lock(map);
414 1.4 mrg for (map = &p->p_vmspace->vm_map, entry = map->header.next;
415 1.4 mrg entry != &map->header; entry = entry->next) {
416 1.4 mrg if (entry->is_a_map || entry->is_sub_map ||
417 1.5 mrg entry->object.uvm_obj == NULL)
418 1.4 mrg continue;
419 1.5 mrg /* XXX how to do this with uvm */
420 1.4 mrg }
421 1.5 mrg vm_map_unlock(map);
422 1.4 mrg if (paging)
423 1.4 mrg totalp->t_pw++;
424 1.1 mrg #endif
425 1.4 mrg }
426 1.48 ad mutex_exit(proc_lock);
427 1.44 ad
428 1.4 mrg /*
429 1.4 mrg * Calculate object memory usage statistics.
430 1.4 mrg */
431 1.41 yamt uvm_estimatepageable(&active, NULL);
432 1.5 mrg totalp->t_free = uvmexp.free;
433 1.5 mrg totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
434 1.41 yamt totalp->t_avm = active + uvmexp.swpginuse; /* XXX */
435 1.5 mrg totalp->t_rm = uvmexp.npages - uvmexp.free;
436 1.41 yamt totalp->t_arm = active;
437 1.5 mrg totalp->t_vmshr = 0; /* XXX */
438 1.5 mrg totalp->t_avmshr = 0; /* XXX */
439 1.5 mrg totalp->t_rmshr = 0; /* XXX */
440 1.5 mrg totalp->t_armshr = 0; /* XXX */
441 1.1 mrg }
442 1.38 yamt
443 1.38 yamt void
444 1.38 yamt uvm_pctparam_set(struct uvm_pctparam *pct, int val)
445 1.38 yamt {
446 1.38 yamt
447 1.38 yamt pct->pct_pct = val;
448 1.38 yamt pct->pct_scaled = val * UVM_PCTPARAM_SCALE / 100;
449 1.38 yamt }
450 1.41 yamt
451 1.41 yamt int
452 1.41 yamt uvm_pctparam_get(struct uvm_pctparam *pct)
453 1.41 yamt {
454 1.41 yamt
455 1.41 yamt return pct->pct_pct;
456 1.41 yamt }
457 1.41 yamt
458 1.41 yamt int
459 1.41 yamt uvm_pctparam_check(struct uvm_pctparam *pct, int val)
460 1.41 yamt {
461 1.41 yamt
462 1.41 yamt if (pct->pct_check == NULL) {
463 1.41 yamt return 0;
464 1.41 yamt }
465 1.41 yamt return (*pct->pct_check)(pct, val);
466 1.41 yamt }
467 1.41 yamt
468 1.41 yamt void
469 1.41 yamt uvm_pctparam_init(struct uvm_pctparam *pct, int val,
470 1.41 yamt int (*fn)(struct uvm_pctparam *, int))
471 1.41 yamt {
472 1.41 yamt
473 1.41 yamt pct->pct_check = fn;
474 1.41 yamt uvm_pctparam_set(pct, val);
475 1.41 yamt }
476 1.41 yamt
477 1.41 yamt int
478 1.41 yamt uvm_pctparam_createsysctlnode(struct uvm_pctparam *pct, const char *name,
479 1.43 yamt const char *desc)
480 1.41 yamt {
481 1.41 yamt
482 1.41 yamt return sysctl_createv(NULL, 0, NULL, NULL,
483 1.41 yamt CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
484 1.41 yamt CTLTYPE_INT, name, SYSCTL_DESCR(desc),
485 1.41 yamt uvm_sysctlpctparam, 0, pct, 0, CTL_VM, CTL_CREATE, CTL_EOL);
486 1.41 yamt }
487