uvm_extern.h revision 1.77
1151497Sru/*	$NetBSD: uvm_extern.h,v 1.77 2003/02/01 06:23:54 thorpej Exp $	*/
275584Sru
375584Sru/*
475584Sru *
575584Sru * Copyright (c) 1997 Charles D. Cranor and Washington University.
675584Sru * All rights reserved.
775584Sru *
875584Sru * Redistribution and use in source and binary forms, with or without
975584Sru * modification, are permitted provided that the following conditions
1075584Sru * are met:
1175584Sru * 1. Redistributions of source code must retain the above copyright
1275584Sru *    notice, this list of conditions and the following disclaimer.
1375584Sru * 2. Redistributions in binary form must reproduce the above copyright
1475584Sru *    notice, this list of conditions and the following disclaimer in the
1575584Sru *    documentation and/or other materials provided with the distribution.
1675584Sru * 3. All advertising materials mentioning features or use of this software
1775584Sru *    must display the following acknowledgement:
1875584Sru *      This product includes software developed by Charles D. Cranor and
1975584Sru *      Washington University.
2075584Sru * 4. The name of the author may not be used to endorse or promote products
2175584Sru *    derived from this software without specific prior written permission.
22104862Sru *
23104862Sru * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24104862Sru * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2575584Sru * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2675584Sru * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2775584Sru * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2875584Sru * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2975584Sru * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3075584Sru * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3175584Sru * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3275584Sru * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3375584Sru *
3475584Sru * from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp
3575584Sru */
3675584Sru
3775584Sru/*-
3875584Sru * Copyright (c) 1991, 1992, 1993
3975584Sru *	The Regents of the University of California.  All rights reserved.
4075584Sru *
4175584Sru * Redistribution and use in source and binary forms, with or without
4275584Sru * modification, are permitted provided that the following conditions
4375584Sru * are met:
4475584Sru * 1. Redistributions of source code must retain the above copyright
4575584Sru *    notice, this list of conditions and the following disclaimer.
4675584Sru * 2. Redistributions in binary form must reproduce the above copyright
4775584Sru *    notice, this list of conditions and the following disclaimer in the
4875584Sru *    documentation and/or other materials provided with the distribution.
4975584Sru * 3. All advertising materials mentioning features or use of this software
5075584Sru *    must display the following acknowledgement:
5175584Sru *	This product includes software developed by the University of
5275584Sru *	California, Berkeley and its contributors.
5375584Sru * 4. Neither the name of the University nor the names of its contributors
5475584Sru *    may be used to endorse or promote products derived from this software
5575584Sru *    without specific prior written permission.
5675584Sru *
5775584Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5875584Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5975584Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6075584Sru * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
6175584Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6275584Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
6375584Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6475584Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6575584Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6675584Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6775584Sru * SUCH DAMAGE.
6875584Sru *
6975584Sru *	@(#)vm_extern.h	8.5 (Berkeley) 5/3/95
7075584Sru */
7175584Sru
7275584Sru#ifndef _UVM_UVM_EXTERN_H_
7375584Sru#define _UVM_UVM_EXTERN_H_
7475584Sru
7575584Sru/*
7675584Sru * uvm_extern.h: this file defines the external interface to the VM system.
7775584Sru *
7875584Sru * this should be the only file included by non-VM parts of the kernel
7975584Sru * which need access to VM services.   if you want to know the interface
80104862Sru * to the MI VM layer without knowing the details, this is the file to
8175584Sru * learn.
8275584Sru *
8375584Sru * NOTE: vm system calls are prototyped in syscallargs.h
84104862Sru */
85104862Sru
86104862Sru/*
87104862Sru * typedefs, necessary for standard UVM headers.
88104862Sru */
89104862Sru
90104862Srutypedef unsigned int uvm_flag_t;
91104862Srutypedef int vm_fault_t;
9275584Sru
9375584Srutypedef int vm_inherit_t;	/* XXX: inheritance codes */
9475584Srutypedef off_t voff_t;		/* XXX: offset within a uvm_object */
9575584Sru
9675584Sru/*
9775584Sru * defines
9875584Sru */
9975584Sru
10075584Sru/*
10175584Sru * the following defines are for uvm_map and functions which call it.
10275584Sru */
10375584Sru
10475584Sru/* protections bits */
10575584Sru#define UVM_PROT_MASK	0x07	/* protection mask */
10675584Sru#define UVM_PROT_NONE	0x00	/* protection none */
10775584Sru#define UVM_PROT_ALL	0x07	/* everything */
10875584Sru#define UVM_PROT_READ	0x01	/* read */
10975584Sru#define UVM_PROT_WRITE  0x02	/* write */
11075584Sru#define UVM_PROT_EXEC	0x04	/* exec */
11175584Sru
11275584Sru/* protection short codes */
11375584Sru#define UVM_PROT_R	0x01	/* read */
11475584Sru#define UVM_PROT_W	0x02	/* write */
11575584Sru#define UVM_PROT_RW	0x03    /* read-write */
11675584Sru#define UVM_PROT_X	0x04	/* exec */
11775584Sru#define UVM_PROT_RX	0x05	/* read-exec */
11875584Sru#define UVM_PROT_WX	0x06	/* write-exec */
11975584Sru#define UVM_PROT_RWX	0x07	/* read-write-exec */
12079543Sru
12179543Sru/* 0x08: not used */
12275584Sru
12379543Sru/* inherit codes */
12479543Sru#define UVM_INH_MASK	0x30	/* inherit mask */
12579543Sru#define UVM_INH_SHARE	0x00	/* "share" */
12679543Sru#define UVM_INH_COPY	0x10	/* "copy" */
12779543Sru#define UVM_INH_NONE	0x20	/* "none" */
12879543Sru#define UVM_INH_DONATE	0x30	/* "donate" << not used */
12979543Sru
13079543Sru/* 0x40, 0x80: not used */
13179543Sru
13279543Sru/* bits 0x700: max protection, 0x800: not used */
13379543Sru
13479543Sru/* bits 0x7000: advice, 0x8000: not used */
13579543Sru/* advice: matches MADV_* from sys/mman.h */
13679543Sru#define UVM_ADV_NORMAL	0x0	/* 'normal' */
13775584Sru#define UVM_ADV_RANDOM	0x1	/* 'random' */
13875584Sru#define UVM_ADV_SEQUENTIAL 0x2	/* 'sequential' */
13979543Sru/* 0x3: will need, 0x4: dontneed */
14079543Sru#define UVM_ADV_MASK	0x7	/* mask */
14175584Sru
14279543Sru/* mapping flags */
14379543Sru#define UVM_FLAG_FIXED   0x010000 /* find space */
14479543Sru#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
14579543Sru#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
14679543Sru#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
14779543Sru#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
14879543Sru#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
14979543Sru#define UVM_FLAG_NOWAIT  0x400000 /* not allowed to sleep */
15079543Sru
151104862Sru/* macros to extract info */
152104862Sru#define UVM_PROTECTION(X)	((X) & UVM_PROT_MASK)
153104862Sru#define UVM_INHERIT(X)		(((X) & UVM_INH_MASK) >> 4)
15475584Sru#define UVM_MAXPROTECTION(X)	(((X) >> 8) & UVM_PROT_MASK)
15575584Sru#define UVM_ADVICE(X)		(((X) >> 12) & UVM_ADV_MASK)
15675584Sru
15775584Sru#define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \
15875584Sru	((MAXPROT << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS))
15975584Sru
16075584Sru/* magic offset value: offset not known(obj) or don't care(!obj) */
16175584Sru#define UVM_UNKNOWN_OFFSET ((voff_t) -1)
16275584Sru
16375584Sru/*
16475584Sru * the following defines are for uvm_km_kmemalloc's flags
16575584Sru */
16675584Sru#define UVM_KMF_VALLOC	0x1			/* allocate VA only */
16775584Sru#define UVM_KMF_CANFAIL	0x2			/* caller handles failure */
16875584Sru#define UVM_KMF_TRYLOCK	UVM_FLAG_TRYLOCK	/* try locking only */
16975584Sru#define UVM_KMF_NOWAIT	UVM_FLAG_NOWAIT		/* not allowed to sleep */
17075584Sru
17175584Sru/*
17275584Sru * the following defines the strategies for uvm_pagealloc_strat()
17375584Sru */
17475584Sru#define	UVM_PGA_STRAT_NORMAL	0	/* high -> low free list walk */
17575584Sru#define	UVM_PGA_STRAT_ONLY	1	/* only specified free list */
176104862Sru#define	UVM_PGA_STRAT_FALLBACK	2	/* ONLY falls back on NORMAL */
177104862Sru
17875584Sru/*
17975584Sru * flags for uvm_pagealloc_strat()
18075584Sru */
18175584Sru#define UVM_PGA_USERESERVE	0x0001	/* ok to use reserve pages */
18275584Sru#define	UVM_PGA_ZERO		0x0002	/* returned page must be zero'd */
18375584Sru
18475584Sru/*
18575584Sru * the following defines are for ubc_alloc's flags
18675584Sru */
18775584Sru#define UBC_READ	0x01
18875584Sru#define UBC_WRITE	0x02
18975584Sru#define UBC_FAULTBUSY	0x04
19075584Sru
19175584Sru/*
19275584Sru * flags for uvn_findpages().
19375584Sru */
19475584Sru#define UFP_ALL		0x00
19575584Sru#define UFP_NOWAIT	0x01
19675584Sru#define UFP_NOALLOC	0x02
197104862Sru#define UFP_NOCACHE	0x04
198104862Sru#define UFP_NORDONLY	0x08
199104862Sru#define UFP_DIRTYONLY	0x10
20075584Sru#define UFP_BACKWARD	0x20
20175584Sru
20275584Sru/*
20375584Sru * lockflags that control the locking behavior of various functions.
20475584Sru */
20575584Sru#define	UVM_LK_ENTER	0x00000001	/* map locked on entry */
20675584Sru#define	UVM_LK_EXIT	0x00000002	/* leave map locked on exit */
20775584Sru
20875584Sru/*
20975584Sru * structures
21075584Sru */
21175584Sru
21275584Srustruct core;
21375584Srustruct mount;
21475584Srustruct pglist;
21575584Srustruct proc;
21675584Srustruct ucred;
21775584Srustruct uio;
21875584Srustruct uvm_object;
21975584Srustruct vm_anon;
22075584Srustruct vmspace;
22175584Srustruct pmap;
22275584Srustruct vnode;
223struct pool;
224struct simplelock;
225struct vm_map_entry;
226struct vm_map;
227struct vm_page;
228
229extern struct pool *uvm_aiobuf_pool;
230
231/*
232 * uvmexp: global data structures that are exported to parts of the kernel
233 * other than the vm system.
234 */
235
236struct uvmexp {
237	/* vm_page constants */
238	int pagesize;   /* size of a page (PAGE_SIZE): must be power of 2 */
239	int pagemask;   /* page mask */
240	int pageshift;  /* page shift */
241
242	/* vm_page counters */
243	int npages;     /* number of pages we manage */
244	int free;       /* number of free pages */
245	int active;     /* number of active pages */
246	int inactive;   /* number of pages that we free'd but may want back */
247	int paging;	/* number of pages in the process of being paged out */
248	int wired;      /* number of wired pages */
249
250	/*
251	 * Adding anything before this line will break binary compatibility
252	 * with top(1) on NetBSD 1.5.
253	 */
254
255	int ncolors;	/* number of page color buckets: must be p-o-2 */
256	int colormask;	/* color bucket mask */
257
258	int zeropages;		/* number of zero'd pages */
259	int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
260	int reserve_kernel;	/* number of pages reserved for kernel */
261	int anonpages;		/* number of pages used by anon mappings */
262	int filepages;		/* number of pages used by cached file data */
263	int execpages;		/* number of pages used by cached exec date */
264
265	/* pageout params */
266	int freemin;    /* min number of free pages */
267	int freetarg;   /* target number of free pages */
268	int inactarg;   /* target number of inactive pages */
269	int wiredmax;   /* max number of wired pages */
270	int anonmin;	/* min threshold for anon pages */
271	int execmin;	/* min threshold for executable pages */
272	int filemin;	/* min threshold for file pages */
273	int anonminpct;	/* min percent anon pages */
274	int execminpct;	/* min percent executable pages */
275	int fileminpct;	/* min percent file pages */
276	int anonmax;	/* max threshold for anon pages */
277	int execmax;	/* max threshold for executable pages */
278	int filemax;	/* max threshold for file pages */
279	int anonmaxpct;	/* max percent anon pages */
280	int execmaxpct;	/* max percent executable pages */
281	int filemaxpct;	/* max percent file pages */
282
283	/* swap */
284	int nswapdev;	/* number of configured swap devices in system */
285	int swpages;	/* number of PAGE_SIZE'ed swap pages */
286	int swpginuse;	/* number of swap pages in use */
287	int swpgonly;	/* number of swap pages in use, not also in RAM */
288	int nswget;	/* number of times fault calls uvm_swap_get() */
289	int nanon;	/* number total of anon's in system */
290	int nanonneeded;/* number of anons currently needed */
291	int nfreeanon;	/* number of free anon's */
292
293	/* stat counters */
294	int faults;		/* page fault count */
295	int traps;		/* trap count */
296	int intrs;		/* interrupt count */
297	int swtch;		/* context switch count */
298	int softs;		/* software interrupt count */
299	int syscalls;		/* system calls */
300	int pageins;		/* pagein operation count */
301				/* pageouts are in pdpageouts below */
302	int swapins;		/* swapins */
303	int swapouts;		/* swapouts */
304	int pgswapin;		/* pages swapped in */
305	int pgswapout;		/* pages swapped out */
306	int forks;  		/* forks */
307	int forks_ppwait;	/* forks where parent waits */
308	int forks_sharevm;	/* forks where vmspace is shared */
309	int pga_zerohit;	/* pagealloc where zero wanted and zero
310				   was available */
311	int pga_zeromiss;	/* pagealloc where zero wanted and zero
312				   not available */
313	int zeroaborts;		/* number of times page zeroing was
314				   aborted */
315	int colorhit;		/* pagealloc where we got optimal color */
316	int colormiss;		/* pagealloc where we didn't */
317
318	/* fault subcounters */
319	int fltnoram;	/* number of times fault was out of ram */
320	int fltnoanon;	/* number of times fault was out of anons */
321	int fltpgwait;	/* number of times fault had to wait on a page */
322	int fltpgrele;	/* number of times fault found a released page */
323	int fltrelck;	/* number of times fault relock called */
324	int fltrelckok;	/* number of times fault relock is a success */
325	int fltanget;	/* number of times fault gets anon page */
326	int fltanretry;	/* number of times fault retrys an anon get */
327	int fltamcopy;	/* number of times fault clears "needs copy" */
328	int fltnamap;	/* number of times fault maps a neighbor anon page */
329	int fltnomap;	/* number of times fault maps a neighbor obj page */
330	int fltlget;	/* number of times fault does a locked pgo_get */
331	int fltget;	/* number of times fault does an unlocked get */
332	int flt_anon;	/* number of times fault anon (case 1a) */
333	int flt_acow;	/* number of times fault anon cow (case 1b) */
334	int flt_obj;	/* number of times fault is on object page (2a) */
335	int flt_prcopy;	/* number of times fault promotes with copy (2b) */
336	int flt_przero;	/* number of times fault promotes with zerofill (2b) */
337
338	/* daemon counters */
339	int pdwoke;	/* number of times daemon woke up */
340	int pdrevs;	/* number of times daemon rev'd clock hand */
341	int pdswout;	/* number of times daemon called for swapout */
342	int pdfreed;	/* number of pages daemon freed since boot */
343	int pdscans;	/* number of pages daemon scaned since boot */
344	int pdanscan;	/* number of anonymous pages scanned by daemon */
345	int pdobscan;	/* number of object pages scanned by daemon */
346	int pdreact;	/* number of pages daemon reactivated since boot */
347	int pdbusy;	/* number of times daemon found a busy page */
348	int pdpageouts;	/* number of times daemon started a pageout */
349	int pdpending;	/* number of times daemon got a pending pagout */
350	int pddeact;	/* number of pages daemon deactivates */
351	int pdreanon;	/* anon pages reactivated due to thresholds */
352	int pdrefile;	/* file pages reactivated due to thresholds */
353	int pdreexec;	/* executable pages reactivated due to thresholds */
354};
355
356/*
357 * The following structure is 64-bit alignment safe.  New elements
358 * should only be added to the end of this structure so binary
359 * compatibility can be preserved.
360 */
361struct uvmexp_sysctl {
362	int64_t	pagesize;
363	int64_t	pagemask;
364	int64_t	pageshift;
365	int64_t	npages;
366	int64_t	free;
367	int64_t	active;
368	int64_t	inactive;
369	int64_t	paging;
370	int64_t	wired;
371	int64_t	zeropages;
372	int64_t	reserve_pagedaemon;
373	int64_t	reserve_kernel;
374	int64_t	freemin;
375	int64_t	freetarg;
376	int64_t	inactarg;
377	int64_t	wiredmax;
378	int64_t	nswapdev;
379	int64_t	swpages;
380	int64_t	swpginuse;
381	int64_t	swpgonly;
382	int64_t	nswget;
383	int64_t	nanon;
384	int64_t	nanonneeded;
385	int64_t	nfreeanon;
386	int64_t	faults;
387	int64_t	traps;
388	int64_t	intrs;
389	int64_t	swtch;
390	int64_t	softs;
391	int64_t	syscalls;
392	int64_t	pageins;
393	int64_t	swapins;
394	int64_t	swapouts;
395	int64_t	pgswapin;
396	int64_t	pgswapout;
397	int64_t	forks;
398	int64_t	forks_ppwait;
399	int64_t	forks_sharevm;
400	int64_t	pga_zerohit;
401	int64_t	pga_zeromiss;
402	int64_t	zeroaborts;
403	int64_t	fltnoram;
404	int64_t	fltnoanon;
405	int64_t	fltpgwait;
406	int64_t	fltpgrele;
407	int64_t	fltrelck;
408	int64_t	fltrelckok;
409	int64_t	fltanget;
410	int64_t	fltanretry;
411	int64_t	fltamcopy;
412	int64_t	fltnamap;
413	int64_t	fltnomap;
414	int64_t	fltlget;
415	int64_t	fltget;
416	int64_t	flt_anon;
417	int64_t	flt_acow;
418	int64_t	flt_obj;
419	int64_t	flt_prcopy;
420	int64_t	flt_przero;
421	int64_t	pdwoke;
422	int64_t	pdrevs;
423	int64_t	pdswout;
424	int64_t	pdfreed;
425	int64_t	pdscans;
426	int64_t	pdanscan;
427	int64_t	pdobscan;
428	int64_t	pdreact;
429	int64_t	pdbusy;
430	int64_t	pdpageouts;
431	int64_t	pdpending;
432	int64_t	pddeact;
433	int64_t	anonpages;
434	int64_t	filepages;
435	int64_t	execpages;
436	int64_t colorhit;
437	int64_t colormiss;
438	int64_t ncolors;
439};
440
441#ifdef _KERNEL
442extern struct uvmexp uvmexp;
443#endif
444
445/*
446 * Finally, bring in standard UVM headers.
447 */
448#include <sys/vmmeter.h>
449#include <sys/queue.h>
450#include <uvm/uvm_param.h>
451#include <sys/lock.h>
452#include <uvm/uvm_prot.h>
453#include <uvm/uvm_page.h>
454#include <uvm/uvm_pmap.h>
455#include <uvm/uvm_map.h>
456#include <uvm/uvm_fault.h>
457#include <uvm/uvm_pager.h>
458
459/*
460 * Shareable process virtual address space.
461 * May eventually be merged with vm_map.
462 * Several fields are temporary (text, data stuff).
463 */
464struct vmspace {
465	struct	vm_map vm_map;	/* VM address map */
466	int	vm_refcnt;	/* number of references */
467	caddr_t	vm_shm;		/* SYS5 shared memory private data XXX */
468/* we copy from vm_startcopy to the end of the structure on fork */
469#define vm_startcopy vm_rssize
470	segsz_t vm_rssize;	/* current resident set size in pages */
471	segsz_t vm_swrss;	/* resident set size before last swap */
472	segsz_t vm_tsize;	/* text size (pages) XXX */
473	segsz_t vm_dsize;	/* data size (pages) XXX */
474	segsz_t vm_ssize;	/* stack size (pages) */
475	caddr_t	vm_taddr;	/* user virtual address of text XXX */
476	caddr_t	vm_daddr;	/* user virtual address of data XXX */
477	caddr_t vm_maxsaddr;	/* user VA at max stack growth */
478	caddr_t vm_minsaddr;	/* user VA at top of stack */
479};
480
481#ifdef _KERNEL
482
483/*
484 * used to keep state while iterating over the map for a core dump.
485 */
486struct uvm_coredump_state {
487	void *cookie;		/* opaque for the caller */
488	vaddr_t start;		/* start of region */
489	vaddr_t end;		/* end of region */
490	vm_prot_t prot;		/* protection of region */
491	int flags;		/* flags; see below */
492};
493
494#define	UVM_COREDUMP_STACK	0x01	/* region is user stack */
495#define	UVM_COREDUMP_NODUMP	0x02	/* don't actually dump this region */
496
497/*
498 * the various kernel maps, owned by MD code
499 */
500extern struct vm_map *exec_map;
501extern struct vm_map *kernel_map;
502extern struct vm_map *kmem_map;
503extern struct vm_map *mb_map;
504extern struct vm_map *phys_map;
505
506/*
507 * macros
508 */
509
510/* zalloc zeros memory, alloc does not */
511#define uvm_km_zalloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,TRUE)
512#define uvm_km_alloc(MAP,SIZE)  uvm_km_alloc1(MAP,SIZE,FALSE)
513
514#endif /* _KERNEL */
515
516#define vm_resident_count(vm) (pmap_resident_count((vm)->vm_map.pmap))
517
518struct buf;
519struct loadavg;
520struct proc;
521struct pmap;
522struct vmspace;
523struct vmtotal;
524struct mount;
525struct vnode;
526struct core;
527
528#ifdef _KERNEL
529#include <sys/mallocvar.h>
530MALLOC_DECLARE(M_VMMAP);
531MALLOC_DECLARE(M_VMPMAP);
532
533/* vm_machdep.c */
534void		vmapbuf __P((struct buf *, vsize_t));
535void		vunmapbuf __P((struct buf *, vsize_t));
536void		pagemove __P((caddr_t, caddr_t, size_t));
537#ifndef	cpu_swapin
538void		cpu_swapin __P((struct lwp *));
539#endif
540#ifndef	cpu_swapout
541void		cpu_swapout __P((struct lwp *));
542#endif
543
544/* uvm_aobj.c */
545struct uvm_object	*uao_create __P((vsize_t, int));
546void			uao_detach __P((struct uvm_object *));
547void			uao_detach_locked __P((struct uvm_object *));
548void			uao_reference __P((struct uvm_object *));
549void			uao_reference_locked __P((struct uvm_object *));
550
551/* uvm_bio.c */
552void			ubc_init __P((void));
553void *			ubc_alloc __P((struct uvm_object *, voff_t, vsize_t *,
554				       int));
555void			ubc_release __P((void *, int));
556void			ubc_flush __P((struct uvm_object *, voff_t, voff_t));
557
558/* uvm_fault.c */
559int			uvm_fault __P((struct vm_map *, vaddr_t, vm_fault_t,
560				       vm_prot_t));
561				/* handle a page fault */
562
563/* uvm_glue.c */
564#if defined(KGDB)
565void			uvm_chgkprot __P((caddr_t, size_t, int));
566#endif
567void			uvm_proc_fork __P((struct proc *, struct proc *, boolean_t));
568void			uvm_lwp_fork __P((struct lwp *, struct lwp *,
569			    void *, size_t, void (*)(void *), void *));
570int			uvm_coredump_walkmap __P((struct proc *,
571			    struct vnode *, struct ucred *,
572			    int (*)(struct proc *, struct vnode *,
573				    struct ucred *,
574				    struct uvm_coredump_state *), void *));
575void			uvm_proc_exit __P((struct proc *));
576void			uvm_lwp_exit __P((struct lwp *));
577void			uvm_init_limits __P((struct proc *));
578boolean_t		uvm_kernacc __P((caddr_t, size_t, int));
579__dead void		uvm_scheduler __P((void)) __attribute__((noreturn));
580void			uvm_swapin __P((struct lwp *));
581boolean_t		uvm_uarea_alloc(vaddr_t *);
582void			uvm_uarea_free(vaddr_t);
583boolean_t		uvm_useracc __P((caddr_t, size_t, int));
584int			uvm_vslock __P((struct proc *, caddr_t, size_t,
585			    vm_prot_t));
586void			uvm_vsunlock __P((struct proc *, caddr_t, size_t));
587
588
589/* uvm_init.c */
590void			uvm_init __P((void));
591
592/* uvm_io.c */
593int			uvm_io __P((struct vm_map *, struct uio *));
594
595/* uvm_km.c */
596vaddr_t			uvm_km_alloc1 __P((struct vm_map *, vsize_t,
597			    boolean_t));
598void			uvm_km_free __P((struct vm_map *, vaddr_t, vsize_t));
599void			uvm_km_free_wakeup __P((struct vm_map *, vaddr_t,
600			    vsize_t));
601vaddr_t			uvm_km_kmemalloc __P((struct vm_map *, struct
602			    uvm_object *, vsize_t, int));
603struct vm_map		*uvm_km_suballoc __P((struct vm_map *, vaddr_t *,
604			    vaddr_t *, vsize_t, int, boolean_t,
605			    struct vm_map *));
606vaddr_t			uvm_km_valloc __P((struct vm_map *, vsize_t));
607vaddr_t			uvm_km_valloc_align __P((struct vm_map *, vsize_t,
608			    vsize_t));
609vaddr_t			uvm_km_valloc_wait __P((struct vm_map *, vsize_t));
610vaddr_t			uvm_km_valloc_prefer_wait __P((struct vm_map *, vsize_t,
611			    voff_t));
612vaddr_t			uvm_km_alloc_poolpage1 __P((struct vm_map *,
613			    struct uvm_object *, boolean_t));
614void			uvm_km_free_poolpage1 __P((struct vm_map *, vaddr_t));
615
616#define	uvm_km_alloc_poolpage(waitok)					\
617	uvm_km_alloc_poolpage1(kmem_map, NULL, (waitok))
618#define	uvm_km_free_poolpage(addr)					\
619	uvm_km_free_poolpage1(kmem_map, (addr))
620
621/* uvm_map.c */
622int			uvm_map __P((struct vm_map *, vaddr_t *, vsize_t,
623				struct uvm_object *, voff_t, vsize_t,
624				uvm_flag_t));
625int			uvm_map_pageable __P((struct vm_map *, vaddr_t,
626				vaddr_t, boolean_t, int));
627int			uvm_map_pageable_all __P((struct vm_map *, int,
628				vsize_t));
629boolean_t		uvm_map_checkprot __P((struct vm_map *, vaddr_t,
630				vaddr_t, vm_prot_t));
631int			uvm_map_protect __P((struct vm_map *, vaddr_t,
632				vaddr_t, vm_prot_t, boolean_t));
633struct vmspace		*uvmspace_alloc __P((vaddr_t, vaddr_t));
634void			uvmspace_init __P((struct vmspace *, struct pmap *,
635				vaddr_t, vaddr_t));
636void			uvmspace_exec __P((struct lwp *, vaddr_t, vaddr_t));
637struct vmspace		*uvmspace_fork __P((struct vmspace *));
638void			uvmspace_free __P((struct vmspace *));
639void			uvmspace_share __P((struct proc *, struct proc *));
640void			uvmspace_unshare __P((struct lwp *));
641
642
643/* uvm_meter.c */
644void			uvm_meter __P((void));
645int			uvm_sysctl __P((int *, u_int, void *, size_t *,
646				void *, size_t, struct proc *));
647
648/* uvm_mmap.c */
649int			uvm_mmap __P((struct vm_map *, vaddr_t *, vsize_t,
650				vm_prot_t, vm_prot_t, int,
651				void *, voff_t, vsize_t));
652
653/* uvm_page.c */
654struct vm_page		*uvm_pagealloc_strat __P((struct uvm_object *,
655				voff_t, struct vm_anon *, int, int, int));
656#define	uvm_pagealloc(obj, off, anon, flags) \
657	    uvm_pagealloc_strat((obj), (off), (anon), (flags), \
658				UVM_PGA_STRAT_NORMAL, 0)
659void			uvm_pagerealloc __P((struct vm_page *,
660					     struct uvm_object *, voff_t));
661/* Actually, uvm_page_physload takes PF#s which need their own type */
662void			uvm_page_physload __P((paddr_t, paddr_t, paddr_t,
663			    paddr_t, int));
664void			uvm_setpagesize __P((void));
665
666/* uvm_pager.c */
667void			uvm_aio_biodone1 __P((struct buf *));
668void			uvm_aio_biodone __P((struct buf *));
669void			uvm_aio_aiodone __P((struct buf *));
670
671/* uvm_pdaemon.c */
672void			uvm_pageout __P((void *));
673void			uvm_aiodone_daemon __P((void *));
674
675/* uvm_pglist.c */
676int			uvm_pglistalloc __P((psize_t, paddr_t, paddr_t,
677			    paddr_t, paddr_t, struct pglist *, int, int));
678void			uvm_pglistfree __P((struct pglist *));
679
680/* uvm_swap.c */
681void			uvm_swap_init __P((void));
682
683/* uvm_unix.c */
684int			uvm_grow __P((struct proc *, vaddr_t));
685
686/* uvm_user.c */
687void			uvm_deallocate __P((struct vm_map *, vaddr_t, vsize_t));
688
689/* uvm_vnode.c */
690void			uvm_vnp_setsize __P((struct vnode *, voff_t));
691void			uvm_vnp_sync __P((struct mount *));
692struct uvm_object	*uvn_attach __P((void *, vm_prot_t));
693int			uvn_findpages __P((struct uvm_object *, voff_t,
694					   int *, struct vm_page **, int));
695void			uvm_vnp_zerorange __P((struct vnode *, off_t, size_t));
696
697/* kern_malloc.c */
698void			kmeminit_nkmempages __P((void));
699void			kmeminit __P((void));
700extern int		nkmempages;
701
702#endif /* _KERNEL */
703
704#endif /* _UVM_UVM_EXTERN_H_ */
705