kernel - simplify vm pager ops, add pre-faulting for zero-fill pages.
[dragonfly.git] / sys / vm / vm_pager.h
CommitLineData
984263bc
MD
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: src/sys/vm/vm_pager.h,v 1.24.2.2 2002/12/31 09:34:51 dillon Exp $
e4846942 40 * $DragonFly: src/sys/vm/vm_pager.h,v 1.9 2006/12/28 21:24:02 dillon Exp $
984263bc
MD
41 */
42
43/*
44 * Pager routine interface definition.
45 */
46
1bd40720
MD
47#ifndef _VM_VM_PAGER_H_
48#define _VM_VM_PAGER_H_
984263bc 49
1bd40720 50#ifndef _SYS_QUEUE_H_
984263bc 51#include <sys/queue.h>
1bd40720
MD
52#endif
53#ifndef _VM_VM_PAGE_H_
54#include <vm/vm_page.h>
55#endif
56#ifndef _VM_VM_OBJECT_H_
57#include <vm/vm_object.h>
58#endif
984263bc
MD
59
60TAILQ_HEAD(pagerlst, vm_object);
61
62struct buf;
81b5c339 63struct bio;
984263bc
MD
64
65struct pagerops {
1388df65
RG
66 void (*pgo_init) (void); /* Initialize pager. */
67 vm_object_t (*pgo_alloc) (void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); /* Allocate pager. */
68 void (*pgo_dealloc) (vm_object_t); /* Disassociate. */
1b9d3514
MD
69 int (*pgo_getpage) (vm_object_t, vm_page_t *, int);
70 void (*pgo_putpages) (vm_object_t, vm_page_t *, int, int, int *);
71 boolean_t (*pgo_haspage) (vm_object_t, vm_pindex_t);
1388df65 72 void (*pgo_pageunswapped) (vm_page_t);
81b5c339 73 void (*pgo_strategy) (vm_object_t, struct bio *);
984263bc
MD
74};
75
76/*
77 * get/put return values
78 * OK operation was successful
79 * BAD specified data was out of the accepted range
80 * FAIL specified data was in range, but doesn't exist
81 * PEND operations was initiated but not completed
82 * ERROR error while accessing data that is in range and exists
83 * AGAIN temporary resource shortage prevented operation from happening
84 */
85#define VM_PAGER_OK 0
86#define VM_PAGER_BAD 1
87#define VM_PAGER_FAIL 2
88#define VM_PAGER_PEND 3
89#define VM_PAGER_ERROR 4
90#define VM_PAGER_AGAIN 5
91
92#define VM_PAGER_PUT_SYNC 0x0001
93#define VM_PAGER_PUT_INVAL 0x0002
94#define VM_PAGER_IGNORE_CLEANCHK 0x0004
95#define VM_PAGER_CLUSTER_OK 0x0008
96
97#ifdef _KERNEL
98
99#ifdef MALLOC_DECLARE
100MALLOC_DECLARE(M_VMPGDATA);
101#endif
102
b5d6ce92
JS
103struct vnode;
104
e4846942 105extern struct vm_map pager_map;
984263bc
MD
106extern int pager_map_size;
107extern struct pagerops *pagertab[];
108
57f7b636 109vm_object_t vm_pager_allocate (objtype_t, void *, off_t, vm_prot_t, off_t);
1388df65
RG
110void vm_pager_bufferinit (void);
111void vm_pager_deallocate (vm_object_t);
1b9d3514
MD
112static __inline int vm_pager_get_page (vm_object_t, vm_page_t *, int);
113static __inline boolean_t vm_pager_has_page (vm_object_t, vm_pindex_t);
1388df65
RG
114void vm_pager_init (void);
115vm_object_t vm_pager_object_lookup (struct pagerlst *, void *);
1388df65 116void vm_pager_sync (void);
81b5c339 117void vm_pager_strategy (vm_object_t object, struct bio *bio);
984263bc
MD
118struct buf *getchainbuf(struct buf *bp, struct vnode *vp, int flags);
119void flushchainbuf(struct buf *nbp);
120void waitchainbuf(struct buf *bp, int count, int done);
121void autochaindone(struct buf *bp);
122
123/*
1b9d3514 124 * vm_page_get_pages:
984263bc 125 *
1b9d3514
MD
126 * Retrieve the contents of the page from the object pager. Note that the
127 * object pager might replace the page.
128 *
129 * If the pagein was successful, we must fully validate it so it can be
130 * memory mapped.
984263bc
MD
131 */
132
133static __inline int
1b9d3514
MD
134vm_pager_get_page(vm_object_t object, vm_page_t *m, int seqaccess)
135{
984263bc
MD
136 int r;
137
1b9d3514
MD
138 r = (*pagertab[object->type]->pgo_getpage)(object, m, seqaccess);
139 if (r == VM_PAGER_OK && (*m)->valid != VM_PAGE_BITS_ALL) {
140 vm_page_zero_invalid(*m, TRUE);
984263bc
MD
141 }
142 return(r);
143}
144
145static __inline void
146vm_pager_put_pages(
147 vm_object_t object,
148 vm_page_t *m,
149 int count,
150 int flags,
151 int *rtvals
152) {
153 (*pagertab[object->type]->pgo_putpages)
154 (object, m, count, flags, rtvals);
155}
156
157/*
158 * vm_pager_haspage
159 *
160 * Check to see if an object's pager has the requested page. The
161 * object's pager will also set before and after to give the caller
162 * some idea of the number of pages before and after the requested
163 * page can be I/O'd efficiently.
164 *
165 * This routine does not have to be called at any particular spl.
166 */
167
168static __inline boolean_t
1b9d3514
MD
169vm_pager_has_page(vm_object_t object, vm_pindex_t offset)
170{
171 return ((*pagertab[object->type]->pgo_haspage)(object, offset));
984263bc
MD
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 */
181
182static __inline void
183vm_pager_page_unswapped(vm_page_t m)
184{
185 if (pagertab[m->object->type]->pgo_pageunswapped)
186 (*pagertab[m->object->type]->pgo_pageunswapped)(m);
187}
188
189#endif
190
1bd40720 191#endif /* _VM_VM_PAGER_H_ */