FreeBSD/Linux Kernel Cross Reference
sys/vm/vm_pager.h
1 /*-
2 * Copyright (c) 1990 University of Utah.
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
8 * Science Department.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94
35 * $FreeBSD$
36 */
37
38 /*
39 * Pager routine interface definition.
40 */
41
42 #ifndef _VM_PAGER_
43 #define _VM_PAGER_
44
45 #include <sys/queue.h>
46
47 TAILQ_HEAD(pagerlst, vm_object);
48
49 typedef void pgo_init_t(void);
50 typedef vm_object_t pgo_alloc_t(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t,
51 struct ucred *);
52 typedef void pgo_dealloc_t(vm_object_t);
53 typedef int pgo_getpages_t(vm_object_t, vm_page_t *, int, int *, int *);
54 typedef void pgo_getpages_iodone_t(void *, vm_page_t *, int, int);
55 typedef int pgo_getpages_async_t(vm_object_t, vm_page_t *, int, int *, int *,
56 pgo_getpages_iodone_t, void *);
57 typedef void pgo_putpages_t(vm_object_t, vm_page_t *, int, int, int *);
58 typedef boolean_t pgo_haspage_t(vm_object_t, vm_pindex_t, int *, int *);
59 typedef int pgo_populate_t(vm_object_t, vm_pindex_t, int, vm_prot_t,
60 vm_pindex_t *, vm_pindex_t *);
61 typedef void pgo_pageunswapped_t(vm_page_t);
62
63 struct pagerops {
64 pgo_init_t *pgo_init; /* Initialize pager. */
65 pgo_alloc_t *pgo_alloc; /* Allocate pager. */
66 pgo_dealloc_t *pgo_dealloc; /* Disassociate. */
67 pgo_getpages_t *pgo_getpages; /* Get (read) page. */
68 pgo_getpages_async_t *pgo_getpages_async; /* Get page asyncly. */
69 pgo_putpages_t *pgo_putpages; /* Put (write) page. */
70 pgo_haspage_t *pgo_haspage; /* Query page. */
71 pgo_populate_t *pgo_populate; /* Bulk spec pagein. */
72 pgo_pageunswapped_t *pgo_pageunswapped;
73 };
74
75 extern struct pagerops defaultpagerops;
76 extern struct pagerops swappagerops;
77 extern struct pagerops vnodepagerops;
78 extern struct pagerops devicepagerops;
79 extern struct pagerops physpagerops;
80 extern struct pagerops sgpagerops;
81 extern struct pagerops mgtdevicepagerops;
82
83 /*
84 * get/put return values
85 * OK operation was successful
86 * BAD specified data was out of the accepted range
87 * FAIL specified data was in range, but doesn't exist
88 * PEND operations was initiated but not completed
89 * ERROR error while accessing data that is in range and exists
90 * AGAIN temporary resource shortage prevented operation from happening
91 */
92 #define VM_PAGER_OK 0
93 #define VM_PAGER_BAD 1
94 #define VM_PAGER_FAIL 2
95 #define VM_PAGER_PEND 3
96 #define VM_PAGER_ERROR 4
97 #define VM_PAGER_AGAIN 5
98
99 #define VM_PAGER_PUT_SYNC 0x0001
100 #define VM_PAGER_PUT_INVAL 0x0002
101 #define VM_PAGER_PUT_NOREUSE 0x0004
102 #define VM_PAGER_CLUSTER_OK 0x0008
103
104 #ifdef _KERNEL
105
106 extern struct pagerops *pagertab[];
107 extern struct mtx_padalign pbuf_mtx;
108
109 vm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t,
110 vm_ooffset_t, struct ucred *);
111 void vm_pager_bufferinit(void);
112 void vm_pager_deallocate(vm_object_t);
113 int vm_pager_get_pages(vm_object_t, vm_page_t *, int, int *, int *);
114 int vm_pager_get_pages_async(vm_object_t, vm_page_t *, int, int *, int *,
115 pgo_getpages_iodone_t, void *);
116 void vm_pager_init(void);
117 vm_object_t vm_pager_object_lookup(struct pagerlst *, void *);
118
119 static __inline void
120 vm_pager_put_pages(
121 vm_object_t object,
122 vm_page_t *m,
123 int count,
124 int flags,
125 int *rtvals
126 ) {
127
128 VM_OBJECT_ASSERT_WLOCKED(object);
129 (*pagertab[object->type]->pgo_putpages)
130 (object, m, count, flags, rtvals);
131 }
132
133 /*
134 * vm_pager_haspage
135 *
136 * Check to see if an object's pager has the requested page. The
137 * object's pager will also set before and after to give the caller
138 * some idea of the number of pages before and after the requested
139 * page can be I/O'd efficiently.
140 *
141 * The object must be locked.
142 */
143 static __inline boolean_t
144 vm_pager_has_page(
145 vm_object_t object,
146 vm_pindex_t offset,
147 int *before,
148 int *after
149 ) {
150 boolean_t ret;
151
152 VM_OBJECT_ASSERT_WLOCKED(object);
153 ret = (*pagertab[object->type]->pgo_haspage)
154 (object, offset, before, after);
155 return (ret);
156 }
157
158 static __inline int
159 vm_pager_populate(vm_object_t object, vm_pindex_t pidx, int fault_type,
160 vm_prot_t max_prot, vm_pindex_t *first, vm_pindex_t *last)
161 {
162
163 MPASS((object->flags & OBJ_POPULATE) != 0);
164 MPASS(pidx < object->size);
165 MPASS(object->paging_in_progress > 0);
166 return ((*pagertab[object->type]->pgo_populate)(object, pidx,
167 fault_type, max_prot, first, last));
168 }
169
170
171 /*
172 * vm_pager_page_unswapped
173 *
174 * Destroy swap associated with the page.
175 *
176 * The object containing the page must be locked.
177 * This function may not block.
178 *
179 * XXX: A much better name would be "vm_pager_page_dirtied()"
180 * XXX: It is not obvious if this could be profitably used by any
181 * XXX: pagers besides the swap_pager or if it should even be a
182 * XXX: generic pager_op in the first place.
183 */
184 static __inline void
185 vm_pager_page_unswapped(vm_page_t m)
186 {
187
188 VM_OBJECT_ASSERT_LOCKED(m->object);
189 if (pagertab[m->object->type]->pgo_pageunswapped)
190 (*pagertab[m->object->type]->pgo_pageunswapped)(m);
191 }
192
193 struct cdev_pager_ops {
194 int (*cdev_pg_fault)(vm_object_t vm_obj, vm_ooffset_t offset,
195 int prot, vm_page_t *mres);
196 int (*cdev_pg_populate)(vm_object_t vm_obj, vm_pindex_t pidx,
197 int fault_type, vm_prot_t max_prot, vm_pindex_t *first,
198 vm_pindex_t *last);
199 int (*cdev_pg_ctor)(void *handle, vm_ooffset_t size, vm_prot_t prot,
200 vm_ooffset_t foff, struct ucred *cred, u_short *color);
201 void (*cdev_pg_dtor)(void *handle);
202 };
203
204 vm_object_t cdev_pager_allocate(void *handle, enum obj_type tp,
205 struct cdev_pager_ops *ops, vm_ooffset_t size, vm_prot_t prot,
206 vm_ooffset_t foff, struct ucred *cred);
207 vm_object_t cdev_pager_lookup(void *handle);
208 void cdev_pager_free_page(vm_object_t object, vm_page_t m);
209
210 #endif /* _KERNEL */
211 #endif /* _VM_PAGER_ */
Cache object: 92cfd7d642b78f96e9d7bd04e053bc31
|