uvm_pdpolicy_clock.c revision 1.1.2.2 1 1.1.2.1 yamt /* $NetBSD: uvm_pdpolicy_clock.c,v 1.1.2.2 2006/09/15 11:54:56 yamt Exp $ */
2 1.1.2.1 yamt /* NetBSD: uvm_pdaemon.c,v 1.72 2006/01/05 10:47:33 yamt Exp $ */
3 1.1.2.1 yamt
4 1.1.2.1 yamt /*
5 1.1.2.1 yamt * Copyright (c) 1997 Charles D. Cranor and Washington University.
6 1.1.2.1 yamt * Copyright (c) 1991, 1993, The Regents of the University of California.
7 1.1.2.1 yamt *
8 1.1.2.1 yamt * All rights reserved.
9 1.1.2.1 yamt *
10 1.1.2.1 yamt * This code is derived from software contributed to Berkeley by
11 1.1.2.1 yamt * The Mach Operating System project at Carnegie-Mellon University.
12 1.1.2.1 yamt *
13 1.1.2.1 yamt * Redistribution and use in source and binary forms, with or without
14 1.1.2.1 yamt * modification, are permitted provided that the following conditions
15 1.1.2.1 yamt * are met:
16 1.1.2.1 yamt * 1. Redistributions of source code must retain the above copyright
17 1.1.2.1 yamt * notice, this list of conditions and the following disclaimer.
18 1.1.2.1 yamt * 2. Redistributions in binary form must reproduce the above copyright
19 1.1.2.1 yamt * notice, this list of conditions and the following disclaimer in the
20 1.1.2.1 yamt * documentation and/or other materials provided with the distribution.
21 1.1.2.1 yamt * 3. All advertising materials mentioning features or use of this software
22 1.1.2.1 yamt * must display the following acknowledgement:
23 1.1.2.1 yamt * This product includes software developed by Charles D. Cranor,
24 1.1.2.1 yamt * Washington University, the University of California, Berkeley and
25 1.1.2.1 yamt * its contributors.
26 1.1.2.1 yamt * 4. Neither the name of the University nor the names of its contributors
27 1.1.2.1 yamt * may be used to endorse or promote products derived from this software
28 1.1.2.1 yamt * without specific prior written permission.
29 1.1.2.1 yamt *
30 1.1.2.1 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 1.1.2.1 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 1.1.2.1 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 1.1.2.1 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 1.1.2.1 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 1.1.2.1 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 1.1.2.1 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 1.1.2.1 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 1.1.2.1 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 1.1.2.1 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 1.1.2.1 yamt * SUCH DAMAGE.
41 1.1.2.1 yamt *
42 1.1.2.1 yamt * @(#)vm_pageout.c 8.5 (Berkeley) 2/14/94
43 1.1.2.1 yamt * from: Id: uvm_pdaemon.c,v 1.1.2.32 1998/02/06 05:26:30 chs Exp
44 1.1.2.1 yamt *
45 1.1.2.1 yamt *
46 1.1.2.1 yamt * Copyright (c) 1987, 1990 Carnegie-Mellon University.
47 1.1.2.1 yamt * All rights reserved.
48 1.1.2.1 yamt *
49 1.1.2.1 yamt * Permission to use, copy, modify and distribute this software and
50 1.1.2.1 yamt * its documentation is hereby granted, provided that both the copyright
51 1.1.2.1 yamt * notice and this permission notice appear in all copies of the
52 1.1.2.1 yamt * software, derivative works or modified versions, and any portions
53 1.1.2.1 yamt * thereof, and that both notices appear in supporting documentation.
54 1.1.2.1 yamt *
55 1.1.2.1 yamt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
56 1.1.2.1 yamt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
57 1.1.2.1 yamt * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
58 1.1.2.1 yamt *
59 1.1.2.1 yamt * Carnegie Mellon requests users of this software to return to
60 1.1.2.1 yamt *
61 1.1.2.1 yamt * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
62 1.1.2.1 yamt * School of Computer Science
63 1.1.2.1 yamt * Carnegie Mellon University
64 1.1.2.1 yamt * Pittsburgh PA 15213-3890
65 1.1.2.1 yamt *
66 1.1.2.1 yamt * any improvements or extensions that they make and grant Carnegie the
67 1.1.2.1 yamt * rights to redistribute these changes.
68 1.1.2.1 yamt */
69 1.1.2.1 yamt
70 1.1.2.1 yamt #if defined(PDSIM)
71 1.1.2.1 yamt
72 1.1.2.1 yamt #include "pdsim.h"
73 1.1.2.1 yamt
74 1.1.2.1 yamt #else /* defined(PDSIM) */
75 1.1.2.1 yamt
76 1.1.2.1 yamt #include <sys/cdefs.h>
77 1.1.2.1 yamt __KERNEL_RCSID(0, "$NetBSD: uvm_pdpolicy_clock.c,v 1.1.2.2 2006/09/15 11:54:56 yamt Exp $");
78 1.1.2.1 yamt
79 1.1.2.1 yamt #include <sys/param.h>
80 1.1.2.1 yamt #include <sys/proc.h>
81 1.1.2.1 yamt #include <sys/systm.h>
82 1.1.2.1 yamt #include <sys/kernel.h>
83 1.1.2.1 yamt #include <sys/vnode.h>
84 1.1.2.1 yamt
85 1.1.2.1 yamt #include <uvm/uvm.h>
86 1.1.2.2 yamt #include <uvm/uvm_pdpolicy.h>
87 1.1.2.1 yamt #include <uvm/uvm_pdpolicy_impl.h>
88 1.1.2.1 yamt
89 1.1.2.1 yamt #endif /* defined(PDSIM) */
90 1.1.2.1 yamt
91 1.1.2.1 yamt #define PQ_INACTIVE PQ_PRIVATE1 /* page is in inactive list */
92 1.1.2.1 yamt #define PQ_ACTIVE PQ_PRIVATE2 /* page is in active list */
93 1.1.2.1 yamt
94 1.1.2.1 yamt #if !defined(CLOCK_INACTIVEPCT)
95 1.1.2.1 yamt #define CLOCK_INACTIVEPCT 33
96 1.1.2.1 yamt #endif /* !defined(CLOCK_INACTIVEPCT) */
97 1.1.2.1 yamt
98 1.1.2.1 yamt struct uvmpdpol_globalstate {
99 1.1.2.1 yamt struct pglist s_activeq; /* allocated pages, in use */
100 1.1.2.1 yamt struct pglist s_inactiveq; /* pages between the clock hands */
101 1.1.2.1 yamt int s_active;
102 1.1.2.1 yamt int s_inactive;
103 1.1.2.1 yamt int s_inactarg;
104 1.1.2.1 yamt struct uvm_pctparam s_anonmin;
105 1.1.2.1 yamt struct uvm_pctparam s_filemin;
106 1.1.2.1 yamt struct uvm_pctparam s_execmin;
107 1.1.2.1 yamt struct uvm_pctparam s_anonmax;
108 1.1.2.1 yamt struct uvm_pctparam s_filemax;
109 1.1.2.1 yamt struct uvm_pctparam s_execmax;
110 1.1.2.1 yamt struct uvm_pctparam s_inactivepct;
111 1.1.2.1 yamt };
112 1.1.2.1 yamt
113 1.1.2.1 yamt struct uvmpdpol_scanstate {
114 1.1.2.1 yamt boolean_t ss_first;
115 1.1.2.1 yamt boolean_t ss_anonreact, ss_filereact, ss_execreact;
116 1.1.2.1 yamt struct vm_page *ss_nextpg;
117 1.1.2.1 yamt };
118 1.1.2.1 yamt
119 1.1.2.1 yamt static struct uvmpdpol_globalstate pdpol_state;
120 1.1.2.1 yamt static struct uvmpdpol_scanstate pdpol_scanstate;
121 1.1.2.1 yamt
122 1.1.2.1 yamt PDPOL_EVCNT_DEFINE(reactexec)
123 1.1.2.1 yamt PDPOL_EVCNT_DEFINE(reactfile)
124 1.1.2.1 yamt PDPOL_EVCNT_DEFINE(reactanon)
125 1.1.2.1 yamt
126 1.1.2.1 yamt static void
127 1.1.2.1 yamt clock_tune(void)
128 1.1.2.1 yamt {
129 1.1.2.1 yamt struct uvmpdpol_globalstate *s = &pdpol_state;
130 1.1.2.1 yamt
131 1.1.2.1 yamt s->s_inactarg =
132 1.1.2.1 yamt s->s_inactarg = UVM_PCTPARAM_APPLY(&s->s_inactivepct,
133 1.1.2.1 yamt s->s_active + s->s_inactive);
134 1.1.2.1 yamt if (s->s_inactarg <= uvmexp.freetarg) {
135 1.1.2.1 yamt s->s_inactarg = uvmexp.freetarg + 1;
136 1.1.2.1 yamt }
137 1.1.2.1 yamt }
138 1.1.2.1 yamt
139 1.1.2.1 yamt void
140 1.1.2.1 yamt uvmpdpol_scaninit(void)
141 1.1.2.1 yamt {
142 1.1.2.1 yamt struct uvmpdpol_globalstate *s = &pdpol_state;
143 1.1.2.1 yamt struct uvmpdpol_scanstate *ss = &pdpol_scanstate;
144 1.1.2.1 yamt int t;
145 1.1.2.1 yamt boolean_t anonunder, fileunder, execunder;
146 1.1.2.1 yamt boolean_t anonover, fileover, execover;
147 1.1.2.1 yamt boolean_t anonreact, filereact, execreact;
148 1.1.2.1 yamt
149 1.1.2.1 yamt /*
150 1.1.2.1 yamt * decide which types of pages we want to reactivate instead of freeing
151 1.1.2.1 yamt * to keep usage within the minimum and maximum usage limits.
152 1.1.2.1 yamt */
153 1.1.2.1 yamt
154 1.1.2.1 yamt t = s->s_active + s->s_inactive + uvmexp.free;
155 1.1.2.1 yamt anonunder = uvmexp.anonpages <= UVM_PCTPARAM_APPLY(&s->s_anonmin, t);
156 1.1.2.1 yamt fileunder = uvmexp.filepages <= UVM_PCTPARAM_APPLY(&s->s_filemin, t);
157 1.1.2.1 yamt execunder = uvmexp.execpages <= UVM_PCTPARAM_APPLY(&s->s_execmin, t);
158 1.1.2.1 yamt anonover = uvmexp.anonpages > UVM_PCTPARAM_APPLY(&s->s_anonmax, t);
159 1.1.2.1 yamt fileover = uvmexp.filepages > UVM_PCTPARAM_APPLY(&s->s_filemax, t);
160 1.1.2.1 yamt execover = uvmexp.execpages > UVM_PCTPARAM_APPLY(&s->s_execmax, t);
161 1.1.2.1 yamt anonreact = anonunder || (!anonover && (fileover || execover));
162 1.1.2.1 yamt filereact = fileunder || (!fileover && (anonover || execover));
163 1.1.2.1 yamt execreact = execunder || (!execover && (anonover || fileover));
164 1.1.2.1 yamt if (filereact && execreact && (anonreact || uvm_swapisfull())) {
165 1.1.2.1 yamt anonreact = filereact = execreact = FALSE;
166 1.1.2.1 yamt }
167 1.1.2.1 yamt ss->ss_anonreact = anonreact;
168 1.1.2.1 yamt ss->ss_filereact = filereact;
169 1.1.2.1 yamt ss->ss_execreact = execreact;
170 1.1.2.1 yamt
171 1.1.2.1 yamt ss->ss_first = TRUE;
172 1.1.2.1 yamt }
173 1.1.2.1 yamt
174 1.1.2.1 yamt struct vm_page *
175 1.1.2.1 yamt uvmpdpol_selectvictim(void)
176 1.1.2.1 yamt {
177 1.1.2.1 yamt struct uvmpdpol_scanstate *ss = &pdpol_scanstate;
178 1.1.2.1 yamt struct vm_page *pg;
179 1.1.2.1 yamt
180 1.1.2.1 yamt UVM_LOCK_ASSERT_PAGEQ();
181 1.1.2.1 yamt
182 1.1.2.1 yamt while (/* CONSTCOND */ 1) {
183 1.1.2.1 yamt struct vm_anon *anon;
184 1.1.2.1 yamt struct uvm_object *uobj;
185 1.1.2.1 yamt
186 1.1.2.1 yamt if (ss->ss_first) {
187 1.1.2.1 yamt pg = TAILQ_FIRST(&pdpol_state.s_inactiveq);
188 1.1.2.1 yamt ss->ss_first = FALSE;
189 1.1.2.1 yamt } else {
190 1.1.2.1 yamt pg = ss->ss_nextpg;
191 1.1.2.1 yamt if (pg != NULL && (pg->pqflags & PQ_INACTIVE) == 0) {
192 1.1.2.1 yamt pg = TAILQ_FIRST(&pdpol_state.s_inactiveq);
193 1.1.2.1 yamt }
194 1.1.2.1 yamt }
195 1.1.2.1 yamt if (pg == NULL) {
196 1.1.2.1 yamt break;
197 1.1.2.1 yamt }
198 1.1.2.1 yamt ss->ss_nextpg = TAILQ_NEXT(pg, pageq);
199 1.1.2.1 yamt
200 1.1.2.1 yamt uvmexp.pdscans++;
201 1.1.2.1 yamt
202 1.1.2.1 yamt /*
203 1.1.2.1 yamt * move referenced pages back to active queue and
204 1.1.2.1 yamt * skip to next page.
205 1.1.2.1 yamt */
206 1.1.2.1 yamt
207 1.1.2.1 yamt if (pmap_is_referenced(pg)) {
208 1.1.2.1 yamt uvmpdpol_pageactivate(pg);
209 1.1.2.1 yamt uvmexp.pdreact++;
210 1.1.2.1 yamt continue;
211 1.1.2.1 yamt }
212 1.1.2.1 yamt
213 1.1.2.1 yamt anon = pg->uanon;
214 1.1.2.1 yamt uobj = pg->uobject;
215 1.1.2.1 yamt
216 1.1.2.1 yamt /*
217 1.1.2.1 yamt * enforce the minimum thresholds on different
218 1.1.2.1 yamt * types of memory usage. if reusing the current
219 1.1.2.1 yamt * page would reduce that type of usage below its
220 1.1.2.1 yamt * minimum, reactivate the page instead and move
221 1.1.2.1 yamt * on to the next page.
222 1.1.2.1 yamt */
223 1.1.2.1 yamt
224 1.1.2.1 yamt if (uobj && UVM_OBJ_IS_VTEXT(uobj) && ss->ss_execreact) {
225 1.1.2.1 yamt uvmpdpol_pageactivate(pg);
226 1.1.2.1 yamt PDPOL_EVCNT_INCR(reactexec);
227 1.1.2.1 yamt continue;
228 1.1.2.1 yamt }
229 1.1.2.1 yamt if (uobj && UVM_OBJ_IS_VNODE(uobj) &&
230 1.1.2.1 yamt !UVM_OBJ_IS_VTEXT(uobj) && ss->ss_filereact) {
231 1.1.2.1 yamt uvmpdpol_pageactivate(pg);
232 1.1.2.1 yamt PDPOL_EVCNT_INCR(reactfile);
233 1.1.2.1 yamt continue;
234 1.1.2.1 yamt }
235 1.1.2.1 yamt if ((anon || UVM_OBJ_IS_AOBJ(uobj)) && ss->ss_anonreact) {
236 1.1.2.1 yamt uvmpdpol_pageactivate(pg);
237 1.1.2.1 yamt PDPOL_EVCNT_INCR(reactanon);
238 1.1.2.1 yamt continue;
239 1.1.2.1 yamt }
240 1.1.2.1 yamt
241 1.1.2.1 yamt break;
242 1.1.2.1 yamt }
243 1.1.2.1 yamt
244 1.1.2.1 yamt return pg;
245 1.1.2.1 yamt }
246 1.1.2.1 yamt
247 1.1.2.1 yamt void
248 1.1.2.1 yamt uvmpdpol_balancequeue(int swap_shortage)
249 1.1.2.1 yamt {
250 1.1.2.1 yamt int inactive_shortage;
251 1.1.2.1 yamt struct vm_page *p, *nextpg;
252 1.1.2.1 yamt
253 1.1.2.1 yamt /*
254 1.1.2.1 yamt * we have done the scan to get free pages. now we work on meeting
255 1.1.2.1 yamt * our inactive target.
256 1.1.2.1 yamt */
257 1.1.2.1 yamt
258 1.1.2.1 yamt inactive_shortage = pdpol_state.s_inactarg - pdpol_state.s_inactive;
259 1.1.2.1 yamt for (p = TAILQ_FIRST(&pdpol_state.s_activeq);
260 1.1.2.1 yamt p != NULL && (inactive_shortage > 0 || swap_shortage > 0);
261 1.1.2.1 yamt p = nextpg) {
262 1.1.2.1 yamt nextpg = TAILQ_NEXT(p, pageq);
263 1.1.2.1 yamt
264 1.1.2.1 yamt /*
265 1.1.2.1 yamt * if there's a shortage of swap slots, try to free it.
266 1.1.2.1 yamt */
267 1.1.2.1 yamt
268 1.1.2.1 yamt if (swap_shortage > 0 && (p->pqflags & PQ_SWAPBACKED) != 0) {
269 1.1.2.1 yamt if (uvmpd_trydropswap(p)) {
270 1.1.2.1 yamt swap_shortage--;
271 1.1.2.1 yamt }
272 1.1.2.1 yamt }
273 1.1.2.1 yamt
274 1.1.2.1 yamt /*
275 1.1.2.1 yamt * if there's a shortage of inactive pages, deactivate.
276 1.1.2.1 yamt */
277 1.1.2.1 yamt
278 1.1.2.1 yamt if (inactive_shortage > 0) {
279 1.1.2.1 yamt /* no need to check wire_count as pg is "active" */
280 1.1.2.1 yamt pmap_clear_reference(p);
281 1.1.2.1 yamt uvmpdpol_pagedeactivate(p);
282 1.1.2.1 yamt uvmexp.pddeact++;
283 1.1.2.1 yamt inactive_shortage--;
284 1.1.2.1 yamt }
285 1.1.2.1 yamt }
286 1.1.2.1 yamt }
287 1.1.2.1 yamt
288 1.1.2.1 yamt void
289 1.1.2.1 yamt uvmpdpol_pagedeactivate(struct vm_page *pg)
290 1.1.2.1 yamt {
291 1.1.2.1 yamt
292 1.1.2.1 yamt UVM_LOCK_ASSERT_PAGEQ();
293 1.1.2.1 yamt if (pg->pqflags & PQ_ACTIVE) {
294 1.1.2.1 yamt TAILQ_REMOVE(&pdpol_state.s_activeq, pg, pageq);
295 1.1.2.1 yamt pg->pqflags &= ~PQ_ACTIVE;
296 1.1.2.1 yamt KASSERT(pdpol_state.s_active > 0);
297 1.1.2.1 yamt pdpol_state.s_active--;
298 1.1.2.1 yamt }
299 1.1.2.1 yamt if ((pg->pqflags & PQ_INACTIVE) == 0) {
300 1.1.2.1 yamt KASSERT(pg->wire_count == 0);
301 1.1.2.1 yamt TAILQ_INSERT_TAIL(&pdpol_state.s_inactiveq, pg, pageq);
302 1.1.2.1 yamt pg->pqflags |= PQ_INACTIVE;
303 1.1.2.1 yamt pdpol_state.s_inactive++;
304 1.1.2.1 yamt }
305 1.1.2.1 yamt }
306 1.1.2.1 yamt
307 1.1.2.1 yamt void
308 1.1.2.1 yamt uvmpdpol_pageactivate(struct vm_page *pg)
309 1.1.2.1 yamt {
310 1.1.2.1 yamt
311 1.1.2.1 yamt uvmpdpol_pagedequeue(pg);
312 1.1.2.1 yamt TAILQ_INSERT_TAIL(&pdpol_state.s_activeq, pg, pageq);
313 1.1.2.1 yamt pg->pqflags |= PQ_ACTIVE;
314 1.1.2.1 yamt pdpol_state.s_active++;
315 1.1.2.1 yamt }
316 1.1.2.1 yamt
317 1.1.2.1 yamt void
318 1.1.2.1 yamt uvmpdpol_pagedequeue(struct vm_page *pg)
319 1.1.2.1 yamt {
320 1.1.2.1 yamt
321 1.1.2.1 yamt if (pg->pqflags & PQ_ACTIVE) {
322 1.1.2.1 yamt UVM_LOCK_ASSERT_PAGEQ();
323 1.1.2.1 yamt TAILQ_REMOVE(&pdpol_state.s_activeq, pg, pageq);
324 1.1.2.1 yamt pg->pqflags &= ~PQ_ACTIVE;
325 1.1.2.1 yamt KASSERT(pdpol_state.s_active > 0);
326 1.1.2.1 yamt pdpol_state.s_active--;
327 1.1.2.1 yamt } else if (pg->pqflags & PQ_INACTIVE) {
328 1.1.2.1 yamt UVM_LOCK_ASSERT_PAGEQ();
329 1.1.2.1 yamt TAILQ_REMOVE(&pdpol_state.s_inactiveq, pg, pageq);
330 1.1.2.1 yamt pg->pqflags &= ~PQ_INACTIVE;
331 1.1.2.1 yamt KASSERT(pdpol_state.s_inactive > 0);
332 1.1.2.1 yamt pdpol_state.s_inactive--;
333 1.1.2.1 yamt }
334 1.1.2.1 yamt }
335 1.1.2.1 yamt
336 1.1.2.1 yamt void
337 1.1.2.1 yamt uvmpdpol_pageenqueue(struct vm_page *pg)
338 1.1.2.1 yamt {
339 1.1.2.1 yamt
340 1.1.2.1 yamt uvmpdpol_pageactivate(pg);
341 1.1.2.1 yamt }
342 1.1.2.1 yamt
343 1.1.2.1 yamt void
344 1.1.2.1 yamt uvmpdpol_anfree(struct vm_anon *an)
345 1.1.2.1 yamt {
346 1.1.2.1 yamt }
347 1.1.2.1 yamt
348 1.1.2.1 yamt boolean_t
349 1.1.2.1 yamt uvmpdpol_pageisqueued_p(struct vm_page *pg)
350 1.1.2.1 yamt {
351 1.1.2.1 yamt
352 1.1.2.1 yamt return (pg->pqflags & (PQ_ACTIVE | PQ_INACTIVE)) != 0;
353 1.1.2.1 yamt }
354 1.1.2.1 yamt
355 1.1.2.1 yamt void
356 1.1.2.1 yamt uvmpdpol_estimatepageable(int *active, int *inactive)
357 1.1.2.1 yamt {
358 1.1.2.1 yamt
359 1.1.2.1 yamt if (active) {
360 1.1.2.1 yamt *active = pdpol_state.s_active;
361 1.1.2.1 yamt }
362 1.1.2.1 yamt if (inactive) {
363 1.1.2.1 yamt *inactive = pdpol_state.s_inactive;
364 1.1.2.1 yamt }
365 1.1.2.1 yamt }
366 1.1.2.1 yamt
367 1.1.2.1 yamt #if !defined(PDSIM)
368 1.1.2.1 yamt static int
369 1.1.2.1 yamt min_check(struct uvm_pctparam *pct, int t)
370 1.1.2.1 yamt {
371 1.1.2.1 yamt struct uvmpdpol_globalstate *s = &pdpol_state;
372 1.1.2.1 yamt int total = t;
373 1.1.2.1 yamt
374 1.1.2.1 yamt if (pct != &s->s_anonmin) {
375 1.1.2.1 yamt total += uvm_pctparam_get(&s->s_anonmin);
376 1.1.2.1 yamt }
377 1.1.2.1 yamt if (pct != &s->s_filemin) {
378 1.1.2.1 yamt total += uvm_pctparam_get(&s->s_filemin);
379 1.1.2.1 yamt }
380 1.1.2.1 yamt if (pct != &s->s_execmin) {
381 1.1.2.1 yamt total += uvm_pctparam_get(&s->s_execmin);
382 1.1.2.1 yamt }
383 1.1.2.1 yamt if (total > 95) {
384 1.1.2.1 yamt return EINVAL;
385 1.1.2.1 yamt }
386 1.1.2.1 yamt return 0;
387 1.1.2.1 yamt }
388 1.1.2.1 yamt #endif /* !defined(PDSIM) */
389 1.1.2.1 yamt
390 1.1.2.1 yamt void
391 1.1.2.1 yamt uvmpdpol_init(void)
392 1.1.2.1 yamt {
393 1.1.2.1 yamt struct uvmpdpol_globalstate *s = &pdpol_state;
394 1.1.2.1 yamt
395 1.1.2.1 yamt TAILQ_INIT(&s->s_activeq);
396 1.1.2.1 yamt TAILQ_INIT(&s->s_inactiveq);
397 1.1.2.1 yamt uvm_pctparam_init(&s->s_inactivepct, CLOCK_INACTIVEPCT, NULL);
398 1.1.2.1 yamt uvm_pctparam_init(&s->s_anonmin, 10, min_check);
399 1.1.2.1 yamt uvm_pctparam_init(&s->s_filemin, 10, min_check);
400 1.1.2.1 yamt uvm_pctparam_init(&s->s_execmin, 5, min_check);
401 1.1.2.1 yamt uvm_pctparam_init(&s->s_anonmax, 80, NULL);
402 1.1.2.1 yamt uvm_pctparam_init(&s->s_filemax, 50, NULL);
403 1.1.2.1 yamt uvm_pctparam_init(&s->s_execmax, 30, NULL);
404 1.1.2.1 yamt }
405 1.1.2.1 yamt
406 1.1.2.1 yamt void
407 1.1.2.1 yamt uvmpdpol_reinit(void)
408 1.1.2.1 yamt {
409 1.1.2.1 yamt }
410 1.1.2.1 yamt
411 1.1.2.1 yamt boolean_t
412 1.1.2.1 yamt uvmpdpol_needsscan_p(void)
413 1.1.2.1 yamt {
414 1.1.2.1 yamt
415 1.1.2.1 yamt return pdpol_state.s_inactive < pdpol_state.s_inactarg;
416 1.1.2.1 yamt }
417 1.1.2.1 yamt
418 1.1.2.1 yamt void
419 1.1.2.1 yamt uvmpdpol_tune(void)
420 1.1.2.1 yamt {
421 1.1.2.1 yamt
422 1.1.2.1 yamt clock_tune();
423 1.1.2.1 yamt }
424 1.1.2.1 yamt
425 1.1.2.1 yamt #if !defined(PDSIM)
426 1.1.2.1 yamt
427 1.1.2.1 yamt #include <sys/sysctl.h> /* XXX SYSCTL_DESCR */
428 1.1.2.1 yamt
429 1.1.2.1 yamt void
430 1.1.2.1 yamt uvmpdpol_sysctlsetup(void)
431 1.1.2.1 yamt {
432 1.1.2.1 yamt struct uvmpdpol_globalstate *s = &pdpol_state;
433 1.1.2.1 yamt
434 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_anonmin, "anonmin",
435 1.1.2.1 yamt SYSCTL_DESCR("Percentage of physical memory reserved "
436 1.1.2.1 yamt "for anonymous application data"));
437 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_filemin, "filemin",
438 1.1.2.1 yamt SYSCTL_DESCR("Percentage of physical memory reserved "
439 1.1.2.1 yamt "for cached executable data"));
440 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_execmin, "execmin",
441 1.1.2.1 yamt SYSCTL_DESCR("Percentage of physical memory reserved "
442 1.1.2.1 yamt "for cached file data"));
443 1.1.2.1 yamt
444 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_anonmax, "anonmax",
445 1.1.2.1 yamt SYSCTL_DESCR("Percentage of physical memory which will "
446 1.1.2.1 yamt "be reclaimed from other usage for "
447 1.1.2.1 yamt "anonymous application data"));
448 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_filemax, "filemax",
449 1.1.2.1 yamt SYSCTL_DESCR("Percentage of physical memory which will "
450 1.1.2.1 yamt "be reclaimed from other usage for cached "
451 1.1.2.1 yamt "file data"));
452 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_execmax, "execmax",
453 1.1.2.1 yamt SYSCTL_DESCR("Percentage of physical memory which will "
454 1.1.2.1 yamt "be reclaimed from other usage for cached "
455 1.1.2.1 yamt "executable data"));
456 1.1.2.1 yamt
457 1.1.2.1 yamt uvm_pctparam_createsysctlnode(&s->s_inactivepct, "inactivepct",
458 1.1.2.1 yamt SYSCTL_DESCR("Percentage of inactive queue of "
459 1.1.2.1 yamt "the entire (active + inactive) queue"));
460 1.1.2.1 yamt }
461 1.1.2.1 yamt
462 1.1.2.1 yamt #endif /* !defined(PDSIM) */
463 1.1.2.1 yamt
464 1.1.2.1 yamt #if defined(PDSIM)
465 1.1.2.1 yamt void
466 1.1.2.1 yamt pdsim_dump(const char *id)
467 1.1.2.1 yamt {
468 1.1.2.1 yamt #if defined(DEBUG)
469 1.1.2.1 yamt /* XXX */
470 1.1.2.1 yamt #endif /* defined(DEBUG) */
471 1.1.2.1 yamt }
472 1.1.2.1 yamt #endif /* defined(PDSIM) */
473