xref: /freebsd/sys/vm/vm_pager.c (revision b9dcd593ff1f6ff7ed984f3c4058133bd398e26a)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1991, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
6df8bae1dSRodney W. Grimes  * The Mach Operating System project at Carnegie-Mellon University.
7df8bae1dSRodney W. Grimes  *
8df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
9df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
10df8bae1dSRodney W. Grimes  * are met:
11df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
12df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
13df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
15df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
16df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
17df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
18df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
19df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
20df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  *
363c4dd356SDavid Greenman  *	from: @(#)vm_pager.c	8.6 (Berkeley) 1/12/94
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  *
39df8bae1dSRodney W. Grimes  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
40df8bae1dSRodney W. Grimes  * All rights reserved.
41df8bae1dSRodney W. Grimes  *
42df8bae1dSRodney W. Grimes  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
43df8bae1dSRodney W. Grimes  *
44df8bae1dSRodney W. Grimes  * Permission to use, copy, modify and distribute this software and
45df8bae1dSRodney W. Grimes  * its documentation is hereby granted, provided that both the copyright
46df8bae1dSRodney W. Grimes  * notice and this permission notice appear in all copies of the
47df8bae1dSRodney W. Grimes  * software, derivative works or modified versions, and any portions
48df8bae1dSRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
49df8bae1dSRodney W. Grimes  *
50df8bae1dSRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51df8bae1dSRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52df8bae1dSRodney W. Grimes  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53df8bae1dSRodney W. Grimes  *
54df8bae1dSRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
55df8bae1dSRodney W. Grimes  *
56df8bae1dSRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
57df8bae1dSRodney W. Grimes  *  School of Computer Science
58df8bae1dSRodney W. Grimes  *  Carnegie Mellon University
59df8bae1dSRodney W. Grimes  *  Pittsburgh PA 15213-3890
60df8bae1dSRodney W. Grimes  *
61df8bae1dSRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
62df8bae1dSRodney W. Grimes  * rights to redistribute these changes.
633c4dd356SDavid Greenman  *
64b9dcd593SBruce Evans  * $Id: vm_pager.c,v 1.27 1997/02/22 09:48:35 peter Exp $
65df8bae1dSRodney W. Grimes  */
66df8bae1dSRodney W. Grimes 
67df8bae1dSRodney W. Grimes /*
68df8bae1dSRodney W. Grimes  *	Paging space routine stubs.  Emulates a matchmaker-like interface
69df8bae1dSRodney W. Grimes  *	for builtin pagers.
70df8bae1dSRodney W. Grimes  */
71df8bae1dSRodney W. Grimes 
72df8bae1dSRodney W. Grimes #include <sys/param.h>
73df8bae1dSRodney W. Grimes #include <sys/systm.h>
7405f0fdd2SPoul-Henning Kamp #include <sys/proc.h>
75df8bae1dSRodney W. Grimes #include <sys/malloc.h>
7616f62314SDavid Greenman #include <sys/buf.h>
7716f62314SDavid Greenman #include <sys/ucred.h>
78df8bae1dSRodney W. Grimes 
79df8bae1dSRodney W. Grimes #include <vm/vm.h>
80efeaf95aSDavid Greenman #include <vm/vm_param.h>
81efeaf95aSDavid Greenman #include <vm/vm_prot.h>
82efeaf95aSDavid Greenman #include <vm/vm_object.h>
83df8bae1dSRodney W. Grimes #include <vm/vm_page.h>
84df8bae1dSRodney W. Grimes #include <vm/vm_kern.h>
8524a1cce3SDavid Greenman #include <vm/vm_pager.h>
86efeaf95aSDavid Greenman #include <vm/vm_extern.h>
87df8bae1dSRodney W. Grimes 
8824a1cce3SDavid Greenman extern struct pagerops defaultpagerops;
89df8bae1dSRodney W. Grimes extern struct pagerops swappagerops;
90df8bae1dSRodney W. Grimes extern struct pagerops vnodepagerops;
91df8bae1dSRodney W. Grimes extern struct pagerops devicepagerops;
92df8bae1dSRodney W. Grimes 
933af76890SPoul-Henning Kamp static struct pagerops *pagertab[] = {
9424a1cce3SDavid Greenman 	&defaultpagerops,	/* OBJT_DEFAULT */
9524a1cce3SDavid Greenman 	&swappagerops,		/* OBJT_SWAP */
9624a1cce3SDavid Greenman 	&vnodepagerops,		/* OBJT_VNODE */
9724a1cce3SDavid Greenman 	&devicepagerops,	/* OBJT_DEVICE */
98df8bae1dSRodney W. Grimes };
993af76890SPoul-Henning Kamp static int npagers = sizeof(pagertab) / sizeof(pagertab[0]);
100df8bae1dSRodney W. Grimes 
101df8bae1dSRodney W. Grimes /*
102df8bae1dSRodney W. Grimes  * Kernel address space for mapping pages.
103df8bae1dSRodney W. Grimes  * Used by pagers where KVAs are needed for IO.
104df8bae1dSRodney W. Grimes  *
105df8bae1dSRodney W. Grimes  * XXX needs to be large enough to support the number of pending async
106df8bae1dSRodney W. Grimes  * cleaning requests (NPENDINGIO == 64) * the maximum swap cluster size
107df8bae1dSRodney W. Grimes  * (MAXPHYS == 64k) if you want to get the most efficiency.
108df8bae1dSRodney W. Grimes  */
10916f62314SDavid Greenman #define PAGER_MAP_SIZE	(8 * 1024 * 1024)
110df8bae1dSRodney W. Grimes 
11126f9a767SRodney W. Grimes int pager_map_size = PAGER_MAP_SIZE;
112df8bae1dSRodney W. Grimes vm_map_t pager_map;
113f708ef1bSPoul-Henning Kamp static int bswneeded;
114f708ef1bSPoul-Henning Kamp static vm_offset_t swapbkva;		/* swap buffers kva */
115df8bae1dSRodney W. Grimes 
116df8bae1dSRodney W. Grimes void
117df8bae1dSRodney W. Grimes vm_pager_init()
118df8bae1dSRodney W. Grimes {
119df8bae1dSRodney W. Grimes 	struct pagerops **pgops;
120df8bae1dSRodney W. Grimes 
121df8bae1dSRodney W. Grimes 	/*
122df8bae1dSRodney W. Grimes 	 * Initialize known pagers
123df8bae1dSRodney W. Grimes 	 */
124df8bae1dSRodney W. Grimes 	for (pgops = pagertab; pgops < &pagertab[npagers]; pgops++)
12524a1cce3SDavid Greenman 		if (pgops && ((*pgops)->pgo_init != NULL))
126df8bae1dSRodney W. Grimes 			(*(*pgops)->pgo_init) ();
127df8bae1dSRodney W. Grimes }
128df8bae1dSRodney W. Grimes 
12916f62314SDavid Greenman void
13016f62314SDavid Greenman vm_pager_bufferinit()
13116f62314SDavid Greenman {
13216f62314SDavid Greenman 	struct buf *bp;
13316f62314SDavid Greenman 	int i;
1340d94caffSDavid Greenman 
13516f62314SDavid Greenman 	bp = swbuf;
13616f62314SDavid Greenman 	/*
13716f62314SDavid Greenman 	 * Now set up swap and physical I/O buffer headers.
13816f62314SDavid Greenman 	 */
13916f62314SDavid Greenman 	for (i = 0; i < nswbuf - 1; i++, bp++) {
14016f62314SDavid Greenman 		TAILQ_INSERT_HEAD(&bswlist, bp, b_freelist);
14116f62314SDavid Greenman 		bp->b_rcred = bp->b_wcred = NOCRED;
14216f62314SDavid Greenman 		bp->b_vnbufs.le_next = NOLIST;
14316f62314SDavid Greenman 	}
14416f62314SDavid Greenman 	bp->b_rcred = bp->b_wcred = NOCRED;
14516f62314SDavid Greenman 	bp->b_vnbufs.le_next = NOLIST;
14616f62314SDavid Greenman 
14716f62314SDavid Greenman 	swapbkva = kmem_alloc_pageable(pager_map, nswbuf * MAXPHYS);
14816f62314SDavid Greenman 	if (!swapbkva)
14916f62314SDavid Greenman 		panic("Not enough pager_map VM space for physical buffers");
15016f62314SDavid Greenman }
15116f62314SDavid Greenman 
152df8bae1dSRodney W. Grimes /*
153df8bae1dSRodney W. Grimes  * Allocate an instance of a pager of the given type.
154df8bae1dSRodney W. Grimes  * Size, protection and offset parameters are passed in for pagers that
155df8bae1dSRodney W. Grimes  * need to perform page-level validation (e.g. the device pager).
156df8bae1dSRodney W. Grimes  */
15724a1cce3SDavid Greenman vm_object_t
158b9dcd593SBruce Evans vm_pager_allocate(objtype_t type, void *handle, vm_size_t size, vm_prot_t prot,
159b9dcd593SBruce Evans 		  vm_ooffset_t off)
160df8bae1dSRodney W. Grimes {
161df8bae1dSRodney W. Grimes 	struct pagerops *ops;
162df8bae1dSRodney W. Grimes 
16324a1cce3SDavid Greenman 	ops = pagertab[type];
164df8bae1dSRodney W. Grimes 	if (ops)
165df8bae1dSRodney W. Grimes 		return ((*ops->pgo_alloc) (handle, size, prot, off));
166df8bae1dSRodney W. Grimes 	return (NULL);
167df8bae1dSRodney W. Grimes }
168df8bae1dSRodney W. Grimes 
169df8bae1dSRodney W. Grimes void
17024a1cce3SDavid Greenman vm_pager_deallocate(object)
17124a1cce3SDavid Greenman 	vm_object_t object;
172df8bae1dSRodney W. Grimes {
17324a1cce3SDavid Greenman 	(*pagertab[object->type]->pgo_dealloc) (object);
174df8bae1dSRodney W. Grimes }
175df8bae1dSRodney W. Grimes 
17626f9a767SRodney W. Grimes 
177df8bae1dSRodney W. Grimes int
17824a1cce3SDavid Greenman vm_pager_get_pages(object, m, count, reqpage)
17924a1cce3SDavid Greenman 	vm_object_t object;
18026f9a767SRodney W. Grimes 	vm_page_t *m;
18126f9a767SRodney W. Grimes 	int count;
18226f9a767SRodney W. Grimes 	int reqpage;
183df8bae1dSRodney W. Grimes {
18424a1cce3SDavid Greenman 	return ((*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage));
185df8bae1dSRodney W. Grimes }
186df8bae1dSRodney W. Grimes 
187df8bae1dSRodney W. Grimes int
18824a1cce3SDavid Greenman vm_pager_put_pages(object, m, count, sync, rtvals)
18924a1cce3SDavid Greenman 	vm_object_t object;
19026f9a767SRodney W. Grimes 	vm_page_t *m;
19126f9a767SRodney W. Grimes 	int count;
192df8bae1dSRodney W. Grimes 	boolean_t sync;
19326f9a767SRodney W. Grimes 	int *rtvals;
194df8bae1dSRodney W. Grimes {
19524a1cce3SDavid Greenman 	return ((*pagertab[object->type]->pgo_putpages)(object, m, count, sync, rtvals));
196df8bae1dSRodney W. Grimes }
197df8bae1dSRodney W. Grimes 
198df8bae1dSRodney W. Grimes boolean_t
19924a1cce3SDavid Greenman vm_pager_has_page(object, offset, before, after)
20024a1cce3SDavid Greenman 	vm_object_t object;
201a316d390SJohn Dyson 	vm_pindex_t offset;
20224a1cce3SDavid Greenman 	int *before;
20324a1cce3SDavid Greenman 	int *after;
204df8bae1dSRodney W. Grimes {
20524a1cce3SDavid Greenman 	return ((*pagertab[object->type]->pgo_haspage) (object, offset, before, after));
206df8bae1dSRodney W. Grimes }
207df8bae1dSRodney W. Grimes 
208df8bae1dSRodney W. Grimes /*
209df8bae1dSRodney W. Grimes  * Called by pageout daemon before going back to sleep.
210df8bae1dSRodney W. Grimes  * Gives pagers a chance to clean up any completed async pageing operations.
211df8bae1dSRodney W. Grimes  */
212df8bae1dSRodney W. Grimes void
213df8bae1dSRodney W. Grimes vm_pager_sync()
214df8bae1dSRodney W. Grimes {
215df8bae1dSRodney W. Grimes 	struct pagerops **pgops;
216df8bae1dSRodney W. Grimes 
217df8bae1dSRodney W. Grimes 	for (pgops = pagertab; pgops < &pagertab[npagers]; pgops++)
21824a1cce3SDavid Greenman 		if (pgops && ((*pgops)->pgo_sync != NULL))
21924a1cce3SDavid Greenman 			(*(*pgops)->pgo_sync) ();
220df8bae1dSRodney W. Grimes }
221df8bae1dSRodney W. Grimes 
222df8bae1dSRodney W. Grimes vm_offset_t
22326f9a767SRodney W. Grimes vm_pager_map_page(m)
224df8bae1dSRodney W. Grimes 	vm_page_t m;
22526f9a767SRodney W. Grimes {
22626f9a767SRodney W. Grimes 	vm_offset_t kva;
227df8bae1dSRodney W. Grimes 
22826f9a767SRodney W. Grimes 	kva = kmem_alloc_wait(pager_map, PAGE_SIZE);
229a481f200SDavid Greenman 	pmap_kenter(kva, VM_PAGE_TO_PHYS(m));
230df8bae1dSRodney W. Grimes 	return (kva);
231df8bae1dSRodney W. Grimes }
232df8bae1dSRodney W. Grimes 
233df8bae1dSRodney W. Grimes void
23426f9a767SRodney W. Grimes vm_pager_unmap_page(kva)
235df8bae1dSRodney W. Grimes 	vm_offset_t kva;
236df8bae1dSRodney W. Grimes {
237a481f200SDavid Greenman 	pmap_kremove(kva);
23826f9a767SRodney W. Grimes 	kmem_free_wakeup(pager_map, kva, PAGE_SIZE);
239df8bae1dSRodney W. Grimes }
240df8bae1dSRodney W. Grimes 
24124a1cce3SDavid Greenman vm_object_t
24224a1cce3SDavid Greenman vm_pager_object_lookup(pg_list, handle)
24324a1cce3SDavid Greenman 	register struct pagerlst *pg_list;
24424a1cce3SDavid Greenman 	void *handle;
245df8bae1dSRodney W. Grimes {
24624a1cce3SDavid Greenman 	register vm_object_t object;
247df8bae1dSRodney W. Grimes 
248b18bfc3dSJohn Dyson 	for (object = TAILQ_FIRST(pg_list); object != NULL; object = TAILQ_NEXT(object,pager_object_list))
24924a1cce3SDavid Greenman 		if (object->handle == handle)
25024a1cce3SDavid Greenman 			return (object);
251df8bae1dSRodney W. Grimes 	return (NULL);
252df8bae1dSRodney W. Grimes }
253df8bae1dSRodney W. Grimes 
254df8bae1dSRodney W. Grimes /*
255a14e8fd0SDavid Greenman  * This routine loses a reference to the object -
256a14e8fd0SDavid Greenman  * thus a reference must be gained before calling.
257df8bae1dSRodney W. Grimes  */
258df8bae1dSRodney W. Grimes int
259df8bae1dSRodney W. Grimes pager_cache(object, should_cache)
260df8bae1dSRodney W. Grimes 	vm_object_t object;
261df8bae1dSRodney W. Grimes 	boolean_t should_cache;
262df8bae1dSRodney W. Grimes {
263df8bae1dSRodney W. Grimes 	if (object == NULL)
264df8bae1dSRodney W. Grimes 		return (KERN_INVALID_ARGUMENT);
265df8bae1dSRodney W. Grimes 
266df8bae1dSRodney W. Grimes 	if (should_cache)
267df8bae1dSRodney W. Grimes 		object->flags |= OBJ_CANPERSIST;
268df8bae1dSRodney W. Grimes 	else
269df8bae1dSRodney W. Grimes 		object->flags &= ~OBJ_CANPERSIST;
270df8bae1dSRodney W. Grimes 
271df8bae1dSRodney W. Grimes 	vm_object_deallocate(object);
272df8bae1dSRodney W. Grimes 
273df8bae1dSRodney W. Grimes 	return (KERN_SUCCESS);
274df8bae1dSRodney W. Grimes }
27516f62314SDavid Greenman 
27616f62314SDavid Greenman /*
27709e0c6ccSJohn Dyson  * initialize a physical buffer
27809e0c6ccSJohn Dyson  */
27909e0c6ccSJohn Dyson 
28009e0c6ccSJohn Dyson static void
28109e0c6ccSJohn Dyson initpbuf(struct buf *bp) {
28209e0c6ccSJohn Dyson 	bzero(bp, sizeof *bp);
28309e0c6ccSJohn Dyson 	bp->b_rcred = NOCRED;
28409e0c6ccSJohn Dyson 	bp->b_wcred = NOCRED;
28509e0c6ccSJohn Dyson 	bp->b_qindex = QUEUE_NONE;
28609e0c6ccSJohn Dyson 	bp->b_data = (caddr_t) (MAXPHYS * (bp - swbuf)) + swapbkva;
28709e0c6ccSJohn Dyson 	bp->b_kvabase = bp->b_data;
28809e0c6ccSJohn Dyson 	bp->b_kvasize = MAXPHYS;
28909e0c6ccSJohn Dyson 	bp->b_vnbufs.le_next = NOLIST;
29009e0c6ccSJohn Dyson }
29109e0c6ccSJohn Dyson 
29209e0c6ccSJohn Dyson /*
29316f62314SDavid Greenman  * allocate a physical buffer
29416f62314SDavid Greenman  */
29516f62314SDavid Greenman struct buf *
2960d94caffSDavid Greenman getpbuf()
2970d94caffSDavid Greenman {
29816f62314SDavid Greenman 	int s;
29916f62314SDavid Greenman 	struct buf *bp;
30016f62314SDavid Greenman 
30116f62314SDavid Greenman 	s = splbio();
30216f62314SDavid Greenman 	/* get a bp from the swap buffer header pool */
303b18bfc3dSJohn Dyson 	while ((bp = TAILQ_FIRST(&bswlist)) == NULL) {
30416f62314SDavid Greenman 		bswneeded = 1;
30524a1cce3SDavid Greenman 		tsleep(&bswneeded, PVM, "wswbuf", 0);
30616f62314SDavid Greenman 	}
30716f62314SDavid Greenman 	TAILQ_REMOVE(&bswlist, bp, b_freelist);
30816f62314SDavid Greenman 	splx(s);
30916f62314SDavid Greenman 
31009e0c6ccSJohn Dyson 	initpbuf(bp);
31116f62314SDavid Greenman 	return bp;
31216f62314SDavid Greenman }
31316f62314SDavid Greenman 
31416f62314SDavid Greenman /*
31516f62314SDavid Greenman  * allocate a physical buffer, if one is available
31616f62314SDavid Greenman  */
31716f62314SDavid Greenman struct buf *
3180d94caffSDavid Greenman trypbuf()
3190d94caffSDavid Greenman {
32016f62314SDavid Greenman 	int s;
32116f62314SDavid Greenman 	struct buf *bp;
32216f62314SDavid Greenman 
32316f62314SDavid Greenman 	s = splbio();
324b18bfc3dSJohn Dyson 	if ((bp = TAILQ_FIRST(&bswlist)) == NULL) {
32516f62314SDavid Greenman 		splx(s);
32616f62314SDavid Greenman 		return NULL;
32716f62314SDavid Greenman 	}
32816f62314SDavid Greenman 	TAILQ_REMOVE(&bswlist, bp, b_freelist);
32916f62314SDavid Greenman 	splx(s);
33016f62314SDavid Greenman 
33109e0c6ccSJohn Dyson 	initpbuf(bp);
33209e0c6ccSJohn Dyson 
33316f62314SDavid Greenman 	return bp;
33416f62314SDavid Greenman }
33516f62314SDavid Greenman 
33616f62314SDavid Greenman /*
33716f62314SDavid Greenman  * release a physical buffer
33816f62314SDavid Greenman  */
33916f62314SDavid Greenman void
34016f62314SDavid Greenman relpbuf(bp)
34116f62314SDavid Greenman 	struct buf *bp;
34216f62314SDavid Greenman {
34316f62314SDavid Greenman 	int s;
34416f62314SDavid Greenman 
34516f62314SDavid Greenman 	s = splbio();
34616f62314SDavid Greenman 
34716f62314SDavid Greenman 	if (bp->b_rcred != NOCRED) {
34816f62314SDavid Greenman 		crfree(bp->b_rcred);
34916f62314SDavid Greenman 		bp->b_rcred = NOCRED;
35016f62314SDavid Greenman 	}
35116f62314SDavid Greenman 	if (bp->b_wcred != NOCRED) {
35216f62314SDavid Greenman 		crfree(bp->b_wcred);
35316f62314SDavid Greenman 		bp->b_wcred = NOCRED;
35416f62314SDavid Greenman 	}
35516f62314SDavid Greenman 	if (bp->b_vp)
3560d94caffSDavid Greenman 		pbrelvp(bp);
35716f62314SDavid Greenman 
35861854083SDavid Greenman 	if (bp->b_flags & B_WANTED)
35924a1cce3SDavid Greenman 		wakeup(bp);
36061854083SDavid Greenman 
36116f62314SDavid Greenman 	TAILQ_INSERT_HEAD(&bswlist, bp, b_freelist);
36216f62314SDavid Greenman 
36316f62314SDavid Greenman 	if (bswneeded) {
36416f62314SDavid Greenman 		bswneeded = 0;
36524a1cce3SDavid Greenman 		wakeup(&bswneeded);
36616f62314SDavid Greenman 	}
36716f62314SDavid Greenman 	splx(s);
36816f62314SDavid Greenman }
369