uvm_extern.h revision 1.1 1 /* $Id: uvm_extern.h,v 1.1 1998/02/05 06:25:10 mrg Exp $ */
2
3 /*
4 * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE!
5 * >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<<
6 */
7 /*
8 *
9 * Copyright (c) 1997 Charles D. Cranor and Washington University.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Charles D. Cranor and
23 * Washington University.
24 * 4. The name of the author may not be used to endorse or promote products
25 * derived from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef UVM_UVM_EXTERN_H
40 #define UVM_UVM_EXTERN_H
41
42 /*
43 * uvm_extern.h: this file defines the external interface to the VM system.
44 *
45 * this should be the only file included by non-VM parts of the kernel
46 * which need access to VM services. if you want to know the interface
47 * to the MI VM layer without knowing the details, this is the file to
48 * learn.
49 *
50 * NOTE: vm system calls are prototyped in syscallargs.h
51 */
52
53 /*
54 * defines
55 */
56
57 /*
58 * the following defines are for uvm_map and functions which call it.
59 */
60
61 /* protections bits */
62 #define UVM_PROT_MASK 0x07 /* protection mask */
63 #define UVM_PROT_NONE 0x00 /* protection none */
64 #define UVM_PROT_ALL 0x07 /* everything */
65 #define UVM_PROT_READ 0x01 /* read */
66 #define UVM_PROT_WRITE 0x02 /* write */
67 #define UVM_PROT_EXEC 0x04 /* exec */
68
69 /* protection short codes */
70 #define UVM_PROT_R 0x01 /* read */
71 #define UVM_PROT_W 0x02 /* write */
72 #define UVM_PROT_RW 0x03 /* read-write */
73 #define UVM_PROT_X 0x04 /* exec */
74 #define UVM_PROT_RX 0x05 /* read-exec */
75 #define UVM_PROT_WX 0x06 /* write-exec */
76 #define UVM_PROT_RWX 0x07 /* read-write-exec */
77
78 /* 0x08: not used */
79
80 /* inherit codes */
81 #define UVM_INH_MASK 0x30 /* inherit mask */
82 #define UVM_INH_SHARE 0x00 /* "share" */
83 #define UVM_INH_COPY 0x10 /* "copy" */
84 #define UVM_INH_NONE 0x20 /* "none" */
85 #define UVM_INH_DONATE 0x30 /* "donate" << not used */
86
87 /* 0x40, 0x80: not used */
88
89 /* bits 0x700: max protection, 0x800: not used */
90
91 /* bits 0x7000: advice, 0x8000: not used */
92 /* advice: matches MADV_* from sys/mman.h */
93 #define UVM_ADV_NORMAL 0x0 /* 'normal' */
94 #define UVM_ADV_RANDOM 0x1 /* 'random' */
95 #define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */
96 /* 0x3: will need, 0x4: dontneed */
97 #define UVM_ADV_MASK 0x7 /* mask */
98
99 /* mapping flags */
100 #define UVM_FLAG_FIXED 0x010000 /* find space */
101 #define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
102 #define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
103 #define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
104 #define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
105 #define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
106
107 /* macros to extract info */
108 #define UVM_PROTECTION(X) ((X) & UVM_PROT_MASK)
109 #define UVM_INHERIT(X) (((X) & UVM_INH_MASK) >> 4)
110 #define UVM_MAXPROTECTION(X) (((X) >> 8) & UVM_PROT_MASK)
111 #define UVM_ADVICE(X) (((X) >> 12) & UVM_ADV_MASK)
112
113 #define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \
114 ((MAXPROT << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS))
115
116 /* magic offset value */
117 #define UVM_UNKNOWN_OFFSET ((vm_offset_t) -1)
118 /* offset not known(obj) or don't care(!obj) */
119
120 /*
121 * the following defines are for uvm_km_kmemalloc's flags
122 */
123
124 #define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */
125 #define UVM_KMF_VALLOC 0x2 /* allocate VA only */
126 #define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
127
128 /*
129 * structures
130 */
131
132 struct core;
133 struct mount;
134 struct pglist;
135 struct proc;
136 struct ucred;
137 struct uio;
138 struct uvm_object;
139 struct vm_anon;
140 struct vmspace;
141 struct vnode;
142
143 /*
144 * uvmexp: global data structures that are exported to parts of the kernel
145 * other than the vm system.
146 */
147
148 struct uvmexp {
149 /* vm_page constants */
150 int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */
151 int pagemask; /* page mask */
152 int pageshift; /* page shift */
153
154 /* vm_page counters */
155 int npages; /* number of pages we manage */
156 int free; /* number of free pages */
157 int active; /* number of active pages */
158 int inactive; /* number of pages that we free'd but may want back */
159 int wired; /* number of wired pages */
160
161 /* pageout params */
162 int freemin; /* min number of free pages */
163 int freetarg; /* target number of free pages */
164 int inactarg; /* target number of inactive pages */
165 int wiredmax; /* max number of wired pages */
166
167 /* swap */
168 int nswapdev; /* number of configured swap devices in system */
169 int swpages; /* number of PAGE_SIZE'ed swap pages */
170 int swpginuse; /* swap pages in use */
171 int nswget; /* number of times fault calls uvm_swap_get() */
172 int nanon; /* number total of anon's in system */
173 int nfreeanon; /* number of free anon's */
174
175 /* stat counters */
176 int faults; /* page fault count */
177 int traps; /* trap count */
178 int intrs; /* interrupt count */
179 int swtch; /* context switch count */
180 int softs; /* software interrupt count */
181 int syscalls; /* system calls */
182 int swapins; /* swapins */
183 int swapouts; /* swapouts */
184 int forks; /* forks */
185 int forks_ppwait; /* forks where parent waits */
186 int forks_sharevm; /* forks where vmspace is shared */
187
188
189 /* fault subcounters */
190 int fltnoram; /* number of times fault was out of ram */
191 int fltnoanon; /* number of times fault was out of anons */
192 int fltpgwait; /* number of times fault had to wait on a page */
193 int fltpgrele; /* number of times fault found a released page */
194 int fltrelck; /* number of times fault relock called */
195 int fltrelckok; /* number of times fault relock is a success */
196 int fltanget; /* number of times fault gets anon page */
197 int fltanretry; /* number of times fault retrys an anon get */
198 int fltamcopy; /* number of times fault clears "needs copy" */
199 int fltnamap; /* number of times fault maps a neighbor anon page */
200 int fltnomap; /* number of times fault maps a neighbor obj page */
201 int fltlget; /* number of times fault does a locked pgo_get */
202 int fltget; /* number of times fault does an unlocked get */
203 int flt_anon; /* number of times fault anon (case 1a) */
204 int flt_acow; /* number of times fault anon cow (case 1b) */
205 int flt_obj; /* number of times fault is on object page (2a) */
206 int flt_prcopy; /* number of times fault promotes with copy (2b) */
207 int flt_przero; /* number of times fault promotes with zerofill (2b) */
208
209 /* daemon counters */
210 int pdwoke; /* number of times daemon woke up */
211 int pdrevs; /* number of times daemon rev'd clock hand */
212 int pdswout; /* number of times daemon called for swapout */
213 int pdfreed; /* number of pages daemon freed since boot */
214 int pdscans; /* number of pages daemon scaned since boot */
215 int pdanscan; /* number of anonymous pages scanned by daemon */
216 int pdobscan; /* number of object pages scanned by daemon */
217 int pdreact; /* number of pages daemon reactivated since boot */
218 int pdbusy; /* number of times daemon found a busy page */
219 int pdpageouts; /* number of times daemon started a pageout */
220 int pdpending; /* number of times daemon got a pending pagout */
221 int pddeact; /* number of pages daemon deactivates */
222
223 /* kernel memory objects: managed by uvm_km_kmemalloc() only! */
224 struct uvm_object *kmem_object;
225 struct uvm_object *mb_object;
226 };
227
228
229 extern struct uvmexp uvmexp;
230
231 /*
232 * macros
233 */
234
235 /* zalloc zeros memory, alloc does not */
236 #define uvm_km_zalloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,TRUE)
237 #define uvm_km_alloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,FALSE)
238
239 /*
240 * typedefs
241 */
242
243 typedef unsigned int uvm_flag_t;
244 typedef int vm_fault_t;
245
246 /* uvm_aobj.c */
247 struct uvm_object *uao_create __P((vm_size_t, int));
248 void uao_detach __P((struct uvm_object *));
249 void uao_reference __P((struct uvm_object *));
250
251 /* uvm_fault.c */
252 int uvm_fault __P((vm_map_t, vm_offset_t,
253 vm_fault_t, vm_prot_t));
254 /* handle a page fault */
255
256 /* uvm_glue.c */
257 #if defined(KGDB)
258 void uvm_chgkprot __P((caddr_t, int, int));
259 #endif
260 void uvm_fork __P((struct proc *, struct proc *, boolean_t));
261 void uvm_init_limits __P((struct proc *));
262 boolean_t uvm_kernacc __P((caddr_t, int, int));
263 void uvm_scheduler __P((void));
264 void uvm_swapin __P((struct proc *));
265 boolean_t uvm_useracc __P((caddr_t, int, int));
266 void uvm_vslock __P((caddr_t, u_int));
267 void uvm_vsunlock __P((caddr_t, u_int));
268
269
270 /* uvm_init.c */
271 void uvm_init __P((void));
272 /* init the uvm system */
273
274 /* uvm_io.c */
275 int uvm_io __P((vm_map_t, struct uio *));
276
277 /* uvm_km.c */
278 vm_offset_t uvm_km_alloc1 __P((vm_map_t, vm_size_t, boolean_t));
279 void uvm_km_free __P((vm_map_t, vm_offset_t, vm_size_t));
280 void uvm_km_free_wakeup __P((vm_map_t, vm_offset_t,
281 vm_size_t));
282 vm_offset_t uvm_km_kmemalloc __P((vm_map_t, struct uvm_object *,
283 vm_size_t, int));
284 struct vm_map *uvm_km_suballoc __P((vm_map_t, vm_offset_t *,
285 vm_offset_t *, vm_size_t, boolean_t,
286 vm_map_t));
287 vm_offset_t uvm_km_valloc __P((vm_map_t, vm_size_t));
288 vm_offset_t uvm_km_valloc_wait __P((vm_map_t, vm_size_t));
289
290
291 /* uvm_map.c */
292 int uvm_map __P((vm_map_t, vm_offset_t *, vm_size_t,
293 struct uvm_object *, vm_offset_t, uvm_flag_t));
294 int uvm_map_pageable __P((vm_map_t, vm_offset_t,
295 vm_offset_t, boolean_t));
296 #if defined(DDB)
297 void uvm_map_print __P((vm_map_t, boolean_t));
298 void uvm_map_printit __P((vm_map_t, boolean_t,
299 void (*) __P((const char *, ...))));
300 #endif
301 int uvm_map_protect __P((vm_map_t, vm_offset_t,
302 vm_offset_t, vm_prot_t, boolean_t));
303 #if defined(DDB)
304 void uvm_object_print __P((struct uvm_object *, boolean_t));
305 void uvm_object_printit __P((struct uvm_object *, boolean_t,
306 void (*) __P((const char *, ...))));
307 void uvm_page_print __P((struct vm_page *, boolean_t));
308 void uvm_page_printit __P((struct vm_page *, boolean_t,
309 void (*) __P((const char *, ...))));
310 #endif
311 struct vmspace *uvmspace_alloc __P((vm_offset_t, vm_offset_t, int));
312 void uvmspace_exec __P((struct proc *));
313 struct vmspace *uvmspace_fork __P((struct vmspace *));
314 void uvmspace_free __P((struct vmspace *));
315 void uvmspace_share __P((struct proc *, struct proc *));
316 void uvmspace_unshare __P((struct proc *));
317
318
319 /* uvm_meter.c */
320 void uvm_meter __P((void));
321 int uvm_sysctl __P((int *, u_int, void *, size_t *,
322 void *, size_t, struct proc *));
323
324 /* uvm_mmap.c */
325 int uvm_mmap __P((vm_map_t, vm_offset_t *, vm_size_t,
326 vm_prot_t, vm_prot_t, int,
327 caddr_t, vm_offset_t));
328
329 /* uvm_page.c */
330 struct vm_page *uvm_pagealloc __P((struct uvm_object *, vm_offset_t,
331 struct vm_anon *));
332 void uvm_pagerealloc __P((struct vm_page *,
333 struct uvm_object *, vm_offset_t));
334 void uvm_page_physload __P((vm_offset_t, vm_offset_t,
335 vm_offset_t, vm_offset_t));
336 void uvm_setpagesize __P((void));
337
338 /* uvm_pdaemon.c */
339 void uvm_pageout __P((void));
340
341 /* uvm_pglist.c */
342 int uvm_pglistalloc __P((vm_size_t, vm_offset_t,
343 vm_offset_t, vm_offset_t, vm_offset_t,
344 struct pglist *, int, int));
345 void uvm_pglistfree __P((struct pglist *));
346
347 /* uvm_swap.c */
348 void uvm_swap_init __P((void));
349
350 /* uvm_unix.c */
351 int uvm_coredump __P((struct proc *, struct vnode *,
352 struct ucred *, struct core *));
353 int uvm_grow __P((struct proc *, vm_offset_t));
354
355 /* uvm_user.c */
356 int uvm_deallocate __P((vm_map_t, vm_offset_t, vm_size_t));
357
358 /* uvm_vnode.c */
359 void uvm_vnp_setsize __P((struct vnode *, u_quad_t));
360 void uvm_vnp_sync __P((struct mount *));
361 void uvm_vnp_terminate __P((struct vnode *));
362 /* terminate a uvm/uvn object */
363 boolean_t uvm_vnp_uncache __P((struct vnode *));
364 struct uvm_object *uvn_attach __P((void *, vm_prot_t));
365
366 #endif
367