uvm_anon.c revision 1.29 1 1.29 yamt /* $NetBSD: uvm_anon.c,v 1.29 2004/05/05 11:54:32 yamt Exp $ */
2 1.1 chuck
3 1.1 chuck /*
4 1.1 chuck *
5 1.1 chuck * Copyright (c) 1997 Charles D. Cranor and Washington University.
6 1.1 chuck * All rights reserved.
7 1.1 chuck *
8 1.1 chuck * Redistribution and use in source and binary forms, with or without
9 1.1 chuck * modification, are permitted provided that the following conditions
10 1.1 chuck * are met:
11 1.1 chuck * 1. Redistributions of source code must retain the above copyright
12 1.1 chuck * notice, this list of conditions and the following disclaimer.
13 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 chuck * notice, this list of conditions and the following disclaimer in the
15 1.1 chuck * documentation and/or other materials provided with the distribution.
16 1.1 chuck * 3. All advertising materials mentioning features or use of this software
17 1.1 chuck * must display the following acknowledgement:
18 1.1 chuck * This product includes software developed by Charles D. Cranor and
19 1.1 chuck * Washington University.
20 1.1 chuck * 4. The name of the author may not be used to endorse or promote products
21 1.1 chuck * derived from this software without specific prior written permission.
22 1.1 chuck *
23 1.1 chuck * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 chuck * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 chuck * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 chuck * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 chuck * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 chuck * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 chuck * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 chuck * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 chuck * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 chuck * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 chuck */
34 1.1 chuck
35 1.1 chuck /*
36 1.1 chuck * uvm_anon.c: uvm anon ops
37 1.1 chuck */
38 1.21 lukem
39 1.21 lukem #include <sys/cdefs.h>
40 1.29 yamt __KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.29 2004/05/05 11:54:32 yamt Exp $");
41 1.1 chuck
42 1.1 chuck #include "opt_uvmhist.h"
43 1.1 chuck
44 1.1 chuck #include <sys/param.h>
45 1.1 chuck #include <sys/systm.h>
46 1.1 chuck #include <sys/proc.h>
47 1.1 chuck #include <sys/malloc.h>
48 1.1 chuck #include <sys/pool.h>
49 1.5 chs #include <sys/kernel.h>
50 1.1 chuck
51 1.1 chuck #include <uvm/uvm.h>
52 1.1 chuck #include <uvm/uvm_swap.h>
53 1.1 chuck
54 1.1 chuck /*
55 1.5 chs * anonblock_list: global list of anon blocks,
56 1.5 chs * locked by swap_syscall_lock (since we never remove
57 1.5 chs * anything from this list and we only add to it via swapctl(2)).
58 1.5 chs */
59 1.5 chs
60 1.5 chs struct uvm_anonblock {
61 1.5 chs LIST_ENTRY(uvm_anonblock) list;
62 1.5 chs int count;
63 1.5 chs struct vm_anon *anons;
64 1.5 chs };
65 1.5 chs static LIST_HEAD(anonlist, uvm_anonblock) anonblock_list;
66 1.5 chs
67 1.5 chs
68 1.28 junyoung static boolean_t anon_pagein(struct vm_anon *);
69 1.5 chs
70 1.5 chs
71 1.5 chs /*
72 1.1 chuck * allocate anons
73 1.1 chuck */
74 1.1 chuck void
75 1.1 chuck uvm_anon_init()
76 1.1 chuck {
77 1.1 chuck int nanon = uvmexp.free - (uvmexp.free / 16); /* XXXCDC ??? */
78 1.5 chs
79 1.5 chs simple_lock_init(&uvm.afreelock);
80 1.5 chs LIST_INIT(&anonblock_list);
81 1.1 chuck
82 1.1 chuck /*
83 1.1 chuck * Allocate the initial anons.
84 1.1 chuck */
85 1.5 chs uvm_anon_add(nanon);
86 1.1 chuck }
87 1.1 chuck
88 1.1 chuck /*
89 1.1 chuck * add some more anons to the free pool. called when we add
90 1.1 chuck * more swap space.
91 1.5 chs *
92 1.5 chs * => swap_syscall_lock should be held (protects anonblock_list).
93 1.1 chuck */
94 1.11 chs int
95 1.5 chs uvm_anon_add(count)
96 1.5 chs int count;
97 1.1 chuck {
98 1.5 chs struct uvm_anonblock *anonblock;
99 1.1 chuck struct vm_anon *anon;
100 1.5 chs int lcv, needed;
101 1.1 chuck
102 1.5 chs simple_lock(&uvm.afreelock);
103 1.5 chs uvmexp.nanonneeded += count;
104 1.5 chs needed = uvmexp.nanonneeded - uvmexp.nanon;
105 1.5 chs simple_unlock(&uvm.afreelock);
106 1.5 chs
107 1.5 chs if (needed <= 0) {
108 1.11 chs return 0;
109 1.5 chs }
110 1.5 chs anon = (void *)uvm_km_alloc(kernel_map, sizeof(*anon) * needed);
111 1.11 chs if (anon == NULL) {
112 1.11 chs simple_lock(&uvm.afreelock);
113 1.11 chs uvmexp.nanonneeded -= count;
114 1.11 chs simple_unlock(&uvm.afreelock);
115 1.11 chs return ENOMEM;
116 1.1 chuck }
117 1.11 chs MALLOC(anonblock, void *, sizeof(*anonblock), M_UVMAMAP, M_WAITOK);
118 1.1 chuck
119 1.5 chs anonblock->count = needed;
120 1.5 chs anonblock->anons = anon;
121 1.5 chs LIST_INSERT_HEAD(&anonblock_list, anonblock, list);
122 1.5 chs memset(anon, 0, sizeof(*anon) * needed);
123 1.17 chs
124 1.1 chuck simple_lock(&uvm.afreelock);
125 1.5 chs uvmexp.nanon += needed;
126 1.5 chs uvmexp.nfreeanon += needed;
127 1.5 chs for (lcv = 0; lcv < needed; lcv++) {
128 1.27 chs simple_lock_init(&anon[lcv].an_lock);
129 1.1 chuck anon[lcv].u.an_nxt = uvm.afree;
130 1.1 chuck uvm.afree = &anon[lcv];
131 1.1 chuck }
132 1.1 chuck simple_unlock(&uvm.afreelock);
133 1.11 chs return 0;
134 1.1 chuck }
135 1.1 chuck
136 1.1 chuck /*
137 1.5 chs * remove anons from the free pool.
138 1.5 chs */
139 1.5 chs void
140 1.5 chs uvm_anon_remove(count)
141 1.5 chs int count;
142 1.5 chs {
143 1.5 chs /*
144 1.5 chs * we never actually free any anons, to avoid allocation overhead.
145 1.5 chs * XXX someday we might want to try to free anons.
146 1.5 chs */
147 1.5 chs
148 1.5 chs simple_lock(&uvm.afreelock);
149 1.5 chs uvmexp.nanonneeded -= count;
150 1.5 chs simple_unlock(&uvm.afreelock);
151 1.5 chs }
152 1.5 chs
153 1.5 chs /*
154 1.1 chuck * allocate an anon
155 1.13 thorpej *
156 1.13 thorpej * => new anon is returned locked!
157 1.1 chuck */
158 1.1 chuck struct vm_anon *
159 1.1 chuck uvm_analloc()
160 1.1 chuck {
161 1.1 chuck struct vm_anon *a;
162 1.1 chuck
163 1.1 chuck simple_lock(&uvm.afreelock);
164 1.1 chuck a = uvm.afree;
165 1.1 chuck if (a) {
166 1.1 chuck uvm.afree = a->u.an_nxt;
167 1.1 chuck uvmexp.nfreeanon--;
168 1.1 chuck a->an_ref = 1;
169 1.1 chuck a->an_swslot = 0;
170 1.1 chuck a->u.an_page = NULL; /* so we can free quickly */
171 1.13 thorpej LOCK_ASSERT(simple_lock_held(&a->an_lock) == 0);
172 1.13 thorpej simple_lock(&a->an_lock);
173 1.1 chuck }
174 1.1 chuck simple_unlock(&uvm.afreelock);
175 1.1 chuck return(a);
176 1.1 chuck }
177 1.1 chuck
178 1.1 chuck /*
179 1.1 chuck * uvm_anfree: free a single anon structure
180 1.1 chuck *
181 1.1 chuck * => caller must remove anon from its amap before calling (if it was in
182 1.1 chuck * an amap).
183 1.1 chuck * => anon must be unlocked and have a zero reference count.
184 1.1 chuck * => we may lock the pageq's.
185 1.1 chuck */
186 1.20 chs
187 1.1 chuck void
188 1.1 chuck uvm_anfree(anon)
189 1.1 chuck struct vm_anon *anon;
190 1.1 chuck {
191 1.1 chuck struct vm_page *pg;
192 1.1 chuck UVMHIST_FUNC("uvm_anfree"); UVMHIST_CALLED(maphist);
193 1.1 chuck UVMHIST_LOG(maphist,"(anon=0x%x)", anon, 0,0,0);
194 1.1 chuck
195 1.12 thorpej KASSERT(anon->an_ref == 0);
196 1.18 chs LOCK_ASSERT(!simple_lock_held(&anon->an_lock));
197 1.12 thorpej
198 1.1 chuck /*
199 1.1 chuck * get page
200 1.1 chuck */
201 1.1 chuck
202 1.1 chuck pg = anon->u.an_page;
203 1.1 chuck
204 1.1 chuck /*
205 1.1 chuck * if there is a resident page and it is loaned, then anon may not
206 1.1 chuck * own it. call out to uvm_anon_lockpage() to ensure the real owner
207 1.1 chuck * of the page has been identified and locked.
208 1.1 chuck */
209 1.1 chuck
210 1.22 chs if (pg && pg->loan_count) {
211 1.22 chs simple_lock(&anon->an_lock);
212 1.1 chuck pg = uvm_anon_lockloanpg(anon);
213 1.22 chs simple_unlock(&anon->an_lock);
214 1.22 chs }
215 1.1 chuck
216 1.1 chuck /*
217 1.1 chuck * if we have a resident page, we must dispose of it before freeing
218 1.1 chuck * the anon.
219 1.1 chuck */
220 1.1 chuck
221 1.1 chuck if (pg) {
222 1.1 chuck
223 1.1 chuck /*
224 1.17 chs * if the page is owned by a uobject (now locked), then we must
225 1.1 chuck * kill the loan on the page rather than free it.
226 1.1 chuck */
227 1.1 chuck
228 1.1 chuck if (pg->uobject) {
229 1.1 chuck uvm_lock_pageq();
230 1.10 chs KASSERT(pg->loan_count > 0);
231 1.1 chuck pg->loan_count--;
232 1.1 chuck pg->uanon = NULL;
233 1.1 chuck uvm_unlock_pageq();
234 1.1 chuck simple_unlock(&pg->uobject->vmobjlock);
235 1.1 chuck } else {
236 1.1 chuck
237 1.1 chuck /*
238 1.1 chuck * page has no uobject, so we must be the owner of it.
239 1.18 chs * if page is busy then we wait until it is not busy,
240 1.18 chs * and then free it.
241 1.1 chuck */
242 1.1 chuck
243 1.18 chs KASSERT((pg->flags & PG_RELEASED) == 0);
244 1.19 chs simple_lock(&anon->an_lock);
245 1.18 chs pmap_page_protect(pg, VM_PROT_NONE);
246 1.29 yamt
247 1.29 yamt /*
248 1.29 yamt * if the page is busy, mark it as PG_RELEASED
249 1.29 yamt * so that uvm_anon_release will release it later.
250 1.29 yamt */
251 1.29 yamt
252 1.29 yamt if (pg->flags & PG_BUSY) {
253 1.29 yamt pg->flags |= PG_RELEASED;
254 1.29 yamt simple_unlock(&anon->an_lock);
255 1.29 yamt return;
256 1.17 chs }
257 1.29 yamt uvm_lock_pageq();
258 1.29 yamt uvm_pagefree(pg);
259 1.29 yamt uvm_unlock_pageq();
260 1.19 chs simple_unlock(&anon->an_lock);
261 1.18 chs UVMHIST_LOG(maphist, "anon 0x%x, page 0x%x: "
262 1.18 chs "freed now!", anon, pg, 0, 0);
263 1.1 chuck }
264 1.1 chuck }
265 1.26 pk if (pg == NULL && anon->an_swslot > 0) {
266 1.20 chs /* this page is no longer only in swap. */
267 1.20 chs simple_lock(&uvm.swap_data_lock);
268 1.20 chs KASSERT(uvmexp.swpgonly > 0);
269 1.20 chs uvmexp.swpgonly--;
270 1.20 chs simple_unlock(&uvm.swap_data_lock);
271 1.20 chs }
272 1.1 chuck
273 1.1 chuck /*
274 1.2 chs * free any swap resources.
275 1.1 chuck */
276 1.18 chs
277 1.2 chs uvm_anon_dropswap(anon);
278 1.1 chuck
279 1.1 chuck /*
280 1.18 chs * now that we've stripped the data areas from the anon,
281 1.18 chs * free the anon itself.
282 1.1 chuck */
283 1.18 chs
284 1.1 chuck simple_lock(&uvm.afreelock);
285 1.1 chuck anon->u.an_nxt = uvm.afree;
286 1.1 chuck uvm.afree = anon;
287 1.1 chuck uvmexp.nfreeanon++;
288 1.1 chuck simple_unlock(&uvm.afreelock);
289 1.1 chuck UVMHIST_LOG(maphist,"<- done!",0,0,0,0);
290 1.2 chs }
291 1.2 chs
292 1.2 chs /*
293 1.2 chs * uvm_anon_dropswap: release any swap resources from this anon.
294 1.17 chs *
295 1.2 chs * => anon must be locked or have a reference count of 0.
296 1.2 chs */
297 1.2 chs void
298 1.2 chs uvm_anon_dropswap(anon)
299 1.2 chs struct vm_anon *anon;
300 1.2 chs {
301 1.2 chs UVMHIST_FUNC("uvm_anon_dropswap"); UVMHIST_CALLED(maphist);
302 1.12 thorpej
303 1.12 thorpej if (anon->an_swslot == 0)
304 1.2 chs return;
305 1.2 chs
306 1.2 chs UVMHIST_LOG(maphist,"freeing swap for anon %p, paged to swslot 0x%x",
307 1.2 chs anon, anon->an_swslot, 0, 0);
308 1.2 chs uvm_swap_free(anon->an_swslot, 1);
309 1.2 chs anon->an_swslot = 0;
310 1.1 chuck }
311 1.1 chuck
312 1.1 chuck /*
313 1.1 chuck * uvm_anon_lockloanpg: given a locked anon, lock its resident page
314 1.1 chuck *
315 1.1 chuck * => anon is locked by caller
316 1.1 chuck * => on return: anon is locked
317 1.1 chuck * if there is a resident page:
318 1.1 chuck * if it has a uobject, it is locked by us
319 1.1 chuck * if it is ownerless, we take over as owner
320 1.1 chuck * we return the resident page (it can change during
321 1.1 chuck * this function)
322 1.1 chuck * => note that the only time an anon has an ownerless resident page
323 1.1 chuck * is if the page was loaned from a uvm_object and the uvm_object
324 1.1 chuck * disowned it
325 1.1 chuck * => this only needs to be called when you want to do an operation
326 1.1 chuck * on an anon's resident page and that page has a non-zero loan
327 1.1 chuck * count.
328 1.1 chuck */
329 1.1 chuck struct vm_page *
330 1.1 chuck uvm_anon_lockloanpg(anon)
331 1.1 chuck struct vm_anon *anon;
332 1.1 chuck {
333 1.1 chuck struct vm_page *pg;
334 1.1 chuck boolean_t locked = FALSE;
335 1.1 chuck
336 1.12 thorpej LOCK_ASSERT(simple_lock_held(&anon->an_lock));
337 1.12 thorpej
338 1.1 chuck /*
339 1.1 chuck * loop while we have a resident page that has a non-zero loan count.
340 1.1 chuck * if we successfully get our lock, we will "break" the loop.
341 1.1 chuck * note that the test for pg->loan_count is not protected -- this
342 1.1 chuck * may produce false positive results. note that a false positive
343 1.1 chuck * result may cause us to do more work than we need to, but it will
344 1.1 chuck * not produce an incorrect result.
345 1.1 chuck */
346 1.1 chuck
347 1.1 chuck while (((pg = anon->u.an_page) != NULL) && pg->loan_count != 0) {
348 1.1 chuck
349 1.1 chuck /*
350 1.1 chuck * quickly check to see if the page has an object before
351 1.1 chuck * bothering to lock the page queues. this may also produce
352 1.1 chuck * a false positive result, but that's ok because we do a real
353 1.1 chuck * check after that.
354 1.1 chuck */
355 1.1 chuck
356 1.1 chuck if (pg->uobject) {
357 1.1 chuck uvm_lock_pageq();
358 1.18 chs if (pg->uobject) {
359 1.1 chuck locked =
360 1.1 chuck simple_lock_try(&pg->uobject->vmobjlock);
361 1.1 chuck } else {
362 1.1 chuck /* object disowned before we got PQ lock */
363 1.1 chuck locked = TRUE;
364 1.1 chuck }
365 1.1 chuck uvm_unlock_pageq();
366 1.1 chuck
367 1.1 chuck /*
368 1.1 chuck * if we didn't get a lock (try lock failed), then we
369 1.1 chuck * toggle our anon lock and try again
370 1.1 chuck */
371 1.1 chuck
372 1.1 chuck if (!locked) {
373 1.1 chuck simple_unlock(&anon->an_lock);
374 1.10 chs
375 1.1 chuck /*
376 1.1 chuck * someone locking the object has a chance to
377 1.1 chuck * lock us right now
378 1.1 chuck */
379 1.10 chs
380 1.1 chuck simple_lock(&anon->an_lock);
381 1.10 chs continue;
382 1.1 chuck }
383 1.1 chuck }
384 1.1 chuck
385 1.1 chuck /*
386 1.1 chuck * if page is un-owned [i.e. the object dropped its ownership],
387 1.1 chuck * then we can take over as owner!
388 1.1 chuck */
389 1.1 chuck
390 1.1 chuck if (pg->uobject == NULL && (pg->pqflags & PQ_ANON) == 0) {
391 1.1 chuck uvm_lock_pageq();
392 1.18 chs pg->pqflags |= PQ_ANON;
393 1.18 chs pg->loan_count--;
394 1.1 chuck uvm_unlock_pageq();
395 1.1 chuck }
396 1.1 chuck break;
397 1.1 chuck }
398 1.1 chuck return(pg);
399 1.5 chs }
400 1.5 chs
401 1.5 chs
402 1.5 chs
403 1.5 chs /*
404 1.5 chs * page in every anon that is paged out to a range of swslots.
405 1.17 chs *
406 1.5 chs * swap_syscall_lock should be held (protects anonblock_list).
407 1.5 chs */
408 1.5 chs
409 1.5 chs boolean_t
410 1.5 chs anon_swap_off(startslot, endslot)
411 1.5 chs int startslot, endslot;
412 1.5 chs {
413 1.5 chs struct uvm_anonblock *anonblock;
414 1.5 chs
415 1.18 chs LIST_FOREACH(anonblock, &anonblock_list, list) {
416 1.5 chs int i;
417 1.5 chs
418 1.5 chs /*
419 1.5 chs * loop thru all the anons in the anonblock,
420 1.5 chs * paging in where needed.
421 1.5 chs */
422 1.5 chs
423 1.5 chs for (i = 0; i < anonblock->count; i++) {
424 1.5 chs struct vm_anon *anon = &anonblock->anons[i];
425 1.5 chs int slot;
426 1.5 chs
427 1.5 chs /*
428 1.5 chs * lock anon to work on it.
429 1.5 chs */
430 1.5 chs
431 1.5 chs simple_lock(&anon->an_lock);
432 1.5 chs
433 1.5 chs /*
434 1.5 chs * is this anon's swap slot in range?
435 1.5 chs */
436 1.5 chs
437 1.5 chs slot = anon->an_swslot;
438 1.5 chs if (slot >= startslot && slot < endslot) {
439 1.5 chs boolean_t rv;
440 1.5 chs
441 1.5 chs /*
442 1.5 chs * yup, page it in.
443 1.5 chs */
444 1.5 chs
445 1.5 chs /* locked: anon */
446 1.5 chs rv = anon_pagein(anon);
447 1.5 chs /* unlocked: anon */
448 1.5 chs
449 1.5 chs if (rv) {
450 1.5 chs return rv;
451 1.5 chs }
452 1.5 chs } else {
453 1.5 chs
454 1.5 chs /*
455 1.5 chs * nope, unlock and proceed.
456 1.5 chs */
457 1.5 chs
458 1.5 chs simple_unlock(&anon->an_lock);
459 1.5 chs }
460 1.5 chs }
461 1.5 chs }
462 1.5 chs return FALSE;
463 1.5 chs }
464 1.5 chs
465 1.5 chs
466 1.5 chs /*
467 1.5 chs * fetch an anon's page.
468 1.5 chs *
469 1.5 chs * => anon must be locked, and is unlocked upon return.
470 1.5 chs * => returns TRUE if pagein was aborted due to lack of memory.
471 1.5 chs */
472 1.5 chs
473 1.5 chs static boolean_t
474 1.5 chs anon_pagein(anon)
475 1.5 chs struct vm_anon *anon;
476 1.5 chs {
477 1.5 chs struct vm_page *pg;
478 1.5 chs struct uvm_object *uobj;
479 1.5 chs int rv;
480 1.8 thorpej
481 1.5 chs /* locked: anon */
482 1.12 thorpej LOCK_ASSERT(simple_lock_held(&anon->an_lock));
483 1.12 thorpej
484 1.5 chs rv = uvmfault_anonget(NULL, NULL, anon);
485 1.12 thorpej
486 1.8 thorpej /*
487 1.16 chs * if rv == 0, anon is still locked, else anon
488 1.8 thorpej * is unlocked
489 1.8 thorpej */
490 1.5 chs
491 1.5 chs switch (rv) {
492 1.16 chs case 0:
493 1.5 chs break;
494 1.5 chs
495 1.16 chs case EIO:
496 1.16 chs case ERESTART:
497 1.5 chs
498 1.5 chs /*
499 1.5 chs * nothing more to do on errors.
500 1.16 chs * ERESTART can only mean that the anon was freed,
501 1.5 chs * so again there's nothing to do.
502 1.5 chs */
503 1.5 chs
504 1.5 chs return FALSE;
505 1.25 pk
506 1.25 pk default:
507 1.25 pk return TRUE;
508 1.5 chs }
509 1.5 chs
510 1.5 chs /*
511 1.5 chs * ok, we've got the page now.
512 1.5 chs * mark it as dirty, clear its swslot and un-busy it.
513 1.5 chs */
514 1.5 chs
515 1.5 chs pg = anon->u.an_page;
516 1.5 chs uobj = pg->uobject;
517 1.23 pk if (anon->an_swslot > 0)
518 1.23 pk uvm_swap_free(anon->an_swslot, 1);
519 1.5 chs anon->an_swslot = 0;
520 1.5 chs pg->flags &= ~(PG_CLEAN);
521 1.5 chs
522 1.5 chs /*
523 1.5 chs * deactivate the page (to put it on a page queue)
524 1.5 chs */
525 1.5 chs
526 1.5 chs pmap_clear_reference(pg);
527 1.5 chs uvm_lock_pageq();
528 1.24 pk if (pg->wire_count == 0)
529 1.24 pk uvm_pagedeactivate(pg);
530 1.5 chs uvm_unlock_pageq();
531 1.25 pk
532 1.25 pk if (pg->flags & PG_WANTED) {
533 1.25 pk wakeup(pg);
534 1.25 pk pg->flags &= ~(PG_WANTED);
535 1.25 pk }
536 1.5 chs
537 1.5 chs /*
538 1.5 chs * unlock the anon and we're done.
539 1.5 chs */
540 1.5 chs
541 1.5 chs simple_unlock(&anon->an_lock);
542 1.5 chs if (uobj) {
543 1.5 chs simple_unlock(&uobj->vmobjlock);
544 1.5 chs }
545 1.5 chs return FALSE;
546 1.1 chuck }
547 1.29 yamt
548 1.29 yamt /*
549 1.29 yamt * uvm_anon_release: release an anon and its page.
550 1.29 yamt *
551 1.29 yamt * => caller must lock the anon.
552 1.29 yamt */
553 1.29 yamt
554 1.29 yamt void
555 1.29 yamt uvm_anon_release(anon)
556 1.29 yamt struct vm_anon *anon;
557 1.29 yamt {
558 1.29 yamt struct vm_page *pg = anon->u.an_page;
559 1.29 yamt
560 1.29 yamt LOCK_ASSERT(simple_lock_held(&anon->an_lock));
561 1.29 yamt
562 1.29 yamt KASSERT(pg != NULL);
563 1.29 yamt KASSERT((pg->flags & PG_RELEASED) != 0);
564 1.29 yamt KASSERT((pg->flags & PG_BUSY) != 0);
565 1.29 yamt KASSERT(pg->uobject == NULL);
566 1.29 yamt KASSERT(pg->uanon == anon);
567 1.29 yamt KASSERT(pg->loan_count == 0);
568 1.29 yamt KASSERT(anon->an_ref == 0);
569 1.29 yamt
570 1.29 yamt uvm_lock_pageq();
571 1.29 yamt uvm_pagefree(pg);
572 1.29 yamt uvm_unlock_pageq();
573 1.29 yamt simple_unlock(&anon->an_lock);
574 1.29 yamt
575 1.29 yamt KASSERT(anon->u.an_page == NULL);
576 1.29 yamt
577 1.29 yamt uvm_anfree(anon);
578 1.29 yamt }
579