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