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