default_pager.c revision 15887
1132718Skan/* 2169699Skan * Copyright (c) 1995, David Greenman 3132718Skan * All rights reserved. 4132718Skan * 5132718Skan * Redistribution and use in source and binary forms, with or without 6132718Skan * modification, are permitted provided that the following conditions 7132718Skan * are met: 8132718Skan * 1. Redistributions of source code must retain the above copyright 9132718Skan * notice, this list of conditions and the following disclaimer. 10169699Skan * 2. Redistributions in binary form must reproduce the above copyright 11132718Skan * notice, this list of conditions and the following disclaimer in the 12132718Skan * documentation and/or other materials provided with the distribution. 13132718Skan * 3. All advertising materials mentioning features or use of this software 14132718Skan * must display the following acknowledgement: 15169699Skan * This product includes software developed by David Greenman. 16132718Skan * 4. The name of the author may not be used to endorse or promote products 17132718Skan * derived from this software without specific prior written permission. 18169699Skan * 19169699Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20132718Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21169699Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22132718Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23169699Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24132718Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25132718Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26132718Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27132718Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28132718Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29132718Skan * SUCH DAMAGE. 30132718Skan * 31132718Skan * $Id: default_pager.c,v 1.6 1996/01/19 03:59:36 dyson Exp $ 32132718Skan */ 33132718Skan 34132718Skan#include <sys/param.h> 35132718Skan#include <sys/systm.h> 36132718Skan#include <sys/kernel.h> 37132718Skan#include <sys/malloc.h> 38132718Skan#include <sys/queue.h> 39132718Skan 40132718Skan#include <vm/vm.h> 41132718Skan#include <vm/vm_param.h> 42132718Skan#include <vm/vm_prot.h> 43132718Skan#include <vm/vm_object.h> 44132718Skan#include <vm/vm_page.h> 45132718Skan#include <vm/vm_pager.h> 46132718Skan#include <vm/default_pager.h> 47132718Skan#include <vm/swap_pager.h> 48132718Skan 49132718Skanstatic vm_object_t default_pager_alloc __P((void *, vm_size_t, vm_prot_t, 50132718Skan vm_ooffset_t)); 51132718Skanstatic void default_pager_dealloc __P((vm_object_t)); 52132718Skanstatic int default_pager_getpages __P((vm_object_t, vm_page_t *, int, int)); 53132718Skanstatic int default_pager_putpages __P((vm_object_t, vm_page_t *, int, 54132718Skan boolean_t, int *)); 55132718Skanstatic boolean_t default_pager_haspage __P((vm_object_t, vm_pindex_t, int *, 56132718Skan int *)); 57132718Skan/* 58132718Skan * pagerops for OBJT_DEFAULT - "default pager". 59132718Skan */ 60169699Skanstruct pagerops defaultpagerops = { 61169699Skan NULL, 62169699Skan default_pager_alloc, 63169699Skan default_pager_dealloc, 64132718Skan default_pager_getpages, 65132718Skan default_pager_putpages, 66132718Skan default_pager_haspage, 67132718Skan NULL 68132718Skan}; 69132718Skan 70169699Skan/* 71132718Skan * no_pager_alloc just returns an initialized object. 72132718Skan */ 73132718Skanstatic vm_object_t 74132718Skandefault_pager_alloc(handle, size, prot, offset) 75132718Skan void *handle; 76132718Skan register vm_size_t size; 77132718Skan vm_prot_t prot; 78132718Skan vm_ooffset_t offset; 79132718Skan{ 80132718Skan if (handle != NULL) 81132718Skan panic("default_pager_alloc: handle specified"); 82132718Skan 83132718Skan return vm_object_allocate(OBJT_DEFAULT, OFF_TO_IDX(offset) + size); 84132718Skan} 85132718Skan 86132718Skanstatic void 87132718Skandefault_pager_dealloc(object) 88132718Skan vm_object_t object; 89132718Skan{ 90132718Skan /* 91132718Skan * OBJT_DEFAULT objects have no special resources allocated to them. 92132718Skan */ 93132718Skan} 94132718Skan 95132718Skan/* 96132718Skan * The default pager has no backing store, so we always return 97132718Skan * failure. 98132718Skan */ 99132718Skanstatic int 100132718Skandefault_pager_getpages(object, m, count, reqpage) 101132718Skan vm_object_t object; 102132718Skan vm_page_t *m; 103132718Skan int count; 104132718Skan int reqpage; 105132718Skan{ 106132718Skan return VM_PAGER_FAIL; 107132718Skan} 108132718Skan 109132718Skanstatic int 110132718Skandefault_pager_putpages(object, m, c, sync, rtvals) 111132718Skan vm_object_t object; 112132718Skan vm_page_t *m; 113132718Skan int c; 114132718Skan boolean_t sync; 115132718Skan int *rtvals; 116132718Skan{ 117169699Skan int i; 118169699Skan 119132718Skan /* 120169699Skan * Try to convert the object type into a OBJT_SWAP. 121169699Skan * If the swp structure allocation fails, convert it 122169699Skan * back to OBJT_DEFAULT and return failure. Otherwise 123169699Skan * pass this putpages to the swap pager. 124132718Skan */ 125132718Skan object->type = OBJT_SWAP; 126132718Skan 127132718Skan if (swap_pager_swp_alloc(object, M_KERNEL) != 0) { 128169699Skan if (swap_pager_swp_alloc(object, M_NOWAIT) != 0) { 129169699Skan object->type = OBJT_DEFAULT; 130169699Skan for (i = 0; i < c; i++) 131169699Skan rtvals[i] = VM_PAGER_FAIL; 132132718Skan return VM_PAGER_FAIL; 133169699Skan } 134132718Skan } 135132718Skan 136169699Skan return swap_pager_putpages(object, m, c, sync, rtvals); 137169699Skan} 138169699Skan 139169699Skanstatic boolean_t 140169699Skandefault_pager_haspage(object, pindex, before, after) 141132718Skan vm_object_t object; 142169699Skan vm_pindex_t pindex; 143132718Skan int *before; 144132718Skan int *after; 145132718Skan{ 146169699Skan return FALSE; 147132718Skan} 148132718Skan