uvm_extern.h revision 1.23.2.1.2.7 1 /* $NetBSD: uvm_extern.h,v 1.23.2.1.2.7 1999/08/09 00:05:55 chs 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 #ifndef _UVM_UVM_EXTERN_H_
38 #define _UVM_UVM_EXTERN_H_
39
40 /*
41 * uvm_extern.h: this file defines the external interface to the VM system.
42 *
43 * this should be the only file included by non-VM parts of the kernel
44 * which need access to VM services. if you want to know the interface
45 * to the MI VM layer without knowing the details, this is the file to
46 * learn.
47 *
48 * NOTE: vm system calls are prototyped in syscallargs.h
49 */
50
51 /*
52 * types
53 */
54
55 /* byte offset within a uvm_object */
56 typedef off_t voff_t;
57
58 /*
59 * defines
60 */
61
62 /*
63 * the following defines are for uvm_map and functions which call it.
64 */
65
66 /* protections bits */
67 #define UVM_PROT_MASK 0x07 /* protection mask */
68 #define UVM_PROT_NONE 0x00 /* protection none */
69 #define UVM_PROT_ALL 0x07 /* everything */
70 #define UVM_PROT_READ 0x01 /* read */
71 #define UVM_PROT_WRITE 0x02 /* write */
72 #define UVM_PROT_EXEC 0x04 /* exec */
73
74 /* protection short codes */
75 #define UVM_PROT_R 0x01 /* read */
76 #define UVM_PROT_W 0x02 /* write */
77 #define UVM_PROT_RW 0x03 /* read-write */
78 #define UVM_PROT_X 0x04 /* exec */
79 #define UVM_PROT_RX 0x05 /* read-exec */
80 #define UVM_PROT_WX 0x06 /* write-exec */
81 #define UVM_PROT_RWX 0x07 /* read-write-exec */
82
83 /* 0x08: not used */
84
85 /* inherit codes */
86 #define UVM_INH_MASK 0x30 /* inherit mask */
87 #define UVM_INH_SHARE 0x00 /* "share" */
88 #define UVM_INH_COPY 0x10 /* "copy" */
89 #define UVM_INH_NONE 0x20 /* "none" */
90 #define UVM_INH_DONATE 0x30 /* "donate" << not used */
91
92 /* 0x40, 0x80: not used */
93
94 /* bits 0x700: max protection, 0x800: not used */
95
96 /* bits 0x7000: advice, 0x8000: not used */
97 /* advice: matches MADV_* from sys/mman.h */
98 #define UVM_ADV_NORMAL 0x0 /* 'normal' */
99 #define UVM_ADV_RANDOM 0x1 /* 'random' */
100 #define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */
101 /* 0x3: will need, 0x4: dontneed */
102 #define UVM_ADV_MASK 0x7 /* mask */
103
104 /* mapping flags */
105 #define UVM_FLAG_FIXED 0x010000 /* find space */
106 #define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
107 #define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
108 #define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
109 #define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
110 #define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
111
112 /* macros to extract info */
113 #define UVM_PROTECTION(X) ((X) & UVM_PROT_MASK)
114 #define UVM_INHERIT(X) (((X) & UVM_INH_MASK) >> 4)
115 #define UVM_MAXPROTECTION(X) (((X) >> 8) & UVM_PROT_MASK)
116 #define UVM_ADVICE(X) (((X) >> 12) & UVM_ADV_MASK)
117
118 #define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \
119 ((MAXPROT << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS))
120
121 /* magic offset value */
122 #define UVM_UNKNOWN_OFFSET ((vaddr_t) -1)
123 /* offset not known(obj) or don't care(!obj) */
124
125 /*
126 * the following defines are for uvm_km_kmemalloc's flags
127 */
128 #define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */
129 #define UVM_KMF_VALLOC 0x2 /* allocate VA only */
130 #define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
131
132 /*
133 * the following defines the strategies for uvm_pagealloc_strat()
134 */
135 #define UVM_PGA_STRAT_NORMAL 0 /* high -> low free list walk */
136 #define UVM_PGA_STRAT_ONLY 1 /* only specified free list */
137 #define UVM_PGA_STRAT_FALLBACK 2 /* ONLY falls back on NORMAL */
138
139 /*
140 * flags for uvm_pagealloc_strat()
141 */
142 #define UVM_PGA_USERESERVE 0x0001
143
144 /*
145 * the following defines are for ubc_alloc's flags
146 */
147 #define UBC_READ 0
148 #define UBC_WRITE 1
149
150 /*
151 * flags for uvn_findpages().
152 */
153 #define UFP_ALL 0x0
154 #define UFP_NOWAIT 0x1
155 #define UFP_NOALLOC 0x2
156 #define UFP_NOCACHE 0x4
157 #define UFP_NORDONLY 0x8
158
159 /*
160 * lockflags that control the locking behavior of various functions.
161 */
162 #define UVM_LK_ENTER 0x00000001 /* map locked on entry */
163 #define UVM_LK_EXIT 0x00000002 /* leave map locked on exit */
164
165 /*
166 * structures
167 */
168
169 struct core;
170 struct mount;
171 struct pglist;
172 struct proc;
173 struct ucred;
174 struct uio;
175 struct uvm_object;
176 struct vm_anon;
177 struct vmspace;
178 struct pmap;
179 struct vnode;
180 struct uvm_aiodesc;
181 struct pool;
182 struct simplelock;
183
184 extern struct pool *uvm_aiobuf_pool;
185
186 /*
187 * uvmexp: global data structures that are exported to parts of the kernel
188 * other than the vm system.
189 */
190
191 struct uvmexp {
192 /* vm_page constants */
193 int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */
194 int pagemask; /* page mask */
195 int pageshift; /* page shift */
196
197 /* vm_page counters */
198 int npages; /* number of pages we manage */
199 int free; /* number of free pages */
200 int active; /* number of active pages */
201 int inactive; /* number of pages that we free'd but may want back */
202 int paging; /* number of pages in the process of being paged out */
203 int wired; /* number of wired pages */
204 int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
205 int reserve_kernel; /* number of pages reserved for kernel */
206
207 /* pageout params */
208 int freemin; /* min number of free pages */
209 int freetarg; /* target number of free pages */
210 int inactarg; /* target number of inactive pages */
211 int wiredmax; /* max number of wired pages */
212
213 /* swap */
214 int nswapdev; /* number of configured swap devices in system */
215 int swpages; /* number of PAGE_SIZE'ed swap pages */
216 int swpguniq; /* number of swap pages in use, not also in RAM */
217 int swpginuse; /* number of swap pages in use */
218 int swpgonly; /* number of swap pages in use, not also in RAM */
219 int nswget; /* number of times fault calls uvm_swap_get() */
220 int nanon; /* number total of anon's in system */
221 int nanonneeded;/* number of anons currently needed */
222 int nfreeanon; /* number of free anon's */
223
224 /* stat counters */
225 int faults; /* page fault count */
226 int traps; /* trap count */
227 int intrs; /* interrupt count */
228 int swtch; /* context switch count */
229 int softs; /* software interrupt count */
230 int syscalls; /* system calls */
231 int pageins; /* pagein operation count */
232 /* pageouts are in pdpageouts below */
233 int swapins; /* swapins */
234 int swapouts; /* swapouts */
235 int pgswapin; /* pages swapped in */
236 int pgswapout; /* pages swapped out */
237 int forks; /* forks */
238 int forks_ppwait; /* forks where parent waits */
239 int forks_sharevm; /* forks where vmspace is shared */
240
241 /* fault subcounters */
242 int fltnoram; /* number of times fault was out of ram */
243 int fltnoanon; /* number of times fault was out of anons */
244 int fltpgwait; /* number of times fault had to wait on a page */
245 int fltpgrele; /* number of times fault found a released page */
246 int fltrelck; /* number of times fault relock called */
247 int fltrelckok; /* number of times fault relock is a success */
248 int fltanget; /* number of times fault gets anon page */
249 int fltanretry; /* number of times fault retrys an anon get */
250 int fltamcopy; /* number of times fault clears "needs copy" */
251 int fltnamap; /* number of times fault maps a neighbor anon page */
252 int fltnomap; /* number of times fault maps a neighbor obj page */
253 int fltlget; /* number of times fault does a locked pgo_get */
254 int fltget; /* number of times fault does an unlocked get */
255 int flt_anon; /* number of times fault anon (case 1a) */
256 int flt_acow; /* number of times fault anon cow (case 1b) */
257 int flt_obj; /* number of times fault is on object page (2a) */
258 int flt_prcopy; /* number of times fault promotes with copy (2b) */
259 int flt_przero; /* number of times fault promotes with zerofill (2b) */
260
261 /* daemon counters */
262 int pdwoke; /* number of times daemon woke up */
263 int pdrevs; /* number of times daemon rev'd clock hand */
264 int pdswout; /* number of times daemon called for swapout */
265 int pdfreed; /* number of pages daemon freed since boot */
266 int pdscans; /* number of pages daemon scaned since boot */
267 int pdanscan; /* number of anonymous pages scanned by daemon */
268 int pdobscan; /* number of object pages scanned by daemon */
269 int pdreact; /* number of pages daemon reactivated since boot */
270 int pdbusy; /* number of times daemon found a busy page */
271 int pdpageouts; /* number of times daemon started a pageout */
272 int pdpending; /* number of times daemon got a pending pagout */
273 int pddeact; /* number of pages daemon deactivates */
274
275 /* kernel memory objects: managed by uvm_km_kmemalloc() only! */
276 struct uvm_object *kmem_object;
277 struct uvm_object *mb_object;
278 };
279
280 #ifdef _KERNEL
281
282 extern struct uvmexp uvmexp;
283
284 /*
285 * macros
286 */
287
288 /* zalloc zeros memory, alloc does not */
289 #define uvm_km_zalloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,TRUE)
290 #define uvm_km_alloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,FALSE)
291
292 #endif /* _KERNEL */
293
294 /*
295 * typedefs
296 */
297
298 typedef unsigned int uvm_flag_t;
299 typedef int vm_fault_t;
300
301 #ifdef _KERNEL
302
303 /* uvm_aobj.c */
304 struct uvm_object *uao_create __P((vsize_t, int));
305 void uao_detach __P((struct uvm_object *));
306 void uao_detach_locked __P((struct uvm_object *));
307 void uao_reference __P((struct uvm_object *));
308 void uao_reference_locked __P((struct uvm_object *));
309
310 /* uvm_bio.c */
311 void * ubc_alloc __P((struct uvm_object *, voff_t, vsize_t *,
312 int));
313 void ubc_release __P((void *, vsize_t));
314 void ubc_flush __P((struct uvm_object *, voff_t, voff_t));
315
316 /* uvm_fault.c */
317 int uvm_fault __P((vm_map_t, vaddr_t, vm_fault_t,
318 vm_prot_t));
319 /* handle a page fault */
320
321 /* uvm_glue.c */
322 #if defined(KGDB)
323 void uvm_chgkprot __P((caddr_t, size_t, int));
324 #endif
325 void uvm_sleep __P((void *, struct simplelock *, boolean_t,
326 const char *, int));
327 void uvm_fork __P((struct proc *, struct proc *, boolean_t,
328 void *, size_t));
329 void uvm_exit __P((struct proc *));
330 void uvm_init_limits __P((struct proc *));
331 boolean_t uvm_kernacc __P((caddr_t, size_t, int));
332 __dead void uvm_scheduler __P((void)) __attribute__((noreturn));
333 void uvm_swapin __P((struct proc *));
334 boolean_t uvm_useracc __P((caddr_t, size_t, int));
335 int uvm_vslock __P((struct proc *, caddr_t, size_t,
336 vm_prot_t));
337 void uvm_vsunlock __P((struct proc *, caddr_t, size_t));
338
339
340 /* uvm_init.c */
341 void uvm_init __P((void));
342 /* init the uvm system */
343
344 /* uvm_io.c */
345 int uvm_io __P((vm_map_t, struct uio *));
346
347 /* uvm_km.c */
348 vaddr_t uvm_km_alloc1 __P((vm_map_t, vsize_t, boolean_t));
349 void uvm_km_free __P((vm_map_t, vaddr_t, vsize_t));
350 void uvm_km_free_wakeup __P((vm_map_t, vaddr_t,
351 vsize_t));
352 vaddr_t uvm_km_kmemalloc __P((vm_map_t, struct uvm_object *,
353 vsize_t, int));
354 struct vm_map *uvm_km_suballoc __P((vm_map_t, vaddr_t *,
355 vaddr_t *, vsize_t, int,
356 boolean_t, vm_map_t));
357 vaddr_t uvm_km_valloc __P((vm_map_t, vsize_t));
358 vaddr_t uvm_km_valloc_wait __P((vm_map_t, vsize_t));
359 vaddr_t uvm_km_alloc_poolpage1 __P((vm_map_t,
360 struct uvm_object *, boolean_t));
361 void uvm_km_free_poolpage1 __P((vm_map_t, vaddr_t));
362
363 #define uvm_km_alloc_poolpage(waitok) uvm_km_alloc_poolpage1(kmem_map, \
364 uvmexp.kmem_object, (waitok))
365 #define uvm_km_free_poolpage(addr) uvm_km_free_poolpage1(kmem_map, (addr))
366
367 /* uvm_map.c */
368 int uvm_map __P((vm_map_t, vaddr_t *, vsize_t,
369 struct uvm_object *, voff_t, uvm_flag_t));
370 int uvm_map_pageable __P((vm_map_t, vaddr_t,
371 vaddr_t, boolean_t, int));
372 int uvm_map_pageable_all __P((vm_map_t, int, vsize_t));
373 boolean_t uvm_map_checkprot __P((vm_map_t, vaddr_t,
374 vaddr_t, vm_prot_t));
375 int uvm_map_protect __P((vm_map_t, vaddr_t,
376 vaddr_t, vm_prot_t, boolean_t));
377 struct vmspace *uvmspace_alloc __P((vaddr_t, vaddr_t,
378 boolean_t));
379 void uvmspace_init __P((struct vmspace *, struct pmap *,
380 vaddr_t, vaddr_t, boolean_t));
381 void uvmspace_exec __P((struct proc *));
382 struct vmspace *uvmspace_fork __P((struct vmspace *));
383 void uvmspace_free __P((struct vmspace *));
384 void uvmspace_share __P((struct proc *, struct proc *));
385 void uvmspace_unshare __P((struct proc *));
386
387
388 /* uvm_meter.c */
389 void uvm_meter __P((void));
390 int uvm_sysctl __P((int *, u_int, void *, size_t *,
391 void *, size_t, struct proc *));
392
393 /* uvm_mmap.c */
394 int uvm_mmap __P((vm_map_t, vaddr_t *, vsize_t,
395 vm_prot_t, vm_prot_t, int,
396 caddr_t, voff_t, vsize_t));
397
398 /* uvm_page.c */
399 struct vm_page *uvm_pagealloc_strat __P((struct uvm_object *,
400 voff_t, struct vm_anon *, int, int, int));
401 #define uvm_pagealloc(obj, off, anon, flags) \
402 uvm_pagealloc_strat((obj), (off), (anon), (flags), \
403 UVM_PGA_STRAT_NORMAL, 0)
404 void uvm_pagerealloc __P((struct vm_page *,
405 struct uvm_object *, voff_t));
406 /* Actually, uvm_page_physload takes PF#s which need their own type */
407 void uvm_page_physload __P((vaddr_t, vaddr_t,
408 vaddr_t, vaddr_t, int));
409 void uvm_setpagesize __P((void));
410
411 /* uvm_pager.c */
412 void uvm_aio_biodone1 __P((struct buf *));
413 void uvm_aio_biodone __P((struct buf *));
414 void uvm_aio_aiodone __P((struct buf *));
415
416 /* uvm_pdaemon.c */
417 void uvm_pageout __P((void));
418 void uvm_aiodone_daemon __P((void));
419
420 /* uvm_pglist.c */
421 int uvm_pglistalloc __P((psize_t, paddr_t,
422 paddr_t, paddr_t, paddr_t,
423 struct pglist *, int, int));
424 void uvm_pglistfree __P((struct pglist *));
425
426 /* uvm_swap.c */
427 void uvm_swap_init __P((void));
428
429 /* uvm_unix.c */
430 int uvm_coredump __P((struct proc *, struct vnode *,
431 struct ucred *, struct core *));
432 int uvm_grow __P((struct proc *, vaddr_t));
433
434 /* uvm_user.c */
435 int uvm_deallocate __P((vm_map_t, vaddr_t, vsize_t));
436
437 /* uvm_vnode.c */
438 void uvm_vnp_setsize __P((struct vnode *, voff_t));
439 void uvm_vnp_sync __P((struct mount *));
440 void uvm_vnp_terminate __P((struct vnode *));
441 struct uvm_object *uvn_attach __P((void *, vm_prot_t));
442 void uvn_findpages __P((struct uvm_object *, voff_t,
443 int *, struct vm_page **, int));
444 void uvm_vnp_zerorange __P((struct vnode *, off_t, size_t));
445 void uvm_vnp_asyncget __P((struct vnode *, off_t, size_t));
446
447 #endif /* _KERNEL */
448
449 #endif /* _UVM_UVM_EXTERN_H_ */
450