uvm_extern.h revision 1.44 1 /* $NetBSD: uvm_extern.h,v 1.44 2000/06/27 09:00:14 mrg Exp $ */
2
3 /*
4 *
5 * Copyright (c) 1997 Charles D. Cranor and Washington University.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles D. Cranor and
19 * Washington University.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp
35 */
36
37 /*-
38 * Copyright (c) 1992, 1993
39 * The Regents of the University of California. All rights reserved.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the University of
52 * California, Berkeley and its contributors.
53 * 4. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * SUCH DAMAGE.
68 *
69 * @(#)vm_extern.h 8.5 (Berkeley) 5/3/95
70 */
71
72 #ifndef _UVM_UVM_EXTERN_H_
73 #define _UVM_UVM_EXTERN_H_
74
75 /*
76 * uvm_extern.h: this file defines the external interface to the VM system.
77 *
78 * this should be the only file included by non-VM parts of the kernel
79 * which need access to VM services. if you want to know the interface
80 * to the MI VM layer without knowing the details, this is the file to
81 * learn.
82 *
83 * NOTE: vm system calls are prototyped in syscallargs.h
84 */
85
86 /*
87 * defines
88 */
89
90 /*
91 * the following defines are for uvm_map and functions which call it.
92 */
93
94 /* protections bits */
95 #define UVM_PROT_MASK 0x07 /* protection mask */
96 #define UVM_PROT_NONE 0x00 /* protection none */
97 #define UVM_PROT_ALL 0x07 /* everything */
98 #define UVM_PROT_READ 0x01 /* read */
99 #define UVM_PROT_WRITE 0x02 /* write */
100 #define UVM_PROT_EXEC 0x04 /* exec */
101
102 /* protection short codes */
103 #define UVM_PROT_R 0x01 /* read */
104 #define UVM_PROT_W 0x02 /* write */
105 #define UVM_PROT_RW 0x03 /* read-write */
106 #define UVM_PROT_X 0x04 /* exec */
107 #define UVM_PROT_RX 0x05 /* read-exec */
108 #define UVM_PROT_WX 0x06 /* write-exec */
109 #define UVM_PROT_RWX 0x07 /* read-write-exec */
110
111 /* 0x08: not used */
112
113 /* inherit codes */
114 #define UVM_INH_MASK 0x30 /* inherit mask */
115 #define UVM_INH_SHARE 0x00 /* "share" */
116 #define UVM_INH_COPY 0x10 /* "copy" */
117 #define UVM_INH_NONE 0x20 /* "none" */
118 #define UVM_INH_DONATE 0x30 /* "donate" << not used */
119
120 /* 0x40, 0x80: not used */
121
122 /* bits 0x700: max protection, 0x800: not used */
123
124 /* bits 0x7000: advice, 0x8000: not used */
125 /* advice: matches MADV_* from sys/mman.h */
126 #define UVM_ADV_NORMAL 0x0 /* 'normal' */
127 #define UVM_ADV_RANDOM 0x1 /* 'random' */
128 #define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */
129 /* 0x3: will need, 0x4: dontneed */
130 #define UVM_ADV_MASK 0x7 /* mask */
131
132 /* mapping flags */
133 #define UVM_FLAG_FIXED 0x010000 /* find space */
134 #define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
135 #define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
136 #define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
137 #define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
138 #define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
139
140 /* macros to extract info */
141 #define UVM_PROTECTION(X) ((X) & UVM_PROT_MASK)
142 #define UVM_INHERIT(X) (((X) & UVM_INH_MASK) >> 4)
143 #define UVM_MAXPROTECTION(X) (((X) >> 8) & UVM_PROT_MASK)
144 #define UVM_ADVICE(X) (((X) >> 12) & UVM_ADV_MASK)
145
146 #define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \
147 ((MAXPROT << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS))
148
149 /* magic offset value */
150 #define UVM_UNKNOWN_OFFSET ((voff_t) -1)
151 /* offset not known(obj) or don't care(!obj) */
152
153 /*
154 * the following defines are for uvm_km_kmemalloc's flags
155 */
156 #define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */
157 #define UVM_KMF_VALLOC 0x2 /* allocate VA only */
158 #define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
159
160 /*
161 * the following defines the strategies for uvm_pagealloc_strat()
162 */
163 #define UVM_PGA_STRAT_NORMAL 0 /* high -> low free list walk */
164 #define UVM_PGA_STRAT_ONLY 1 /* only specified free list */
165 #define UVM_PGA_STRAT_FALLBACK 2 /* ONLY falls back on NORMAL */
166
167 /*
168 * flags for uvm_pagealloc_strat()
169 */
170 #define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */
171 #define UVM_PGA_ZERO 0x0002 /* returned page must be zero'd */
172
173 /*
174 * lockflags that control the locking behavior of various functions.
175 */
176 #define UVM_LK_ENTER 0x00000001 /* map locked on entry */
177 #define UVM_LK_EXIT 0x00000002 /* leave map locked on exit */
178
179 /*
180 * structures
181 */
182
183 struct core;
184 struct mount;
185 struct pglist;
186 struct proc;
187 struct ucred;
188 struct uio;
189 struct uvm_object;
190 struct vm_anon;
191 struct vmspace;
192 struct pmap;
193 struct vnode;
194 struct simplelock;
195
196 /*
197 * uvmexp: global data structures that are exported to parts of the kernel
198 * other than the vm system.
199 */
200
201 struct uvmexp {
202 /* vm_page constants */
203 int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */
204 int pagemask; /* page mask */
205 int pageshift; /* page shift */
206
207 /* vm_page counters */
208 int npages; /* number of pages we manage */
209 int free; /* number of free pages */
210 int active; /* number of active pages */
211 int inactive; /* number of pages that we free'd but may want back */
212 int paging; /* number of pages in the process of being paged out */
213 int wired; /* number of wired pages */
214 int zeropages; /* number of zero'd pages */
215 int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
216 int reserve_kernel; /* number of pages reserved for kernel */
217
218 /* pageout params */
219 int freemin; /* min number of free pages */
220 int freetarg; /* target number of free pages */
221 int inactarg; /* target number of inactive pages */
222 int wiredmax; /* max number of wired pages */
223
224 /* swap */
225 int nswapdev; /* number of configured swap devices in system */
226 int swpages; /* number of PAGE_SIZE'ed swap pages */
227 int swpguniq; /* number of swap pages in use, not also in RAM */
228 int swpginuse; /* number of swap pages in use */
229 int swpgonly; /* number of swap pages in use, not also in RAM */
230 int nswget; /* number of times fault calls uvm_swap_get() */
231 int nanon; /* number total of anon's in system */
232 int nanonneeded;/* number of anons currently needed */
233 int nfreeanon; /* number of free anon's */
234
235 /* stat counters */
236 int faults; /* page fault count */
237 int traps; /* trap count */
238 int intrs; /* interrupt count */
239 int swtch; /* context switch count */
240 int softs; /* software interrupt count */
241 int syscalls; /* system calls */
242 int pageins; /* pagein operation count */
243 /* pageouts are in pdpageouts below */
244 int swapins; /* swapins */
245 int swapouts; /* swapouts */
246 int pgswapin; /* pages swapped in */
247 int pgswapout; /* pages swapped out */
248 int forks; /* forks */
249 int forks_ppwait; /* forks where parent waits */
250 int forks_sharevm; /* forks where vmspace is shared */
251 int pga_zerohit; /* pagealloc where zero wanted and zero
252 was available */
253 int pga_zeromiss; /* pagealloc where zero wanted and zero
254 not available */
255
256 /* fault subcounters */
257 int fltnoram; /* number of times fault was out of ram */
258 int fltnoanon; /* number of times fault was out of anons */
259 int fltpgwait; /* number of times fault had to wait on a page */
260 int fltpgrele; /* number of times fault found a released page */
261 int fltrelck; /* number of times fault relock called */
262 int fltrelckok; /* number of times fault relock is a success */
263 int fltanget; /* number of times fault gets anon page */
264 int fltanretry; /* number of times fault retrys an anon get */
265 int fltamcopy; /* number of times fault clears "needs copy" */
266 int fltnamap; /* number of times fault maps a neighbor anon page */
267 int fltnomap; /* number of times fault maps a neighbor obj page */
268 int fltlget; /* number of times fault does a locked pgo_get */
269 int fltget; /* number of times fault does an unlocked get */
270 int flt_anon; /* number of times fault anon (case 1a) */
271 int flt_acow; /* number of times fault anon cow (case 1b) */
272 int flt_obj; /* number of times fault is on object page (2a) */
273 int flt_prcopy; /* number of times fault promotes with copy (2b) */
274 int flt_przero; /* number of times fault promotes with zerofill (2b) */
275
276 /* daemon counters */
277 int pdwoke; /* number of times daemon woke up */
278 int pdrevs; /* number of times daemon rev'd clock hand */
279 int pdswout; /* number of times daemon called for swapout */
280 int pdfreed; /* number of pages daemon freed since boot */
281 int pdscans; /* number of pages daemon scaned since boot */
282 int pdanscan; /* number of anonymous pages scanned by daemon */
283 int pdobscan; /* number of object pages scanned by daemon */
284 int pdreact; /* number of pages daemon reactivated since boot */
285 int pdbusy; /* number of times daemon found a busy page */
286 int pdpageouts; /* number of times daemon started a pageout */
287 int pdpending; /* number of times daemon got a pending pagout */
288 int pddeact; /* number of pages daemon deactivates */
289
290 /* kernel memory objects: managed by uvm_km_kmemalloc() only! */
291 struct uvm_object *kmem_object;
292 struct uvm_object *mb_object;
293 };
294
295 #ifdef _KERNEL
296
297 extern struct uvmexp uvmexp;
298
299 /*
300 * the various kernel maps, owned by MD code
301 */
302 extern vm_map_t exec_map;
303 extern vm_map_t kernel_map;
304 extern vm_map_t kmem_map;
305 extern vm_map_t mb_map;
306 extern vm_map_t phys_map;
307
308 /*
309 * macros
310 */
311
312 /* zalloc zeros memory, alloc does not */
313 #define uvm_km_zalloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,TRUE)
314 #define uvm_km_alloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,FALSE)
315
316 #endif /* _KERNEL */
317
318 /*
319 * typedefs
320 */
321
322 typedef unsigned int uvm_flag_t;
323 typedef int vm_fault_t;
324
325 /* XXX clean up later */
326 struct buf;
327 struct loadavg;
328 struct proc;
329 struct pmap;
330 struct vmspace;
331 struct vmtotal;
332 struct mount;
333 struct vnode;
334 struct core;
335
336 #ifdef _KERNEL
337
338 /* vm_machdep.c */
339 void vmapbuf __P((struct buf *, vsize_t));
340 void vunmapbuf __P((struct buf *, vsize_t));
341 void pagemove __P((caddr_t, caddr_t, size_t));
342 #ifndef cpu_swapin
343 void cpu_swapin __P((struct proc *));
344 #endif
345 #ifndef cpu_swapout
346 void cpu_swapout __P((struct proc *));
347 #endif
348
349 /* uvm_aobj.c */
350 struct uvm_object *uao_create __P((vsize_t, int));
351 void uao_detach __P((struct uvm_object *));
352 void uao_detach_locked __P((struct uvm_object *));
353 void uao_reference __P((struct uvm_object *));
354 void uao_reference_locked __P((struct uvm_object *));
355
356 /* uvm_fault.c */
357 int uvm_fault __P((vm_map_t, vaddr_t,
358 vm_fault_t, vm_prot_t));
359 /* handle a page fault */
360
361 /* uvm_glue.c */
362 #if defined(KGDB)
363 void uvm_chgkprot __P((caddr_t, size_t, int));
364 #endif
365 void uvm_fork __P((struct proc *, struct proc *, boolean_t,
366 void *, size_t, void (*)(void *), void *));
367 void uvm_exit __P((struct proc *));
368 void uvm_init_limits __P((struct proc *));
369 boolean_t uvm_kernacc __P((caddr_t, size_t, int));
370 __dead void uvm_scheduler __P((void)) __attribute__((noreturn));
371 void uvm_swapin __P((struct proc *));
372 boolean_t uvm_useracc __P((caddr_t, size_t, int));
373 int uvm_vslock __P((struct proc *, caddr_t, size_t,
374 vm_prot_t));
375 void uvm_vsunlock __P((struct proc *, caddr_t, size_t));
376
377
378 /* uvm_init.c */
379 void uvm_init __P((void));
380 /* init the uvm system */
381
382 /* uvm_io.c */
383 int uvm_io __P((vm_map_t, struct uio *));
384
385 /* uvm_km.c */
386 vaddr_t uvm_km_alloc1 __P((vm_map_t, vsize_t, boolean_t));
387 void uvm_km_free __P((vm_map_t, vaddr_t, vsize_t));
388 void uvm_km_free_wakeup __P((vm_map_t, vaddr_t,
389 vsize_t));
390 vaddr_t uvm_km_kmemalloc __P((vm_map_t, struct uvm_object *,
391 vsize_t, int));
392 struct vm_map *uvm_km_suballoc __P((vm_map_t, vaddr_t *,
393 vaddr_t *, vsize_t, int,
394 boolean_t, vm_map_t));
395 vaddr_t uvm_km_valloc __P((vm_map_t, vsize_t));
396 vaddr_t uvm_km_valloc_wait __P((vm_map_t, vsize_t));
397 vaddr_t uvm_km_alloc_poolpage1 __P((vm_map_t,
398 struct uvm_object *, boolean_t));
399 void uvm_km_free_poolpage1 __P((vm_map_t, vaddr_t));
400
401 #define uvm_km_alloc_poolpage(waitok) uvm_km_alloc_poolpage1(kmem_map, \
402 uvmexp.kmem_object, (waitok))
403 #define uvm_km_free_poolpage(addr) uvm_km_free_poolpage1(kmem_map, (addr))
404
405 /* uvm_map.c */
406 int uvm_map __P((vm_map_t, vaddr_t *, vsize_t,
407 struct uvm_object *, voff_t, uvm_flag_t));
408 int uvm_map_pageable __P((vm_map_t, vaddr_t,
409 vaddr_t, boolean_t, int));
410 int uvm_map_pageable_all __P((vm_map_t, int, vsize_t));
411 boolean_t uvm_map_checkprot __P((vm_map_t, vaddr_t,
412 vaddr_t, vm_prot_t));
413 int uvm_map_protect __P((vm_map_t, vaddr_t,
414 vaddr_t, vm_prot_t, boolean_t));
415 struct vmspace *uvmspace_alloc __P((vaddr_t, vaddr_t,
416 boolean_t));
417 void uvmspace_init __P((struct vmspace *, struct pmap *,
418 vaddr_t, vaddr_t, boolean_t));
419 void uvmspace_exec __P((struct proc *));
420 struct vmspace *uvmspace_fork __P((struct vmspace *));
421 void uvmspace_free __P((struct vmspace *));
422 void uvmspace_share __P((struct proc *, struct proc *));
423 void uvmspace_unshare __P((struct proc *));
424
425
426 /* uvm_meter.c */
427 void uvm_meter __P((void));
428 int uvm_sysctl __P((int *, u_int, void *, size_t *,
429 void *, size_t, struct proc *));
430
431 /* uvm_mmap.c */
432 int uvm_mmap __P((vm_map_t, vaddr_t *, vsize_t,
433 vm_prot_t, vm_prot_t, int,
434 caddr_t, voff_t, vsize_t));
435
436 /* uvm_page.c */
437 struct vm_page *uvm_pagealloc_strat __P((struct uvm_object *,
438 voff_t, struct vm_anon *, int, int, int));
439 #define uvm_pagealloc(obj, off, anon, flags) \
440 uvm_pagealloc_strat((obj), (off), (anon), (flags), \
441 UVM_PGA_STRAT_NORMAL, 0)
442 void uvm_pagerealloc __P((struct vm_page *,
443 struct uvm_object *, voff_t));
444 /* Actually, uvm_page_physload takes PF#s which need their own type */
445 void uvm_page_physload __P((paddr_t, paddr_t,
446 paddr_t, paddr_t, int));
447 void uvm_setpagesize __P((void));
448
449 /* uvm_pdaemon.c */
450 void uvm_pageout __P((void));
451
452 /* uvm_pglist.c */
453 int uvm_pglistalloc __P((psize_t, paddr_t,
454 paddr_t, paddr_t, paddr_t,
455 struct pglist *, int, int));
456 void uvm_pglistfree __P((struct pglist *));
457
458 /* uvm_swap.c */
459 void uvm_swap_init __P((void));
460
461 /* uvm_unix.c */
462 int uvm_coredump __P((struct proc *, struct vnode *,
463 struct ucred *, struct core *));
464 int uvm_grow __P((struct proc *, vaddr_t));
465 /* should only be needed if COMPAT_NETBSD32 is defined */
466 struct core32;
467 int uvm_coredump32 __P((struct proc *, struct vnode *,
468 struct ucred *, struct core32 *));
469
470 /* uvm_user.c */
471 int uvm_deallocate __P((vm_map_t, vaddr_t, vsize_t));
472
473 /* uvm_vnode.c */
474 void uvm_vnp_setsize __P((struct vnode *, voff_t));
475 void uvm_vnp_sync __P((struct mount *));
476 void uvm_vnp_terminate __P((struct vnode *));
477 /* terminate a uvm/uvn object */
478 boolean_t uvm_vnp_uncache __P((struct vnode *));
479 struct uvm_object *uvn_attach __P((void *, vm_prot_t));
480
481 /* kern_malloc.c */
482 void kmeminit_nkmempages __P((void));
483 void kmeminit __P((void));
484 extern int nkmempages;
485
486 #endif /* _KERNEL */
487
488 #endif /* _UVM_UVM_EXTERN_H_ */
489