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