default_pager.c revision 116226
19514Sdg/*
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 116226 2003-06-11 23:50:51Z obrien $");
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 = {
679513Sdg	NULL,
689513Sdg	default_pager_alloc,
699513Sdg	default_pager_dealloc,
709513Sdg	default_pager_getpages,
719513Sdg	default_pager_putpages,
729513Sdg	default_pager_haspage,
739513Sdg	NULL
749513Sdg};
759513Sdg
769513Sdg/*
779513Sdg * no_pager_alloc just returns an initialized object.
789513Sdg */
7912820Sphkstatic vm_object_t
8040286Sdgdefault_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
8128751Sbde		    vm_ooffset_t offset)
829513Sdg{
839513Sdg	if (handle != NULL)
849513Sdg		panic("default_pager_alloc: handle specified");
859513Sdg
8640286Sdg	return vm_object_allocate(OBJT_DEFAULT, OFF_TO_IDX(round_page(offset + size)));
879513Sdg}
889513Sdg
8942957Sdillon/*
9042957Sdillon * deallocate resources associated with default objects.   The default objects
9142957Sdillon * have no special resources allocated to them, but the vm_page's being used
9242957Sdillon * in this object might.  Still, we do not have to do anything - we will free
9342957Sdillon * the swapblk in the underlying vm_page's when we free the vm_page or
9442957Sdillon * garbage collect the vm_page cache list.
9542957Sdillon */
9612820Sphkstatic void
979513Sdgdefault_pager_dealloc(object)
989513Sdg	vm_object_t object;
999513Sdg{
1009513Sdg	/*
1019513Sdg	 * OBJT_DEFAULT objects have no special resources allocated to them.
1029513Sdg	 */
1039513Sdg}
1049513Sdg
1059513Sdg/*
10642957Sdillon * Load pages from backing store.  Since OBJT_DEFAULT is converted to
10742957Sdillon * OBJT_SWAP at the time a swap-backed vm_page_t is freed, we will never
10842957Sdillon * see a vm_page with assigned swap here.
1099513Sdg */
11012820Sphkstatic int
1119513Sdgdefault_pager_getpages(object, m, count, reqpage)
1129513Sdg	vm_object_t object;
1139513Sdg	vm_page_t *m;
1149513Sdg	int count;
1159513Sdg	int reqpage;
1169513Sdg{
1179513Sdg	return VM_PAGER_FAIL;
1189513Sdg}
1199513Sdg
12042957Sdillon/*
12142957Sdillon * Store pages to backing store.  We should assign swap and initiate
12242957Sdillon * I/O.  We do not actually convert the object to OBJT_SWAP here.  The
12342957Sdillon * object will be converted when the written-out vm_page_t is moved from the
12442957Sdillon * cache to the free list.
12542957Sdillon */
12643129Sdillonstatic void
1279513Sdgdefault_pager_putpages(object, m, c, sync, rtvals)
1289513Sdg	vm_object_t object;
1299513Sdg	vm_page_t *m;
1309513Sdg	int c;
1319513Sdg	boolean_t sync;
1329513Sdg	int *rtvals;
1339513Sdg{
13443129Sdillon	swap_pager_putpages(object, m, c, sync, rtvals);
1359513Sdg}
1369513Sdg
13742957Sdillon/*
13842957Sdillon * Tell us whether the backing store for the requested (object,index) is
13942957Sdillon * synchronized.  i.e. tell us whether we can throw the page away and
14042957Sdillon * reload it later.  So, for example, if we are in the process of writing
14142957Sdillon * the page to its backing store, or if no backing store has been assigned,
14242957Sdillon * it is not yet synchronized.
14342957Sdillon *
14442957Sdillon * It is possible to have fully-synchronized swap assigned without the
14542957Sdillon * object having been converted.  We just call swap_pager_haspage() to
14642957Sdillon * deal with it since it must already deal with it plus deal with swap
14742957Sdillon * meta-data structures.
14842957Sdillon */
14912820Sphkstatic boolean_t
15012767Sdysondefault_pager_haspage(object, pindex, before, after)
1519513Sdg	vm_object_t object;
15212767Sdyson	vm_pindex_t pindex;
1539513Sdg	int *before;
1549513Sdg	int *after;
1559513Sdg{
1569513Sdg	return FALSE;
1579513Sdg}
15815978Sdyson
159