vm_pager.h revision 128038
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: head/sys/vm/vm_pager.h 128038 2004-04-08 19:08:49Z alc $
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
47TAILQ_HEAD(pagerlst, vm_object);
48
49struct bio;
50
51struct pagerops {
52	void (*pgo_init)(void);		/* Initialize pager. */
53	vm_object_t (*pgo_alloc)(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t);	/* Allocate pager. */
54	void (*pgo_dealloc)(vm_object_t);	/* Disassociate. */
55	int (*pgo_getpages)(vm_object_t, vm_page_t *, int, int);	/* Get (read) page. */
56	void (*pgo_putpages)(vm_object_t, vm_page_t *, int, int, int *); /* Put (write) page. */
57	boolean_t (*pgo_haspage)(vm_object_t, vm_pindex_t, int *, int *); /* Does pager have page? */
58	void (*pgo_pageunswapped)(vm_page_t);
59};
60
61extern struct pagerops defaultpagerops;
62extern struct pagerops swappagerops;
63extern struct pagerops vnodepagerops;
64extern struct pagerops devicepagerops;
65extern struct pagerops physpagerops;
66
67/*
68 * get/put return values
69 * OK	 operation was successful
70 * BAD	 specified data was out of the accepted range
71 * FAIL	 specified data was in range, but doesn't exist
72 * PEND	 operations was initiated but not completed
73 * ERROR error while accessing data that is in range and exists
74 * AGAIN temporary resource shortage prevented operation from happening
75 */
76#define	VM_PAGER_OK	0
77#define	VM_PAGER_BAD	1
78#define	VM_PAGER_FAIL	2
79#define	VM_PAGER_PEND	3
80#define	VM_PAGER_ERROR	4
81#define VM_PAGER_AGAIN	5
82
83#define	VM_PAGER_PUT_SYNC		0x0001
84#define	VM_PAGER_PUT_INVAL		0x0002
85#define VM_PAGER_IGNORE_CLEANCHK	0x0004
86#define VM_PAGER_CLUSTER_OK		0x0008
87
88#ifdef _KERNEL
89#ifdef MALLOC_DECLARE
90MALLOC_DECLARE(M_VMPGDATA);
91#endif
92
93extern vm_map_t pager_map;
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 *);
104
105/*
106 *	vm_page_get_pages:
107 *
108 *	Retrieve pages from the VM system in order to map them into an object
109 *	( or into VM space somewhere ).  If the pagein was successful, we
110 *	must fully validate it.
111 */
112static __inline int
113vm_pager_get_pages(
114	vm_object_t object,
115	vm_page_t *m,
116	int count,
117	int reqpage
118) {
119	int r;
120
121	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
122	r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage);
123	if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) {
124		vm_page_zero_invalid(m[reqpage], TRUE);
125	}
126	return (r);
127}
128
129static __inline void
130vm_pager_put_pages(
131	vm_object_t object,
132	vm_page_t *m,
133	int count,
134	int flags,
135	int *rtvals
136) {
137
138	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
139	(*pagertab[object->type]->pgo_putpages)
140	    (object, m, count, flags, rtvals);
141}
142
143/*
144 *	vm_pager_haspage
145 *
146 *	Check to see if an object's pager has the requested page.  The
147 *	object's pager will also set before and after to give the caller
148 *	some idea of the number of pages before and after the requested
149 *	page can be I/O'd efficiently.
150 *
151 *	This routine does not have to be called at any particular spl.
152 */
153static __inline boolean_t
154vm_pager_has_page(
155	vm_object_t object,
156	vm_pindex_t offset,
157	int *before,
158	int *after
159) {
160	boolean_t ret;
161
162	VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
163	ret = (*pagertab[object->type]->pgo_haspage)
164	    (object, offset, before, after);
165	return (ret);
166}
167
168/*
169 *      vm_pager_page_unswapped
170 *
171 *      called at splvm() to destroy swap associated with the page.
172 *
173 *      This function may not block.
174 *
175 *	XXX: A much better name would be "vm_pager_page_dirtied()"
176 *	XXX: It is not obvious if this could be profitably used by any
177 *	XXX: pagers besides the swap_pager or if it should even be a
178 *	XXX: generic pager_op in the first place.
179 */
180static __inline void
181vm_pager_page_unswapped(vm_page_t m)
182{
183
184	VM_OBJECT_LOCK_ASSERT(m->object, MA_OWNED);
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_ */
191