default_pager.c revision 12662
1/* 2 * Copyright (c) 1995, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by David Greenman. 16 * 4. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $Id: default_pager.c,v 1.2 1995/07/13 10:29:34 davidg Exp $ 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/queue.h> 39 40#include <vm/vm.h> 41#include <vm/vm_param.h> 42#include <vm/vm_prot.h> 43#include <vm/vm_object.h> 44#include <vm/vm_page.h> 45#include <vm/vm_pager.h> 46#include <vm/default_pager.h> 47#include <vm/swap_pager.h> 48 49/* 50 * pagerops for OBJT_DEFAULT - "default pager". 51 */ 52struct pagerops defaultpagerops = { 53 NULL, 54 default_pager_alloc, 55 default_pager_dealloc, 56 default_pager_getpages, 57 default_pager_putpages, 58 default_pager_haspage, 59 NULL 60}; 61 62/* 63 * no_pager_alloc just returns an initialized object. 64 */ 65vm_object_t 66default_pager_alloc(handle, size, prot, offset) 67 void *handle; 68 register vm_size_t size; 69 vm_prot_t prot; 70 vm_offset_t offset; 71{ 72 if (handle != NULL) 73 panic("default_pager_alloc: handle specified"); 74 75 return vm_object_allocate(OBJT_DEFAULT, offset + size); 76} 77 78void 79default_pager_dealloc(object) 80 vm_object_t object; 81{ 82 /* 83 * OBJT_DEFAULT objects have no special resources allocated to them. 84 */ 85} 86 87/* 88 * The default pager has no backing store, so we always return 89 * failure. 90 */ 91int 92default_pager_getpages(object, m, count, reqpage) 93 vm_object_t object; 94 vm_page_t *m; 95 int count; 96 int reqpage; 97{ 98 return VM_PAGER_FAIL; 99} 100 101int 102default_pager_putpages(object, m, c, sync, rtvals) 103 vm_object_t object; 104 vm_page_t *m; 105 int c; 106 boolean_t sync; 107 int *rtvals; 108{ 109 int i; 110 111 /* 112 * Try to convert the object type into a OBJT_SWAP. 113 * If the swp structure allocation fails, convert it 114 * back to OBJT_DEFAULT and return failure. Otherwise 115 * pass this putpages to the swap pager. 116 */ 117 object->type = OBJT_SWAP; 118 119 if (swap_pager_swp_alloc(object, M_KERNEL) != 0) { 120 object->type = OBJT_DEFAULT; 121 for (i = 0; i < c; i++) 122 rtvals[i] = VM_PAGER_FAIL; 123 return VM_PAGER_FAIL; 124 } 125 126 return swap_pager_putpages(object, m, c, sync, rtvals); 127} 128 129boolean_t 130default_pager_haspage(object, offset, before, after) 131 vm_object_t object; 132 vm_offset_t offset; 133 int *before; 134 int *after; 135{ 136 return FALSE; 137} 138