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