Deleted Added
full compact
vm_pager.h (116695) vm_pager.h (116710)
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94
39 * $FreeBSD: head/sys/vm/vm_pager.h 116695 2003-06-22 21:35:41Z alc $
39 * $FreeBSD: head/sys/vm/vm_pager.h 116710 2003-06-23 06:15:05Z alc $
40 */
41
42/*
43 * Pager routine interface definition.
44 */
45
46#ifndef _VM_PAGER_
47#define _VM_PAGER_
48
49#include <sys/queue.h>
50
51TAILQ_HEAD(pagerlst, vm_object);
52
53struct bio;
54
55struct pagerops {
56 void (*pgo_init)(void); /* Initialize pager. */
57 vm_object_t (*pgo_alloc)(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); /* Allocate pager. */
58 void (*pgo_dealloc)(vm_object_t); /* Disassociate. */
59 int (*pgo_getpages)(vm_object_t, vm_page_t *, int, int); /* Get (read) page. */
60 void (*pgo_putpages)(vm_object_t, vm_page_t *, int, int, int *); /* Put (write) page. */
61 boolean_t (*pgo_haspage)(vm_object_t, vm_pindex_t, int *, int *); /* Does pager have page? */
62 void (*pgo_pageunswapped)(vm_page_t);
63 void (*pgo_strategy)(vm_object_t, struct bio *);
64};
65
66/*
67 * get/put return values
68 * OK operation was successful
69 * BAD specified data was out of the accepted range
70 * FAIL specified data was in range, but doesn't exist
71 * PEND operations was initiated but not completed
72 * ERROR error while accessing data that is in range and exists
73 * AGAIN temporary resource shortage prevented operation from happening
74 */
75#define VM_PAGER_OK 0
76#define VM_PAGER_BAD 1
77#define VM_PAGER_FAIL 2
78#define VM_PAGER_PEND 3
79#define VM_PAGER_ERROR 4
80#define VM_PAGER_AGAIN 5
81
82#define VM_PAGER_PUT_SYNC 0x0001
83#define VM_PAGER_PUT_INVAL 0x0002
84#define VM_PAGER_IGNORE_CLEANCHK 0x0004
85#define VM_PAGER_CLUSTER_OK 0x0008
86
87#ifdef _KERNEL
88#ifdef MALLOC_DECLARE
89MALLOC_DECLARE(M_VMPGDATA);
90#endif
91
92extern vm_map_t pager_map;
93extern int pager_map_size;
94extern struct pagerops *pagertab[];
95extern struct mtx pbuf_mtx;
96
97vm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t);
98void vm_pager_bufferinit(void);
99void vm_pager_deallocate(vm_object_t);
100static __inline int vm_pager_get_pages(vm_object_t, vm_page_t *, int, int);
101static __inline boolean_t vm_pager_has_page(vm_object_t, vm_pindex_t, int *, int *);
102void vm_pager_init(void);
103vm_object_t vm_pager_object_lookup(struct pagerlst *, void *);
104vm_offset_t vm_pager_map_page(vm_page_t);
105void vm_pager_unmap_page(vm_offset_t);
106void vm_pager_strategy(vm_object_t object, struct bio *bp);
107
108/*
109 * vm_page_get_pages:
110 *
111 * Retrieve pages from the VM system in order to map them into an object
112 * ( or into VM space somewhere ). If the pagein was successful, we
113 * must fully validate it.
114 */
115static __inline int
116vm_pager_get_pages(
117 vm_object_t object,
118 vm_page_t *m,
119 int count,
120 int reqpage
121) {
40 */
41
42/*
43 * Pager routine interface definition.
44 */
45
46#ifndef _VM_PAGER_
47#define _VM_PAGER_
48
49#include <sys/queue.h>
50
51TAILQ_HEAD(pagerlst, vm_object);
52
53struct bio;
54
55struct pagerops {
56 void (*pgo_init)(void); /* Initialize pager. */
57 vm_object_t (*pgo_alloc)(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); /* Allocate pager. */
58 void (*pgo_dealloc)(vm_object_t); /* Disassociate. */
59 int (*pgo_getpages)(vm_object_t, vm_page_t *, int, int); /* Get (read) page. */
60 void (*pgo_putpages)(vm_object_t, vm_page_t *, int, int, int *); /* Put (write) page. */
61 boolean_t (*pgo_haspage)(vm_object_t, vm_pindex_t, int *, int *); /* Does pager have page? */
62 void (*pgo_pageunswapped)(vm_page_t);
63 void (*pgo_strategy)(vm_object_t, struct bio *);
64};
65
66/*
67 * get/put return values
68 * OK operation was successful
69 * BAD specified data was out of the accepted range
70 * FAIL specified data was in range, but doesn't exist
71 * PEND operations was initiated but not completed
72 * ERROR error while accessing data that is in range and exists
73 * AGAIN temporary resource shortage prevented operation from happening
74 */
75#define VM_PAGER_OK 0
76#define VM_PAGER_BAD 1
77#define VM_PAGER_FAIL 2
78#define VM_PAGER_PEND 3
79#define VM_PAGER_ERROR 4
80#define VM_PAGER_AGAIN 5
81
82#define VM_PAGER_PUT_SYNC 0x0001
83#define VM_PAGER_PUT_INVAL 0x0002
84#define VM_PAGER_IGNORE_CLEANCHK 0x0004
85#define VM_PAGER_CLUSTER_OK 0x0008
86
87#ifdef _KERNEL
88#ifdef MALLOC_DECLARE
89MALLOC_DECLARE(M_VMPGDATA);
90#endif
91
92extern vm_map_t pager_map;
93extern int pager_map_size;
94extern struct pagerops *pagertab[];
95extern struct mtx pbuf_mtx;
96
97vm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t);
98void vm_pager_bufferinit(void);
99void vm_pager_deallocate(vm_object_t);
100static __inline int vm_pager_get_pages(vm_object_t, vm_page_t *, int, int);
101static __inline boolean_t vm_pager_has_page(vm_object_t, vm_pindex_t, int *, int *);
102void vm_pager_init(void);
103vm_object_t vm_pager_object_lookup(struct pagerlst *, void *);
104vm_offset_t vm_pager_map_page(vm_page_t);
105void vm_pager_unmap_page(vm_offset_t);
106void vm_pager_strategy(vm_object_t object, struct bio *bp);
107
108/*
109 * vm_page_get_pages:
110 *
111 * Retrieve pages from the VM system in order to map them into an object
112 * ( or into VM space somewhere ). If the pagein was successful, we
113 * must fully validate it.
114 */
115static __inline int
116vm_pager_get_pages(
117 vm_object_t object,
118 vm_page_t *m,
119 int count,
120 int reqpage
121) {
122 int is_object_locked;
123 int r;
124
122 int r;
123
125 if (!(is_object_locked = VM_OBJECT_LOCKED(object)))
126 VM_OBJECT_LOCK(object);
124 VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
127 r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage);
128 if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) {
129 vm_page_zero_invalid(m[reqpage], TRUE);
130 }
125 r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage);
126 if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) {
127 vm_page_zero_invalid(m[reqpage], TRUE);
128 }
131 if (!is_object_locked)
132 VM_OBJECT_UNLOCK(object);
133 return (r);
134}
135
136static __inline void
137vm_pager_put_pages(
138 vm_object_t object,
139 vm_page_t *m,
140 int count,
141 int flags,
142 int *rtvals
143) {
144 GIANT_REQUIRED;
145 (*pagertab[object->type]->pgo_putpages)
146 (object, m, count, flags, rtvals);
147}
148
149/*
150 * vm_pager_haspage
151 *
152 * Check to see if an object's pager has the requested page. The
153 * object's pager will also set before and after to give the caller
154 * some idea of the number of pages before and after the requested
155 * page can be I/O'd efficiently.
156 *
157 * This routine does not have to be called at any particular spl.
158 */
159static __inline boolean_t
160vm_pager_has_page(
161 vm_object_t object,
162 vm_pindex_t offset,
163 int *before,
164 int *after
165) {
166 boolean_t ret;
167
168 VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
169 ret = (*pagertab[object->type]->pgo_haspage)
170 (object, offset, before, after);
171 return (ret);
172}
173
174/*
175 * vm_pager_page_unswapped
176 *
177 * called at splvm() to destroy swap associated with the page.
178 *
179 * This function may not block.
180 */
181static __inline void
182vm_pager_page_unswapped(vm_page_t m)
183{
184 GIANT_REQUIRED;
185 if (pagertab[m->object->type]->pgo_pageunswapped)
186 (*pagertab[m->object->type]->pgo_pageunswapped)(m);
187}
188
189#endif /* _KERNEL */
190#endif /* _VM_PAGER_ */
129 return (r);
130}
131
132static __inline void
133vm_pager_put_pages(
134 vm_object_t object,
135 vm_page_t *m,
136 int count,
137 int flags,
138 int *rtvals
139) {
140 GIANT_REQUIRED;
141 (*pagertab[object->type]->pgo_putpages)
142 (object, m, count, flags, rtvals);
143}
144
145/*
146 * vm_pager_haspage
147 *
148 * Check to see if an object's pager has the requested page. The
149 * object's pager will also set before and after to give the caller
150 * some idea of the number of pages before and after the requested
151 * page can be I/O'd efficiently.
152 *
153 * This routine does not have to be called at any particular spl.
154 */
155static __inline boolean_t
156vm_pager_has_page(
157 vm_object_t object,
158 vm_pindex_t offset,
159 int *before,
160 int *after
161) {
162 boolean_t ret;
163
164 VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
165 ret = (*pagertab[object->type]->pgo_haspage)
166 (object, offset, before, after);
167 return (ret);
168}
169
170/*
171 * vm_pager_page_unswapped
172 *
173 * called at splvm() to destroy swap associated with the page.
174 *
175 * This function may not block.
176 */
177static __inline void
178vm_pager_page_unswapped(vm_page_t m)
179{
180 GIANT_REQUIRED;
181 if (pagertab[m->object->type]->pgo_pageunswapped)
182 (*pagertab[m->object->type]->pgo_pageunswapped)(m);
183}
184
185#endif /* _KERNEL */
186#endif /* _VM_PAGER_ */