default_pager.c revision 139825
1139825Simp/*-
29514Sdg * Copyright (c) 1995, David Greenman
39514Sdg * All rights reserved.
49514Sdg *
59514Sdg * Redistribution and use in source and binary forms, with or without
69514Sdg * modification, are permitted provided that the following conditions
79514Sdg * are met:
89514Sdg * 1. Redistributions of source code must retain the above copyright
99514Sdg *    notice, this list of conditions and the following disclaimer.
109514Sdg * 2. Redistributions in binary form must reproduce the above copyright
119514Sdg *    notice, this list of conditions and the following disclaimer in the
129514Sdg *    documentation and/or other materials provided with the distribution.
139514Sdg * 3. All advertising materials mentioning features or use of this software
1458705Scharnier *    must display the following acknowledgement:
159514Sdg *	This product includes software developed by David Greenman.
169514Sdg * 4. The name of the author may not be used to endorse or promote products
179514Sdg *    derived from this software without specific prior written permission.
189514Sdg *
199514Sdg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
209514Sdg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219514Sdg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
229514Sdg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
239514Sdg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
249514Sdg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
259514Sdg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
269514Sdg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
279514Sdg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
289514Sdg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
299514Sdg * SUCH DAMAGE.
309514Sdg *
3142957Sdillon * The default pager is responsible for supplying backing store to unbacked
3242957Sdillon * storage.  The backing store is usually swap so we just fall through to
3342957Sdillon * the swap routines.  However, since swap metadata has not been assigned,
3442957Sdillon * the swap routines assign and manage the swap backing store through the
3542957Sdillon * vm_page->swapblk field.  The object is only converted when the page is
3642957Sdillon * physically freed after having been cleaned and even then vm_page->swapblk
3742957Sdillon * is maintained whenever a resident page also has swap backing store.
389514Sdg */
399514Sdg
40116226Sobrien#include <sys/cdefs.h>
41116226Sobrien__FBSDID("$FreeBSD: head/sys/vm/default_pager.c 139825 2005-01-07 02:29:27Z imp $");
42116226Sobrien
439513Sdg#include <sys/param.h>
449513Sdg#include <sys/systm.h>
4576827Salfred#include <sys/lock.h>
4679224Sdillon#include <sys/proc.h>
4776827Salfred#include <sys/mutex.h>
489513Sdg
499513Sdg#include <vm/vm.h>
5012662Sdg#include <vm/vm_object.h>
5112662Sdg#include <vm/vm_page.h>
529513Sdg#include <vm/vm_pager.h>
539513Sdg#include <vm/swap_pager.h>
549513Sdg
5592727Salfredstatic vm_object_t default_pager_alloc(void *, vm_ooffset_t, vm_prot_t,
5692727Salfred		vm_ooffset_t);
5792727Salfredstatic void default_pager_dealloc(vm_object_t);
5892727Salfredstatic int default_pager_getpages(vm_object_t, vm_page_t *, int, int);
5992727Salfredstatic void default_pager_putpages(vm_object_t, vm_page_t *, int,
6092727Salfred		boolean_t, int *);
6192727Salfredstatic boolean_t default_pager_haspage(vm_object_t, vm_pindex_t, int *,
6292727Salfred		int *);
639513Sdg/*
649513Sdg * pagerops for OBJT_DEFAULT - "default pager".
659513Sdg */
669513Sdgstruct pagerops defaultpagerops = {
67118466Sphk	.pgo_alloc =	default_pager_alloc,
68118466Sphk	.pgo_dealloc =	default_pager_dealloc,
69118466Sphk	.pgo_getpages =	default_pager_getpages,
70118466Sphk	.pgo_putpages =	default_pager_putpages,
71118466Sphk	.pgo_haspage =	default_pager_haspage,
729513Sdg};
739513Sdg
749513Sdg/*
759513Sdg * no_pager_alloc just returns an initialized object.
769513Sdg */
7712820Sphkstatic vm_object_t
7840286Sdgdefault_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
7928751Sbde		    vm_ooffset_t offset)
809513Sdg{
819513Sdg	if (handle != NULL)
829513Sdg		panic("default_pager_alloc: handle specified");
839513Sdg
8440286Sdg	return vm_object_allocate(OBJT_DEFAULT, OFF_TO_IDX(round_page(offset + size)));
859513Sdg}
869513Sdg
8742957Sdillon/*
8842957Sdillon * deallocate resources associated with default objects.   The default objects
8942957Sdillon * have no special resources allocated to them, but the vm_page's being used
9042957Sdillon * in this object might.  Still, we do not have to do anything - we will free
9142957Sdillon * the swapblk in the underlying vm_page's when we free the vm_page or
9242957Sdillon * garbage collect the vm_page cache list.
9342957Sdillon */
9412820Sphkstatic void
959513Sdgdefault_pager_dealloc(object)
969513Sdg	vm_object_t object;
979513Sdg{
989513Sdg	/*
999513Sdg	 * OBJT_DEFAULT objects have no special resources allocated to them.
1009513Sdg	 */
1019513Sdg}
1029513Sdg
1039513Sdg/*
10442957Sdillon * Load pages from backing store.  Since OBJT_DEFAULT is converted to
10542957Sdillon * OBJT_SWAP at the time a swap-backed vm_page_t is freed, we will never
10642957Sdillon * see a vm_page with assigned swap here.
1079513Sdg */
10812820Sphkstatic int
1099513Sdgdefault_pager_getpages(object, m, count, reqpage)
1109513Sdg	vm_object_t object;
1119513Sdg	vm_page_t *m;
1129513Sdg	int count;
1139513Sdg	int reqpage;
1149513Sdg{
1159513Sdg	return VM_PAGER_FAIL;
1169513Sdg}
1179513Sdg
11842957Sdillon/*
11942957Sdillon * Store pages to backing store.  We should assign swap and initiate
12042957Sdillon * I/O.  We do not actually convert the object to OBJT_SWAP here.  The
12142957Sdillon * object will be converted when the written-out vm_page_t is moved from the
12242957Sdillon * cache to the free list.
12342957Sdillon */
12443129Sdillonstatic void
1259513Sdgdefault_pager_putpages(object, m, c, sync, rtvals)
1269513Sdg	vm_object_t object;
1279513Sdg	vm_page_t *m;
1289513Sdg	int c;
1299513Sdg	boolean_t sync;
1309513Sdg	int *rtvals;
1319513Sdg{
132118535Sphk	swappagerops.pgo_putpages(object, m, c, sync, rtvals);
1339513Sdg}
1349513Sdg
13542957Sdillon/*
13642957Sdillon * Tell us whether the backing store for the requested (object,index) is
13742957Sdillon * synchronized.  i.e. tell us whether we can throw the page away and
13842957Sdillon * reload it later.  So, for example, if we are in the process of writing
13942957Sdillon * the page to its backing store, or if no backing store has been assigned,
14042957Sdillon * it is not yet synchronized.
14142957Sdillon *
14242957Sdillon * It is possible to have fully-synchronized swap assigned without the
14342957Sdillon * object having been converted.  We just call swap_pager_haspage() to
14442957Sdillon * deal with it since it must already deal with it plus deal with swap
14542957Sdillon * meta-data structures.
14642957Sdillon */
14712820Sphkstatic boolean_t
14812767Sdysondefault_pager_haspage(object, pindex, before, after)
1499513Sdg	vm_object_t object;
15012767Sdyson	vm_pindex_t pindex;
1519513Sdg	int *before;
1529513Sdg	int *after;
1539513Sdg{
1549513Sdg	return FALSE;
1559513Sdg}
15615978Sdyson
157