Home | History | Annotate | Line # | Download | only in uvm
uvm_pager.c revision 1.48.2.3
      1  1.48.2.3  jdolecek /*	$NetBSD: uvm_pager.c,v 1.48.2.3 2002/06/23 17:52:18 jdolecek Exp $	*/
      2       1.1       mrg 
      3       1.1       mrg /*
      4       1.1       mrg  *
      5       1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      6       1.1       mrg  * All rights reserved.
      7       1.1       mrg  *
      8       1.1       mrg  * Redistribution and use in source and binary forms, with or without
      9       1.1       mrg  * modification, are permitted provided that the following conditions
     10       1.1       mrg  * are met:
     11       1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     12       1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     13       1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     15       1.1       mrg  *    documentation and/or other materials provided with the distribution.
     16       1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     17       1.1       mrg  *    must display the following acknowledgement:
     18       1.1       mrg  *      This product includes software developed by Charles D. Cranor and
     19       1.1       mrg  *      Washington University.
     20       1.1       mrg  * 4. The name of the author may not be used to endorse or promote products
     21       1.1       mrg  *    derived from this software without specific prior written permission.
     22       1.1       mrg  *
     23       1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24       1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25       1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26       1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27       1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28       1.1       mrg  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29       1.1       mrg  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30       1.1       mrg  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31       1.1       mrg  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32       1.1       mrg  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33       1.3       mrg  *
     34       1.3       mrg  * from: Id: uvm_pager.c,v 1.1.2.23 1998/02/02 20:38:06 chuck Exp
     35       1.1       mrg  */
     36       1.1       mrg 
     37       1.1       mrg /*
     38       1.1       mrg  * uvm_pager.c: generic functions used to assist the pagers.
     39       1.1       mrg  */
     40       1.1       mrg 
     41  1.48.2.2   thorpej #include <sys/cdefs.h>
     42  1.48.2.3  jdolecek __KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.48.2.3 2002/06/23 17:52:18 jdolecek Exp $");
     43  1.48.2.2   thorpej 
     44  1.48.2.2   thorpej #include "opt_uvmhist.h"
     45  1.48.2.2   thorpej 
     46       1.1       mrg #include <sys/param.h>
     47       1.1       mrg #include <sys/systm.h>
     48       1.1       mrg #include <sys/proc.h>
     49       1.1       mrg #include <sys/malloc.h>
     50      1.35       chs #include <sys/pool.h>
     51      1.35       chs #include <sys/vnode.h>
     52       1.1       mrg 
     53       1.1       mrg #define UVM_PAGER
     54       1.1       mrg #include <uvm/uvm.h>
     55       1.1       mrg 
     56      1.35       chs struct pool *uvm_aiobuf_pool;
     57      1.35       chs 
     58       1.1       mrg /*
     59       1.1       mrg  * list of uvm pagers in the system
     60       1.1       mrg  */
     61       1.1       mrg 
     62  1.48.2.3  jdolecek struct uvm_pagerops * const uvmpagerops[] = {
     63      1.10   thorpej 	&aobj_pager,
     64       1.6       mrg 	&uvm_deviceops,
     65       1.6       mrg 	&uvm_vnodeops,
     66      1.35       chs 	&ubc_pager,
     67       1.1       mrg };
     68       1.1       mrg 
     69       1.1       mrg /*
     70       1.1       mrg  * the pager map: provides KVA for I/O
     71       1.1       mrg  */
     72       1.1       mrg 
     73      1.47       chs struct vm_map *pager_map;		/* XXX */
     74      1.46       chs struct simplelock pager_map_wanted_lock;
     75       1.1       mrg boolean_t pager_map_wanted;	/* locked by pager map */
     76      1.35       chs static vaddr_t emergva;
     77      1.35       chs static boolean_t emerginuse;
     78       1.1       mrg 
     79       1.1       mrg /*
     80       1.1       mrg  * uvm_pager_init: init pagers (at boot time)
     81       1.1       mrg  */
     82       1.1       mrg 
     83       1.6       mrg void
     84       1.6       mrg uvm_pager_init()
     85       1.6       mrg {
     86       1.6       mrg 	int lcv;
     87  1.48.2.2   thorpej 	vaddr_t sva, eva;
     88       1.1       mrg 
     89       1.6       mrg 	/*
     90       1.6       mrg 	 * init pager map
     91       1.6       mrg 	 */
     92       1.6       mrg 
     93  1.48.2.2   thorpej 	sva = 0;
     94  1.48.2.2   thorpej 	pager_map = uvm_km_suballoc(kernel_map, &sva, &eva, PAGER_MAP_SIZE, 0,
     95  1.48.2.2   thorpej 	    FALSE, NULL);
     96      1.35       chs 	simple_lock_init(&pager_map_wanted_lock);
     97      1.35       chs 	pager_map_wanted = FALSE;
     98      1.35       chs 	emergva = uvm_km_valloc(kernel_map, MAXBSIZE);
     99      1.35       chs 	emerginuse = FALSE;
    100       1.6       mrg 
    101       1.6       mrg 	/*
    102       1.6       mrg 	 * init ASYNC I/O queue
    103       1.6       mrg 	 */
    104      1.45       chs 
    105       1.6       mrg 	TAILQ_INIT(&uvm.aio_done);
    106       1.1       mrg 
    107       1.6       mrg 	/*
    108       1.6       mrg 	 * call pager init functions
    109       1.6       mrg 	 */
    110       1.6       mrg 	for (lcv = 0 ; lcv < sizeof(uvmpagerops)/sizeof(struct uvm_pagerops *);
    111       1.6       mrg 	    lcv++) {
    112       1.6       mrg 		if (uvmpagerops[lcv]->pgo_init)
    113       1.6       mrg 			uvmpagerops[lcv]->pgo_init();
    114       1.6       mrg 	}
    115       1.1       mrg }
    116       1.1       mrg 
    117       1.1       mrg /*
    118       1.1       mrg  * uvm_pagermapin: map pages into KVA (pager_map) for I/O that needs mappings
    119       1.1       mrg  *
    120       1.1       mrg  * we basically just map in a blank map entry to reserve the space in the
    121       1.1       mrg  * map and then use pmap_enter() to put the mappings in by hand.
    122       1.1       mrg  */
    123       1.1       mrg 
    124       1.9       eeh vaddr_t
    125      1.35       chs uvm_pagermapin(pps, npages, flags)
    126       1.6       mrg 	struct vm_page **pps;
    127       1.6       mrg 	int npages;
    128      1.29   thorpej 	int flags;
    129       1.1       mrg {
    130       1.9       eeh 	vsize_t size;
    131       1.9       eeh 	vaddr_t kva;
    132       1.9       eeh 	vaddr_t cva;
    133       1.6       mrg 	struct vm_page *pp;
    134      1.29   thorpej 	vm_prot_t prot;
    135       1.6       mrg 	UVMHIST_FUNC("uvm_pagermapin"); UVMHIST_CALLED(maphist);
    136       1.1       mrg 
    137      1.35       chs 	UVMHIST_LOG(maphist,"(pps=0x%x, npages=%d)", pps, npages,0,0);
    138      1.29   thorpej 
    139      1.29   thorpej 	/*
    140      1.29   thorpej 	 * compute protection.  outgoing I/O only needs read
    141      1.29   thorpej 	 * access to the page, whereas incoming needs read/write.
    142      1.29   thorpej 	 */
    143      1.29   thorpej 
    144      1.29   thorpej 	prot = VM_PROT_READ;
    145      1.29   thorpej 	if (flags & UVMPAGER_MAPIN_READ)
    146      1.29   thorpej 		prot |= VM_PROT_WRITE;
    147       1.1       mrg 
    148       1.1       mrg ReStart:
    149      1.12       chs 	size = npages << PAGE_SHIFT;
    150      1.29   thorpej 	kva = 0;			/* let system choose VA */
    151       1.1       mrg 
    152      1.45       chs 	if (uvm_map(pager_map, &kva, size, NULL,
    153      1.43       chs 	      UVM_UNKNOWN_OFFSET, 0, UVM_FLAG_NOMERGE) != 0) {
    154      1.35       chs 		if (curproc == uvm.pagedaemon_proc) {
    155      1.35       chs 			simple_lock(&pager_map_wanted_lock);
    156      1.35       chs 			if (emerginuse) {
    157      1.35       chs 				UVM_UNLOCK_AND_WAIT(&emergva,
    158      1.35       chs 				    &pager_map_wanted_lock, FALSE,
    159      1.35       chs 				    "emergva", 0);
    160      1.35       chs 				goto ReStart;
    161      1.35       chs 			}
    162      1.35       chs 			emerginuse = TRUE;
    163      1.35       chs 			simple_unlock(&pager_map_wanted_lock);
    164      1.35       chs 			kva = emergva;
    165      1.35       chs 			KASSERT(npages <= MAXBSIZE >> PAGE_SHIFT);
    166      1.35       chs 			goto enter;
    167      1.35       chs 		}
    168      1.29   thorpej 		if ((flags & UVMPAGER_MAPIN_WAITOK) == 0) {
    169       1.6       mrg 			UVMHIST_LOG(maphist,"<- NOWAIT failed", 0,0,0,0);
    170      1.29   thorpej 			return(0);
    171       1.6       mrg 		}
    172       1.6       mrg 		simple_lock(&pager_map_wanted_lock);
    173      1.45       chs 		pager_map_wanted = TRUE;
    174       1.6       mrg 		UVMHIST_LOG(maphist, "  SLEEPING on pager_map",0,0,0,0);
    175      1.45       chs 		UVM_UNLOCK_AND_WAIT(pager_map, &pager_map_wanted_lock, FALSE,
    176      1.35       chs 		    "pager_map", 0);
    177       1.6       mrg 		goto ReStart;
    178       1.6       mrg 	}
    179       1.1       mrg 
    180      1.35       chs enter:
    181       1.6       mrg 	/* got it */
    182       1.6       mrg 	for (cva = kva ; size != 0 ; size -= PAGE_SIZE, cva += PAGE_SIZE) {
    183       1.6       mrg 		pp = *pps++;
    184      1.40       mrg 		KASSERT(pp);
    185      1.38       chs 		KASSERT(pp->flags & PG_BUSY);
    186  1.48.2.2   thorpej 		pmap_kenter_pa(cva, VM_PAGE_TO_PHYS(pp), prot);
    187       1.6       mrg 	}
    188  1.48.2.1   thorpej 	pmap_update(vm_map_pmap(pager_map));
    189       1.1       mrg 
    190       1.6       mrg 	UVMHIST_LOG(maphist, "<- done (KVA=0x%x)", kva,0,0,0);
    191       1.6       mrg 	return(kva);
    192       1.1       mrg }
    193       1.1       mrg 
    194       1.1       mrg /*
    195       1.1       mrg  * uvm_pagermapout: remove pager_map mapping
    196       1.1       mrg  *
    197       1.1       mrg  * we remove our mappings by hand and then remove the mapping (waking
    198       1.1       mrg  * up anyone wanting space).
    199       1.1       mrg  */
    200       1.1       mrg 
    201       1.6       mrg void
    202       1.6       mrg uvm_pagermapout(kva, npages)
    203       1.9       eeh 	vaddr_t kva;
    204       1.6       mrg 	int npages;
    205       1.6       mrg {
    206      1.12       chs 	vsize_t size = npages << PAGE_SHIFT;
    207      1.47       chs 	struct vm_map_entry *entries;
    208       1.6       mrg 	UVMHIST_FUNC("uvm_pagermapout"); UVMHIST_CALLED(maphist);
    209      1.35       chs 
    210       1.6       mrg 	UVMHIST_LOG(maphist, " (kva=0x%x, npages=%d)", kva, npages,0,0);
    211       1.1       mrg 
    212       1.6       mrg 	/*
    213       1.6       mrg 	 * duplicate uvm_unmap, but add in pager_map_wanted handling.
    214       1.6       mrg 	 */
    215       1.6       mrg 
    216  1.48.2.2   thorpej 	pmap_kremove(kva, npages << PAGE_SHIFT);
    217      1.35       chs 	if (kva == emergva) {
    218      1.35       chs 		simple_lock(&pager_map_wanted_lock);
    219      1.35       chs 		emerginuse = FALSE;
    220      1.35       chs 		wakeup(&emergva);
    221      1.35       chs 		simple_unlock(&pager_map_wanted_lock);
    222  1.48.2.2   thorpej 		return;
    223      1.35       chs 	}
    224      1.35       chs 
    225       1.6       mrg 	vm_map_lock(pager_map);
    226      1.43       chs 	uvm_unmap_remove(pager_map, kva, kva + size, &entries);
    227       1.6       mrg 	simple_lock(&pager_map_wanted_lock);
    228       1.6       mrg 	if (pager_map_wanted) {
    229       1.6       mrg 		pager_map_wanted = FALSE;
    230       1.6       mrg 		wakeup(pager_map);
    231       1.6       mrg 	}
    232       1.6       mrg 	simple_unlock(&pager_map_wanted_lock);
    233       1.6       mrg 	vm_map_unlock(pager_map);
    234       1.6       mrg 	if (entries)
    235       1.6       mrg 		uvm_unmap_detach(entries, 0);
    236  1.48.2.1   thorpej 	pmap_update(pmap_kernel());
    237       1.6       mrg 	UVMHIST_LOG(maphist,"<- done",0,0,0,0);
    238       1.1       mrg }
    239       1.1       mrg 
    240       1.1       mrg /*
    241      1.35       chs  * interrupt-context iodone handler for nested i/o bufs.
    242      1.35       chs  *
    243      1.35       chs  * => must be at splbio().
    244      1.35       chs  */
    245      1.35       chs 
    246      1.35       chs void
    247      1.35       chs uvm_aio_biodone1(bp)
    248      1.35       chs 	struct buf *bp;
    249      1.35       chs {
    250      1.35       chs 	struct buf *mbp = bp->b_private;
    251      1.35       chs 
    252      1.35       chs 	KASSERT(mbp != bp);
    253      1.35       chs 	if (bp->b_flags & B_ERROR) {
    254      1.35       chs 		mbp->b_flags |= B_ERROR;
    255      1.35       chs 		mbp->b_error = bp->b_error;
    256      1.35       chs 	}
    257      1.35       chs 	mbp->b_resid -= bp->b_bcount;
    258      1.35       chs 	pool_put(&bufpool, bp);
    259      1.35       chs 	if (mbp->b_resid == 0) {
    260      1.35       chs 		biodone(mbp);
    261      1.35       chs 	}
    262      1.35       chs }
    263      1.35       chs 
    264      1.35       chs /*
    265      1.35       chs  * interrupt-context iodone handler for single-buf i/os
    266      1.35       chs  * or the top-level buf of a nested-buf i/o.
    267      1.35       chs  *
    268      1.35       chs  * => must be at splbio().
    269      1.35       chs  */
    270      1.35       chs 
    271      1.35       chs void
    272      1.35       chs uvm_aio_biodone(bp)
    273      1.35       chs 	struct buf *bp;
    274      1.35       chs {
    275      1.35       chs 	/* reset b_iodone for when this is a single-buf i/o. */
    276      1.35       chs 	bp->b_iodone = uvm_aio_aiodone;
    277      1.35       chs 
    278      1.35       chs 	simple_lock(&uvm.aiodoned_lock);	/* locks uvm.aio_done */
    279      1.35       chs 	TAILQ_INSERT_TAIL(&uvm.aio_done, bp, b_freelist);
    280      1.35       chs 	wakeup(&uvm.aiodoned);
    281      1.35       chs 	simple_unlock(&uvm.aiodoned_lock);
    282      1.35       chs }
    283      1.35       chs 
    284      1.35       chs /*
    285      1.35       chs  * uvm_aio_aiodone: do iodone processing for async i/os.
    286      1.35       chs  * this should be called in thread context, not interrupt context.
    287      1.35       chs  */
    288      1.35       chs 
    289      1.35       chs void
    290      1.35       chs uvm_aio_aiodone(bp)
    291      1.35       chs 	struct buf *bp;
    292      1.35       chs {
    293      1.35       chs 	int npages = bp->b_bufsize >> PAGE_SHIFT;
    294      1.35       chs 	struct vm_page *pg, *pgs[npages];
    295      1.35       chs 	struct uvm_object *uobj;
    296  1.48.2.2   thorpej 	struct simplelock *slock;
    297  1.48.2.2   thorpej 	int s, i, error, swslot;
    298  1.48.2.3  jdolecek 	boolean_t write, swap;
    299      1.35       chs 	UVMHIST_FUNC("uvm_aio_aiodone"); UVMHIST_CALLED(ubchist);
    300      1.35       chs 	UVMHIST_LOG(ubchist, "bp %p", bp, 0,0,0);
    301      1.35       chs 
    302      1.41       chs 	error = (bp->b_flags & B_ERROR) ? (bp->b_error ? bp->b_error : EIO) : 0;
    303      1.35       chs 	write = (bp->b_flags & B_READ) == 0;
    304      1.35       chs 	/* XXXUBC B_NOCACHE is for swap pager, should be done differently */
    305      1.36       chs 	if (write && !(bp->b_flags & B_NOCACHE) && bioops.io_pageiodone) {
    306      1.36       chs 		(*bioops.io_pageiodone)(bp);
    307      1.35       chs 	}
    308      1.35       chs 
    309      1.35       chs 	uobj = NULL;
    310      1.35       chs 	for (i = 0; i < npages; i++) {
    311      1.35       chs 		pgs[i] = uvm_pageratop((vaddr_t)bp->b_data + (i << PAGE_SHIFT));
    312      1.35       chs 		UVMHIST_LOG(ubchist, "pgs[%d] = %p", i, pgs[i],0,0);
    313      1.35       chs 	}
    314      1.35       chs 	uvm_pagermapout((vaddr_t)bp->b_data, npages);
    315      1.35       chs 
    316  1.48.2.2   thorpej 	swslot = 0;
    317  1.48.2.2   thorpej 	slock = NULL;
    318  1.48.2.2   thorpej 	pg = pgs[0];
    319  1.48.2.2   thorpej 	swap = (pg->uanon != NULL && pg->uobject == NULL) ||
    320  1.48.2.2   thorpej 		(pg->pqflags & PQ_AOBJ) != 0;
    321  1.48.2.2   thorpej 	if (!swap) {
    322  1.48.2.2   thorpej 		uobj = pg->uobject;
    323  1.48.2.2   thorpej 		slock = &uobj->vmobjlock;
    324  1.48.2.2   thorpej 		simple_lock(slock);
    325  1.48.2.2   thorpej 		uvm_lock_pageq();
    326  1.48.2.2   thorpej 	} else if (error) {
    327  1.48.2.2   thorpej 		if (pg->uobject != NULL) {
    328  1.48.2.2   thorpej 			swslot = uao_find_swslot(pg->uobject, pg->offset);
    329  1.48.2.2   thorpej 		} else {
    330  1.48.2.2   thorpej 			swslot = pg->uanon->an_swslot;
    331      1.35       chs 		}
    332  1.48.2.2   thorpej 		KASSERT(swslot);
    333  1.48.2.2   thorpej 	}
    334  1.48.2.2   thorpej 	for (i = 0; i < npages; i++) {
    335  1.48.2.2   thorpej 		pg = pgs[i];
    336      1.35       chs 		KASSERT(swap || pg->uobject == uobj);
    337  1.48.2.2   thorpej 		UVMHIST_LOG(ubchist, "pg %p", pg, 0,0,0);
    338  1.48.2.2   thorpej 
    339  1.48.2.2   thorpej 		/*
    340  1.48.2.2   thorpej 		 * for swap i/os, lock each page's object (or anon)
    341  1.48.2.2   thorpej 		 * individually since each page may need a different lock.
    342  1.48.2.2   thorpej 		 */
    343  1.48.2.2   thorpej 
    344      1.35       chs 		if (swap) {
    345  1.48.2.2   thorpej 			if (pg->uobject != NULL) {
    346  1.48.2.2   thorpej 				slock = &pg->uobject->vmobjlock;
    347      1.35       chs 			} else {
    348  1.48.2.2   thorpej 				slock = &pg->uanon->an_lock;
    349      1.35       chs 			}
    350  1.48.2.2   thorpej 			simple_lock(slock);
    351  1.48.2.2   thorpej 			uvm_lock_pageq();
    352      1.35       chs 		}
    353      1.35       chs 
    354      1.35       chs 		/*
    355  1.48.2.2   thorpej 		 * process errors.  for reads, just mark the page to be freed.
    356  1.48.2.2   thorpej 		 * for writes, if the error was ENOMEM, we assume this was
    357  1.48.2.2   thorpej 		 * a transient failure so we mark the page dirty so that
    358  1.48.2.2   thorpej 		 * we'll try to write it again later.  for all other write
    359  1.48.2.2   thorpej 		 * errors, we assume the error is permanent, thus the data
    360  1.48.2.2   thorpej 		 * in the page is lost.  bummer.
    361      1.35       chs 		 */
    362      1.35       chs 
    363  1.48.2.2   thorpej 		if (error) {
    364  1.48.2.2   thorpej 			if (!write) {
    365  1.48.2.2   thorpej 				pg->flags |= PG_RELEASED;
    366  1.48.2.2   thorpej 				continue;
    367  1.48.2.2   thorpej 			} else if (error == ENOMEM) {
    368  1.48.2.2   thorpej 				if (pg->flags & PG_PAGEOUT) {
    369  1.48.2.2   thorpej 					pg->flags &= ~PG_PAGEOUT;
    370  1.48.2.2   thorpej 					uvmexp.paging--;
    371  1.48.2.2   thorpej 				}
    372  1.48.2.2   thorpej 				pg->flags &= ~PG_CLEAN;
    373  1.48.2.2   thorpej 				uvm_pageactivate(pg);
    374  1.48.2.2   thorpej 			}
    375  1.48.2.2   thorpej 		}
    376  1.48.2.2   thorpej 
    377  1.48.2.2   thorpej 		/*
    378  1.48.2.2   thorpej 		 * if the page is PG_FAKE, this must have been a read to
    379  1.48.2.2   thorpej 		 * initialize the page.  clear PG_FAKE and activate the page.
    380  1.48.2.2   thorpej 		 * we must also clear the pmap "modified" flag since it may
    381  1.48.2.2   thorpej 		 * still be set from the page's previous identity.
    382  1.48.2.2   thorpej 		 */
    383  1.48.2.2   thorpej 
    384  1.48.2.2   thorpej 		if (pg->flags & PG_FAKE) {
    385  1.48.2.2   thorpej 			KASSERT(!write);
    386  1.48.2.2   thorpej 			pg->flags &= ~PG_FAKE;
    387  1.48.2.2   thorpej 			uvm_pageactivate(pg);
    388  1.48.2.2   thorpej 			pmap_clear_modify(pg);
    389      1.35       chs 		}
    390      1.35       chs 
    391      1.35       chs 		/*
    392  1.48.2.2   thorpej 		 * do accounting for pagedaemon i/o and arrange to free
    393  1.48.2.2   thorpej 		 * the pages instead of just unbusying them.
    394      1.35       chs 		 */
    395      1.35       chs 
    396  1.48.2.2   thorpej 		if (pg->flags & PG_PAGEOUT) {
    397  1.48.2.2   thorpej 			pg->flags &= ~PG_PAGEOUT;
    398  1.48.2.2   thorpej 			uvmexp.paging--;
    399  1.48.2.2   thorpej 			pg->flags |= PG_RELEASED;
    400      1.37       chs 		}
    401  1.48.2.2   thorpej 
    402  1.48.2.2   thorpej 		/*
    403  1.48.2.2   thorpej 		 * for swap pages, unlock everything for this page now.
    404  1.48.2.2   thorpej 		 */
    405  1.48.2.2   thorpej 
    406      1.35       chs 		if (swap) {
    407  1.48.2.2   thorpej 			uvm_page_unbusy(&pg, 1);
    408  1.48.2.2   thorpej 			uvm_unlock_pageq();
    409  1.48.2.2   thorpej 			simple_unlock(slock);
    410      1.35       chs 		}
    411      1.35       chs 	}
    412      1.35       chs 	if (!swap) {
    413  1.48.2.2   thorpej 		uvm_page_unbusy(pgs, npages);
    414  1.48.2.2   thorpej 		uvm_unlock_pageq();
    415  1.48.2.2   thorpej 		simple_unlock(slock);
    416  1.48.2.2   thorpej 	} else {
    417  1.48.2.2   thorpej 		KASSERT(write);
    418      1.35       chs 
    419  1.48.2.2   thorpej 		/* these pages are now only in swap. */
    420  1.48.2.2   thorpej 		simple_lock(&uvm.swap_data_lock);
    421  1.48.2.2   thorpej 		KASSERT(uvmexp.swpgonly + npages <= uvmexp.swpginuse);
    422  1.48.2.2   thorpej 		uvmexp.swpgonly += npages;
    423  1.48.2.2   thorpej 		simple_unlock(&uvm.swap_data_lock);
    424  1.48.2.2   thorpej 		if (error) {
    425  1.48.2.2   thorpej 			uvm_swap_markbad(swslot, npages);
    426  1.48.2.2   thorpej 		}
    427  1.48.2.2   thorpej 	}
    428      1.35       chs 	s = splbio();
    429      1.35       chs 	if (write && (bp->b_flags & B_AGE) != 0) {
    430      1.35       chs 		vwakeup(bp);
    431      1.35       chs 	}
    432      1.35       chs 	pool_put(&bufpool, bp);
    433      1.35       chs 	splx(s);
    434       1.1       mrg }
    435