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 * $FreeBSD: src/sys/vm/default_pager.c,v 1.9.2.1 1999/09/05 08:24:13 peter 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 #include <sys/vmmeter.h>
40
41 #include <vm/vm.h>
42 #include <vm/vm_param.h>
43 #include <vm/vm_prot.h>
44 #include <vm/vm_object.h>
45 #include <vm/vm_page.h>
46 #include <vm/vm_pager.h>
47 #include <vm/default_pager.h>
48 #include <vm/swap_pager.h>
49
50 static vm_object_t default_pager_alloc __P((void *, vm_size_t, vm_prot_t,
51 vm_ooffset_t));
52 static void default_pager_dealloc __P((vm_object_t));
53 static int default_pager_getpages __P((vm_object_t, vm_page_t *, int, int));
54 static int default_pager_putpages __P((vm_object_t, vm_page_t *, int,
55 boolean_t, int *));
56 static boolean_t default_pager_haspage __P((vm_object_t, vm_pindex_t, int *,
57 int *));
58 /*
59 * pagerops for OBJT_DEFAULT - "default pager".
60 */
61 struct pagerops defaultpagerops = {
62 NULL,
63 default_pager_alloc,
64 default_pager_dealloc,
65 default_pager_getpages,
66 default_pager_putpages,
67 default_pager_haspage,
68 NULL
69 };
70
71 /*
72 * no_pager_alloc just returns an initialized object.
73 */
74 static vm_object_t
75 default_pager_alloc(handle, size, prot, offset)
76 void *handle;
77 register vm_size_t size;
78 vm_prot_t prot;
79 vm_ooffset_t offset;
80 {
81 if (handle != NULL)
82 panic("default_pager_alloc: handle specified");
83
84 return vm_object_allocate(OBJT_DEFAULT, OFF_TO_IDX(offset) + size);
85 }
86
87 static void
88 default_pager_dealloc(object)
89 vm_object_t object;
90 {
91 /*
92 * OBJT_DEFAULT objects have no special resources allocated to them.
93 */
94 }
95
96 /*
97 * The default pager has no backing store, so we always return
98 * failure.
99 */
100 static int
101 default_pager_getpages(object, m, count, reqpage)
102 vm_object_t object;
103 vm_page_t *m;
104 int count;
105 int reqpage;
106 {
107 return VM_PAGER_FAIL;
108 }
109
110 static int
111 default_pager_putpages(object, m, c, sync, rtvals)
112 vm_object_t object;
113 vm_page_t *m;
114 int c;
115 boolean_t sync;
116 int *rtvals;
117 {
118 int i;
119
120 /*
121 * Try to convert the object type into a OBJT_SWAP.
122 * If the swp structure allocation fails, convert it
123 * back to OBJT_DEFAULT and return failure. Otherwise
124 * pass this putpages to the swap pager.
125 */
126 object->type = OBJT_SWAP;
127
128 if (swap_pager_swp_alloc(object, M_KERNEL) != 0) {
129 object->type = OBJT_DEFAULT;
130 for (i = 0; i < c; i++)
131 rtvals[i] = VM_PAGER_FAIL;
132 return VM_PAGER_FAIL;
133 }
134
135 return swap_pager_putpages(object, m, c, sync, rtvals);
136 }
137
138 static boolean_t
139 default_pager_haspage(object, pindex, before, after)
140 vm_object_t object;
141 vm_pindex_t pindex;
142 int *before;
143 int *after;
144 {
145 return FALSE;
146 }
147
148 void
149 default_pager_convert_to_swap(object)
150 vm_object_t object;
151 {
152 object->type = OBJT_SWAP;
153 if (swap_pager_swp_alloc(object, M_KERNEL) != 0) {
154 object->type = OBJT_DEFAULT;
155 }
156 }
157
158 void
159 default_pager_convert_to_swapq(object)
160 vm_object_t object;
161 {
162 if (object &&
163 (object->type == OBJT_DEFAULT) &&
164 (object != kernel_object && object != kmem_object) &&
165 (object->size > ((cnt.v_page_count - cnt.v_wire_count) / 4)))
166 default_pager_convert_to_swap(object);
167 }
168
Cache object: b8490758c4adef40ced74cbe77b4ff65
|