Home | History | Annotate | Line # | Download | only in uvm
uvm_anon.c revision 1.68
      1  1.68       chs /*	$NetBSD: uvm_anon.c,v 1.68 2019/12/02 20:02:02 chs Exp $	*/
      2   1.1     chuck 
      3   1.1     chuck /*
      4   1.1     chuck  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5   1.1     chuck  * All rights reserved.
      6   1.1     chuck  *
      7   1.1     chuck  * Redistribution and use in source and binary forms, with or without
      8   1.1     chuck  * modification, are permitted provided that the following conditions
      9   1.1     chuck  * are met:
     10   1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     11   1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     12   1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     14   1.1     chuck  *    documentation and/or other materials provided with the distribution.
     15   1.1     chuck  *
     16   1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1     chuck  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1     chuck  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1     chuck  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1     chuck  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21   1.1     chuck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22   1.1     chuck  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23   1.1     chuck  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24   1.1     chuck  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25   1.1     chuck  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26   1.1     chuck  */
     27   1.1     chuck 
     28   1.1     chuck /*
     29   1.1     chuck  * uvm_anon.c: uvm anon ops
     30   1.1     chuck  */
     31  1.21     lukem 
     32  1.21     lukem #include <sys/cdefs.h>
     33  1.68       chs __KERNEL_RCSID(0, "$NetBSD: uvm_anon.c,v 1.68 2019/12/02 20:02:02 chs Exp $");
     34   1.1     chuck 
     35   1.1     chuck #include "opt_uvmhist.h"
     36   1.1     chuck 
     37   1.1     chuck #include <sys/param.h>
     38   1.1     chuck #include <sys/systm.h>
     39   1.1     chuck #include <sys/pool.h>
     40   1.5       chs #include <sys/kernel.h>
     41  1.67       uwe #include <sys/atomic.h>
     42   1.1     chuck 
     43   1.1     chuck #include <uvm/uvm.h>
     44   1.1     chuck #include <uvm/uvm_swap.h>
     45  1.39      yamt #include <uvm/uvm_pdpolicy.h>
     46   1.1     chuck 
     47  1.55     rmind static struct pool_cache	uvm_anon_cache;
     48   1.5       chs 
     49  1.55     rmind static int			uvm_anon_ctor(void *, void *, int);
     50   1.5       chs 
     51   1.1     chuck void
     52  1.34   thorpej uvm_anon_init(void)
     53   1.1     chuck {
     54   1.5       chs 
     55  1.49        ad 	pool_cache_bootstrap(&uvm_anon_cache, sizeof(struct vm_anon), 0, 0,
     56  1.49        ad 	    PR_LARGECACHE, "anonpl", NULL, IPL_NONE, uvm_anon_ctor,
     57  1.55     rmind 	    NULL, NULL);
     58   1.1     chuck }
     59   1.1     chuck 
     60  1.33      yamt static int
     61  1.41      yamt uvm_anon_ctor(void *arg, void *object, int flags)
     62   1.1     chuck {
     63  1.33      yamt 	struct vm_anon *anon = object;
     64   1.1     chuck 
     65  1.33      yamt 	anon->an_ref = 0;
     66  1.59     rmind 	anon->an_lock = NULL;
     67  1.33      yamt 	anon->an_page = NULL;
     68  1.37      yamt #if defined(VMSWAP)
     69  1.33      yamt 	anon->an_swslot = 0;
     70  1.55     rmind #endif
     71  1.11       chs 	return 0;
     72   1.1     chuck }
     73   1.1     chuck 
     74   1.1     chuck /*
     75  1.55     rmind  * uvm_analloc: allocate a new anon.
     76  1.13   thorpej  *
     77  1.55     rmind  * => anon will have no lock associated.
     78   1.1     chuck  */
     79   1.1     chuck struct vm_anon *
     80  1.34   thorpej uvm_analloc(void)
     81   1.1     chuck {
     82  1.33      yamt 	struct vm_anon *anon;
     83   1.1     chuck 
     84  1.47        ad 	anon = pool_cache_get(&uvm_anon_cache, PR_NOWAIT);
     85  1.33      yamt 	if (anon) {
     86  1.33      yamt 		KASSERT(anon->an_ref == 0);
     87  1.59     rmind 		KASSERT(anon->an_lock == NULL);
     88  1.33      yamt 		KASSERT(anon->an_page == NULL);
     89  1.37      yamt #if defined(VMSWAP)
     90  1.33      yamt 		KASSERT(anon->an_swslot == 0);
     91  1.55     rmind #endif
     92  1.33      yamt 		anon->an_ref = 1;
     93   1.1     chuck 	}
     94  1.33      yamt 	return anon;
     95   1.1     chuck }
     96   1.1     chuck 
     97   1.1     chuck /*
     98  1.66        ad  * uvm_anon_dispose: break loans and remove pmap mapping
     99   1.1     chuck  *
    100  1.55     rmind  * => anon must be removed from the amap (if anon was in an amap).
    101  1.59     rmind  * => amap must be locked; we may drop and re-acquire the lock here.
    102   1.1     chuck  */
    103  1.60     rmind static bool
    104  1.59     rmind uvm_anon_dispose(struct vm_anon *anon)
    105   1.1     chuck {
    106  1.55     rmind 	struct vm_page *pg = anon->an_page;
    107  1.55     rmind 
    108  1.59     rmind 	UVMHIST_FUNC("uvm_anon_dispose"); UVMHIST_CALLED(maphist);
    109  1.64  pgoyette 	UVMHIST_LOG(maphist,"(anon=0x%#jx)", (uintptr_t)anon, 0,0,0);
    110   1.1     chuck 
    111  1.59     rmind 	KASSERT(mutex_owned(anon->an_lock));
    112  1.12   thorpej 
    113   1.1     chuck 	/*
    114  1.66        ad 	 * Dispose the page, if it is resident.
    115   1.1     chuck 	 */
    116   1.1     chuck 
    117  1.66        ad 	if (pg) {
    118  1.54     rmind 		KASSERT(anon->an_lock != NULL);
    119   1.1     chuck 
    120  1.66        ad 		/*
    121  1.66        ad 		 * If there is a resident page and it is loaned, then anon
    122  1.66        ad 		 * may not own it.  Call out to uvm_anon_lockloanpg() to
    123  1.66        ad 		 * identify and lock the real owner of the page.
    124  1.66        ad 		 */
    125   1.1     chuck 
    126  1.66        ad 		if (pg->loan_count) {
    127  1.66        ad 			pg = uvm_anon_lockloanpg(anon);
    128  1.66        ad 		}
    129   1.1     chuck 
    130   1.1     chuck 		/*
    131  1.55     rmind 		 * If the page is owned by a UVM object (now locked),
    132  1.55     rmind 		 * then kill the loan on the page rather than free it,
    133  1.55     rmind 		 * and release the object lock.
    134   1.1     chuck 		 */
    135   1.1     chuck 
    136   1.1     chuck 		if (pg->uobject) {
    137  1.50        ad 			mutex_enter(&uvm_pageqlock);
    138  1.10       chs 			KASSERT(pg->loan_count > 0);
    139   1.1     chuck 			pg->loan_count--;
    140   1.1     chuck 			pg->uanon = NULL;
    141  1.50        ad 			mutex_exit(&uvm_pageqlock);
    142  1.54     rmind 			mutex_exit(pg->uobject->vmobjlock);
    143   1.1     chuck 		} else {
    144   1.1     chuck 
    145   1.1     chuck 			/*
    146  1.55     rmind 			 * If page has no UVM object, then anon is the owner,
    147  1.55     rmind 			 * and it is already locked.
    148   1.1     chuck 			 */
    149   1.1     chuck 
    150  1.18       chs 			KASSERT((pg->flags & PG_RELEASED) == 0);
    151  1.18       chs 			pmap_page_protect(pg, VM_PROT_NONE);
    152  1.29      yamt 
    153  1.29      yamt 			/*
    154  1.55     rmind 			 * If the page is busy, mark it as PG_RELEASED, so
    155  1.55     rmind 			 * that uvm_anon_release(9) would release it later.
    156  1.29      yamt 			 */
    157  1.29      yamt 
    158  1.29      yamt 			if (pg->flags & PG_BUSY) {
    159  1.29      yamt 				pg->flags |= PG_RELEASED;
    160  1.58      yamt 				mutex_obj_hold(anon->an_lock);
    161  1.60     rmind 				return false;
    162  1.17       chs 			}
    163   1.1     chuck 		}
    164   1.1     chuck 	}
    165  1.55     rmind 
    166  1.37      yamt #if defined(VMSWAP)
    167  1.26        pk 	if (pg == NULL && anon->an_swslot > 0) {
    168  1.55     rmind 		/* This page is no longer only in swap. */
    169  1.20       chs 		KASSERT(uvmexp.swpgonly > 0);
    170  1.65        ad 		atomic_dec_uint(&uvmexp.swpgonly);
    171  1.20       chs 	}
    172  1.55     rmind #endif
    173   1.1     chuck 
    174  1.59     rmind 	UVMHIST_LOG(maphist,"<- done!",0,0,0,0);
    175  1.60     rmind 	return true;
    176  1.59     rmind }
    177  1.59     rmind 
    178  1.59     rmind /*
    179  1.59     rmind  * uvm_anon_free: free a single anon.
    180  1.59     rmind  *
    181  1.59     rmind  * => anon must be already disposed.
    182  1.59     rmind  */
    183  1.59     rmind void
    184  1.59     rmind uvm_anon_free(struct vm_anon *anon)
    185  1.59     rmind {
    186  1.39      yamt 
    187  1.66        ad #if defined(VMSWAP)
    188  1.66        ad 	/* Free any dangling swap slot. */
    189  1.66        ad 	uvm_anon_dropswap(anon);
    190  1.66        ad #endif
    191  1.59     rmind 	KASSERT(anon->an_ref == 0);
    192  1.59     rmind 	KASSERT(anon->an_lock == NULL);
    193  1.33      yamt 	KASSERT(anon->an_page == NULL);
    194  1.37      yamt #if defined(VMSWAP)
    195  1.31      yamt 	KASSERT(anon->an_swslot == 0);
    196  1.55     rmind #endif
    197  1.47        ad 	pool_cache_put(&uvm_anon_cache, anon);
    198   1.2       chs }
    199   1.2       chs 
    200  1.55     rmind /*
    201  1.59     rmind  * uvm_anon_freelst: free a linked list of anon structures.
    202  1.59     rmind  *
    203  1.66        ad  * => amap must be locked, we will unlock it.
    204  1.55     rmind  */
    205  1.54     rmind void
    206  1.59     rmind uvm_anon_freelst(struct vm_amap *amap, struct vm_anon *anonlst)
    207  1.54     rmind {
    208  1.61      yamt 	struct vm_anon *anon;
    209  1.61      yamt 	struct vm_anon **anonp = &anonlst;
    210  1.66        ad 	struct vm_page *pg;
    211  1.59     rmind 
    212  1.68       chs 	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
    213  1.68       chs 
    214  1.59     rmind 	KASSERT(mutex_owned(amap->am_lock));
    215  1.66        ad 
    216  1.66        ad 	if (anonlst == NULL) {
    217  1.66        ad 		amap_unlock(amap);
    218  1.66        ad 		return;
    219  1.66        ad 	}
    220  1.66        ad 
    221  1.66        ad 	/* Break loans and hardware mappings.  Defer release of busy pages. */
    222  1.61      yamt 	while ((anon = *anonp) != NULL) {
    223  1.60     rmind 		if (!uvm_anon_dispose(anon)) {
    224  1.60     rmind 			/* Do not free this anon. */
    225  1.61      yamt 			*anonp = anon->an_link;
    226  1.61      yamt 			/* Note: clears an_ref as well. */
    227  1.61      yamt 			anon->an_link = NULL;
    228  1.61      yamt 		} else {
    229  1.61      yamt 			anonp = &anon->an_link;
    230  1.60     rmind 		}
    231  1.59     rmind 	}
    232  1.66        ad 
    233  1.66        ad 	/* Free pages and leave a page replacement hint. */
    234  1.66        ad 	mutex_enter(&uvm_pageqlock);
    235  1.66        ad 	for (anon = anonlst; anon != NULL; anon = anon->an_link) {
    236  1.66        ad 		UVMHIST_LOG(maphist, "anon 0x%#jx, page 0x%#jx: "
    237  1.66        ad 		    "releasing now!", (uintptr_t)anon,
    238  1.66        ad 		    (uintptr_t)anon->an_page, 0, 0);
    239  1.66        ad 		if ((pg = anon->an_page) != NULL) {
    240  1.66        ad 			uvm_pagefree(pg);
    241  1.66        ad 		}
    242  1.66        ad 		uvmpdpol_anfree(anon);
    243  1.66        ad 	}
    244  1.66        ad 	mutex_exit(&uvm_pageqlock);
    245  1.59     rmind 	amap_unlock(amap);
    246  1.59     rmind 
    247  1.66        ad 	/* Free swap space, pages and vm_anon. */
    248  1.59     rmind 	while (anonlst) {
    249  1.59     rmind 		anon = anonlst->an_link;
    250  1.59     rmind 		/* Note: clears an_ref as well. */
    251  1.59     rmind 		anonlst->an_link = NULL;
    252  1.59     rmind 		anonlst->an_lock = NULL;
    253  1.59     rmind 		uvm_anon_free(anonlst);
    254  1.59     rmind 		anonlst = anon;
    255  1.54     rmind 	}
    256  1.54     rmind }
    257  1.54     rmind 
    258   1.2       chs /*
    259  1.55     rmind  * uvm_anon_lockloanpg: given a locked anon, lock its resident page owner.
    260   1.1     chuck  *
    261   1.1     chuck  * => anon is locked by caller
    262   1.1     chuck  * => on return: anon is locked
    263   1.1     chuck  *		 if there is a resident page:
    264   1.1     chuck  *			if it has a uobject, it is locked by us
    265   1.1     chuck  *			if it is ownerless, we take over as owner
    266   1.1     chuck  *		 we return the resident page (it can change during
    267   1.1     chuck  *		 this function)
    268   1.1     chuck  * => note that the only time an anon has an ownerless resident page
    269   1.1     chuck  *	is if the page was loaned from a uvm_object and the uvm_object
    270   1.1     chuck  *	disowned it
    271   1.1     chuck  * => this only needs to be called when you want to do an operation
    272   1.1     chuck  *	on an anon's resident page and that page has a non-zero loan
    273   1.1     chuck  *	count.
    274   1.1     chuck  */
    275   1.1     chuck struct vm_page *
    276  1.34   thorpej uvm_anon_lockloanpg(struct vm_anon *anon)
    277   1.1     chuck {
    278   1.1     chuck 	struct vm_page *pg;
    279  1.43   thorpej 	bool locked = false;
    280   1.1     chuck 
    281  1.54     rmind 	KASSERT(mutex_owned(anon->an_lock));
    282  1.12   thorpej 
    283   1.1     chuck 	/*
    284   1.1     chuck 	 * loop while we have a resident page that has a non-zero loan count.
    285   1.1     chuck 	 * if we successfully get our lock, we will "break" the loop.
    286   1.1     chuck 	 * note that the test for pg->loan_count is not protected -- this
    287   1.1     chuck 	 * may produce false positive results.   note that a false positive
    288   1.1     chuck 	 * result may cause us to do more work than we need to, but it will
    289   1.1     chuck 	 * not produce an incorrect result.
    290   1.1     chuck 	 */
    291   1.1     chuck 
    292  1.33      yamt 	while (((pg = anon->an_page) != NULL) && pg->loan_count != 0) {
    293   1.1     chuck 
    294   1.1     chuck 		/*
    295   1.1     chuck 		 * quickly check to see if the page has an object before
    296   1.1     chuck 		 * bothering to lock the page queues.   this may also produce
    297   1.1     chuck 		 * a false positive result, but that's ok because we do a real
    298   1.1     chuck 		 * check after that.
    299   1.1     chuck 		 */
    300   1.1     chuck 
    301   1.1     chuck 		if (pg->uobject) {
    302  1.50        ad 			mutex_enter(&uvm_pageqlock);
    303  1.18       chs 			if (pg->uobject) {
    304   1.1     chuck 				locked =
    305  1.54     rmind 				    mutex_tryenter(pg->uobject->vmobjlock);
    306   1.1     chuck 			} else {
    307   1.1     chuck 				/* object disowned before we got PQ lock */
    308  1.43   thorpej 				locked = true;
    309   1.1     chuck 			}
    310  1.50        ad 			mutex_exit(&uvm_pageqlock);
    311   1.1     chuck 
    312   1.1     chuck 			/*
    313   1.1     chuck 			 * if we didn't get a lock (try lock failed), then we
    314   1.1     chuck 			 * toggle our anon lock and try again
    315   1.1     chuck 			 */
    316   1.1     chuck 
    317   1.1     chuck 			if (!locked) {
    318   1.1     chuck 				/*
    319   1.1     chuck 				 * someone locking the object has a chance to
    320   1.1     chuck 				 * lock us right now
    321  1.54     rmind 				 *
    322  1.54     rmind 				 * XXX Better than yielding but inadequate.
    323   1.1     chuck 				 */
    324  1.54     rmind 				kpause("livelock", false, 1, anon->an_lock);
    325  1.10       chs 				continue;
    326   1.1     chuck 			}
    327   1.1     chuck 		}
    328   1.1     chuck 
    329   1.1     chuck 		/*
    330  1.55     rmind 		 * If page is un-owned i.e. the object dropped its ownership,
    331  1.55     rmind 		 * then we have to take the ownership.
    332   1.1     chuck 		 */
    333   1.1     chuck 
    334   1.1     chuck 		if (pg->uobject == NULL && (pg->pqflags & PQ_ANON) == 0) {
    335  1.50        ad 			mutex_enter(&uvm_pageqlock);
    336  1.18       chs 			pg->pqflags |= PQ_ANON;
    337  1.18       chs 			pg->loan_count--;
    338  1.50        ad 			mutex_exit(&uvm_pageqlock);
    339   1.1     chuck 		}
    340   1.1     chuck 		break;
    341   1.1     chuck 	}
    342  1.55     rmind 	return pg;
    343   1.5       chs }
    344   1.5       chs 
    345  1.37      yamt #if defined(VMSWAP)
    346  1.37      yamt 
    347   1.5       chs /*
    348  1.55     rmind  * uvm_anon_pagein: fetch an anon's page.
    349   1.5       chs  *
    350   1.5       chs  * => anon must be locked, and is unlocked upon return.
    351  1.43   thorpej  * => returns true if pagein was aborted due to lack of memory.
    352   1.5       chs  */
    353   1.5       chs 
    354  1.42   thorpej bool
    355  1.57     rmind uvm_anon_pagein(struct vm_amap *amap, struct vm_anon *anon)
    356   1.5       chs {
    357   1.5       chs 	struct vm_page *pg;
    358   1.5       chs 	struct uvm_object *uobj;
    359   1.8   thorpej 
    360  1.54     rmind 	KASSERT(mutex_owned(anon->an_lock));
    361  1.57     rmind 	KASSERT(anon->an_lock == amap->am_lock);
    362  1.12   thorpej 
    363   1.8   thorpej 	/*
    364  1.55     rmind 	 * Get the page of the anon.
    365   1.8   thorpej 	 */
    366   1.5       chs 
    367  1.57     rmind 	switch (uvmfault_anonget(NULL, amap, anon)) {
    368  1.16       chs 	case 0:
    369  1.55     rmind 		/* Success - we have the page. */
    370  1.55     rmind 		KASSERT(mutex_owned(anon->an_lock));
    371   1.5       chs 		break;
    372  1.16       chs 	case EIO:
    373  1.16       chs 	case ERESTART:
    374   1.5       chs 		/*
    375  1.55     rmind 		 * Nothing more to do on errors.  ERESTART means that the
    376  1.55     rmind 		 * anon was freed.
    377   1.5       chs 		 */
    378  1.43   thorpej 		return false;
    379  1.25        pk 	default:
    380  1.43   thorpej 		return true;
    381   1.5       chs 	}
    382   1.5       chs 
    383   1.5       chs 	/*
    384  1.55     rmind 	 * Mark the page as dirty, clear its swslot and un-busy it.
    385   1.5       chs 	 */
    386   1.5       chs 
    387  1.33      yamt 	pg = anon->an_page;
    388   1.5       chs 	uobj = pg->uobject;
    389  1.55     rmind 	if (anon->an_swslot > 0) {
    390  1.23        pk 		uvm_swap_free(anon->an_swslot, 1);
    391  1.55     rmind 	}
    392   1.5       chs 	anon->an_swslot = 0;
    393  1.55     rmind 	pg->flags &= ~PG_CLEAN;
    394   1.5       chs 
    395   1.5       chs 	/*
    396  1.55     rmind 	 * Deactivate the page (to put it on a page queue).
    397   1.5       chs 	 */
    398   1.5       chs 
    399  1.50        ad 	mutex_enter(&uvm_pageqlock);
    400  1.55     rmind 	if (pg->wire_count == 0) {
    401  1.24        pk 		uvm_pagedeactivate(pg);
    402  1.55     rmind 	}
    403  1.50        ad 	mutex_exit(&uvm_pageqlock);
    404  1.25        pk 
    405  1.25        pk 	if (pg->flags & PG_WANTED) {
    406  1.55     rmind 		pg->flags &= ~PG_WANTED;
    407  1.25        pk 		wakeup(pg);
    408  1.25        pk 	}
    409   1.5       chs 
    410  1.54     rmind 	mutex_exit(anon->an_lock);
    411   1.5       chs 	if (uobj) {
    412  1.54     rmind 		mutex_exit(uobj->vmobjlock);
    413   1.5       chs 	}
    414  1.43   thorpej 	return false;
    415   1.1     chuck }
    416  1.29      yamt 
    417  1.55     rmind /*
    418  1.55     rmind  * uvm_anon_dropswap: release any swap resources from this anon.
    419  1.55     rmind  *
    420  1.55     rmind  * => anon must be locked or have a reference count of 0.
    421  1.55     rmind  */
    422  1.55     rmind void
    423  1.55     rmind uvm_anon_dropswap(struct vm_anon *anon)
    424  1.55     rmind {
    425  1.55     rmind 	UVMHIST_FUNC("uvm_anon_dropswap"); UVMHIST_CALLED(maphist);
    426  1.55     rmind 
    427  1.55     rmind 	if (anon->an_swslot == 0)
    428  1.55     rmind 		return;
    429  1.55     rmind 
    430  1.64  pgoyette 	UVMHIST_LOG(maphist,"freeing swap for anon %#jx, paged to swslot 0x%jx",
    431  1.64  pgoyette 		    (uintptr_t)anon, anon->an_swslot, 0, 0);
    432  1.55     rmind 	uvm_swap_free(anon->an_swslot, 1);
    433  1.55     rmind 	anon->an_swslot = 0;
    434  1.55     rmind }
    435  1.55     rmind 
    436  1.55     rmind #endif
    437  1.37      yamt 
    438  1.29      yamt /*
    439  1.29      yamt  * uvm_anon_release: release an anon and its page.
    440  1.29      yamt  *
    441  1.55     rmind  * => anon should not have any references.
    442  1.55     rmind  * => anon must be locked.
    443  1.29      yamt  */
    444  1.29      yamt 
    445  1.29      yamt void
    446  1.34   thorpej uvm_anon_release(struct vm_anon *anon)
    447  1.29      yamt {
    448  1.33      yamt 	struct vm_page *pg = anon->an_page;
    449  1.63    martin 	bool success __diagused;
    450  1.29      yamt 
    451  1.59     rmind 	KASSERT(mutex_owned(anon->an_lock));
    452  1.29      yamt 	KASSERT(pg != NULL);
    453  1.29      yamt 	KASSERT((pg->flags & PG_RELEASED) != 0);
    454  1.29      yamt 	KASSERT((pg->flags & PG_BUSY) != 0);
    455  1.29      yamt 	KASSERT(pg->uobject == NULL);
    456  1.29      yamt 	KASSERT(pg->uanon == anon);
    457  1.29      yamt 	KASSERT(pg->loan_count == 0);
    458  1.29      yamt 	KASSERT(anon->an_ref == 0);
    459  1.29      yamt 
    460  1.50        ad 	mutex_enter(&uvm_pageqlock);
    461  1.29      yamt 	uvm_pagefree(pg);
    462  1.50        ad 	mutex_exit(&uvm_pageqlock);
    463  1.62      yamt 	KASSERT(anon->an_page == NULL);
    464  1.62      yamt 	/* dispose should succeed as no one can reach this anon anymore. */
    465  1.62      yamt 	success = uvm_anon_dispose(anon);
    466  1.62      yamt 	KASSERT(success);
    467  1.59     rmind 	mutex_exit(anon->an_lock);
    468  1.59     rmind 	/* Note: extra reference is held for PG_RELEASED case. */
    469  1.62      yamt 	mutex_obj_free(anon->an_lock);
    470  1.59     rmind 	anon->an_lock = NULL;
    471  1.59     rmind 	uvm_anon_free(anon);
    472  1.29      yamt }
    473