xref: /netbsd-src/sys/uvm/uvm.h (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: uvm.h,v 1.63 2012/02/02 19:43:08 tls Exp $	*/
2 
3 /*
4  * Copyright (c) 1997 Charles D. Cranor and Washington University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
28  */
29 
30 #ifndef _UVM_UVM_H_
31 #define _UVM_UVM_H_
32 
33 #if defined(_KERNEL_OPT)
34 #include "opt_lockdebug.h"
35 #include "opt_multiprocessor.h"
36 #include "opt_uvmhist.h"
37 #include "opt_uvm_page_trkown.h"
38 #endif
39 
40 #include <uvm/uvm_extern.h>
41 
42 #ifdef _KERNEL
43 #include <uvm/uvm_stat.h>
44 #endif
45 
46 /*
47  * pull in prototypes
48  */
49 
50 #include <uvm/uvm_amap.h>
51 #include <uvm/uvm_aobj.h>
52 #include <uvm/uvm_fault.h>
53 #include <uvm/uvm_glue.h>
54 #include <uvm/uvm_km.h>
55 #include <uvm/uvm_loan.h>
56 #include <uvm/uvm_map.h>
57 #include <uvm/uvm_object.h>
58 #include <uvm/uvm_page.h>
59 #include <uvm/uvm_pager.h>
60 #include <uvm/uvm_pdaemon.h>
61 #include <uvm/uvm_swap.h>
62 #include <sys/rnd.h>
63 
64 #ifdef _KERNEL
65 
66 /*
67  * pull in VM_NFREELIST
68  */
69 #include <machine/vmparam.h>
70 
71 struct workqueue;
72 
73 /*
74  * per-cpu data
75  */
76 
77 struct uvm_cpu {
78 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
79 	int page_free_nextcolor;	/* next color to allocate from */
80 	int page_idlezero_next;		/* which color to zero next */
81 	bool page_idle_zero;		/* TRUE if we should try to zero
82 					   pages in the idle loop */
83 	int pages[PGFL_NQUEUES];	/* total of pages in page_free */
84 	u_int emap_gen;			/* emap generation number */
85 
86 	uintptr_t last_fltaddr;		/* last faulted address */
87 	uintptr_t last_delta;		/* difference of last two flt addrs */
88 	uintptr_t last_delta2;		/* difference of differences */
89 	krndsource_t rs;		/* entropy source */
90 };
91 
92 /*
93  * uvm structure (vm global state: collected in one structure for ease
94  * of reference...)
95  */
96 
97 struct uvm {
98 	/* vm_page related parameters */
99 
100 		/* vm_page queues */
101 	struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
102 	bool page_init_done;		/* TRUE if uvm_page_init() finished */
103 
104 		/* page daemon trigger */
105 	int pagedaemon;			/* daemon sleeps on this */
106 	struct lwp *pagedaemon_lwp;	/* daemon's lid */
107 
108 		/* aiodone daemon */
109 	struct workqueue *aiodone_queue;
110 
111 	/* aio_done is locked by uvm.pagedaemon_lock and splbio! */
112 	TAILQ_HEAD(, buf) aio_done;		/* done async i/o reqs */
113 
114 	/* per-cpu data */
115 	struct uvm_cpu *cpus[MAXCPUS];
116 };
117 
118 /*
119  * kernel object: to support anonymous pageable kernel memory
120  */
121 extern struct uvm_object *uvm_kernel_object;
122 
123 /*
124  * locks (made globals for lockstat).
125  */
126 
127 extern kmutex_t uvm_pageqlock;		/* lock for active/inactive page q */
128 extern kmutex_t uvm_fpageqlock;		/* lock for free page q */
129 extern kmutex_t uvm_kentry_lock;
130 extern kmutex_t uvm_swap_data_lock;
131 
132 #endif /* _KERNEL */
133 
134 /*
135  * vm_map_entry etype bits:
136  */
137 
138 #define UVM_ET_OBJ		0x01	/* it is a uvm_object */
139 #define UVM_ET_SUBMAP		0x02	/* it is a vm_map submap */
140 #define UVM_ET_COPYONWRITE 	0x04	/* copy_on_write */
141 #define UVM_ET_NEEDSCOPY	0x08	/* needs_copy */
142 
143 #define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
144 #define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
145 #define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
146 #define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
147 
148 #ifdef _KERNEL
149 
150 /*
151  * holds all the internal UVM data
152  */
153 extern struct uvm uvm;
154 
155 /*
156  * historys
157  */
158 
159 #ifdef UVMHIST
160 UVMHIST_DECL(maphist);
161 UVMHIST_DECL(pdhist);
162 UVMHIST_DECL(ubchist);
163 UVMHIST_DECL(loanhist);
164 #endif
165 
166 extern struct evcnt uvm_ra_total;
167 extern struct evcnt uvm_ra_hit;
168 extern struct evcnt uvm_ra_miss;
169 
170 /*
171  * UVM_UNLOCK_AND_WAIT: atomic unlock+wait... wrapper around the
172  * interlocked tsleep() function.
173  */
174 
175 #define	UVM_UNLOCK_AND_WAIT(event, slock, intr, msg, timo)		\
176 do {									\
177 	(void) mtsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0),	\
178 	    msg, timo, slock);						\
179 } while (/*CONSTCOND*/ 0)
180 
181 void uvm_kick_pdaemon(void);
182 
183 /*
184  * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
185  */
186 
187 #if defined(UVM_PAGE_TRKOWN)
188 #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
189 #else
190 #define UVM_PAGE_OWN(PG, TAG) /* nothing */
191 #endif /* UVM_PAGE_TRKOWN */
192 
193 #include <uvm/uvm_fault_i.h>
194 
195 #endif /* _KERNEL */
196 
197 #endif /* _UVM_UVM_H_ */
198