Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1991 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * The Mach Operating System project at Carnegie-Mellon University. | |
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 the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
35 | * | |
1284e777 | 36 | * from: @(#)vm_page.h 7.3 (Berkeley) 4/21/91 |
a200ca2b | 37 | * $Id: vm_page.h,v 1.7 1994/01/14 16:27:27 davidg Exp $ |
1284e777 RG |
38 | */ |
39 | ||
40 | /* | |
15637ed4 RG |
41 | * Copyright (c) 1987, 1990 Carnegie-Mellon University. |
42 | * All rights reserved. | |
43 | * | |
44 | * Authors: Avadis Tevanian, Jr., Michael Wayne Young | |
45 | * | |
46 | * Permission to use, copy, modify and distribute this software and | |
47 | * its documentation is hereby granted, provided that both the copyright | |
48 | * notice and this permission notice appear in all copies of the | |
49 | * software, derivative works or modified versions, and any portions | |
50 | * thereof, and that both notices appear in supporting documentation. | |
51 | * | |
52 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
53 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND | |
54 | * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
55 | * | |
56 | * Carnegie Mellon requests users of this software to return to | |
57 | * | |
58 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
59 | * School of Computer Science | |
60 | * Carnegie Mellon University | |
61 | * Pittsburgh PA 15213-3890 | |
62 | * | |
63 | * any improvements or extensions that they make and grant Carnegie the | |
64 | * rights to redistribute these changes. | |
65 | */ | |
66 | ||
67 | /* | |
68 | * Resident memory system definitions. | |
69 | */ | |
70 | ||
71 | #ifndef _VM_PAGE_ | |
72 | #define _VM_PAGE_ | |
73 | ||
74 | /* | |
75 | * Management of resident (logical) pages. | |
76 | * | |
77 | * A small structure is kept for each resident | |
78 | * page, indexed by page number. Each structure | |
79 | * is an element of several lists: | |
80 | * | |
81 | * A hash table bucket used to quickly | |
82 | * perform object/offset lookups | |
83 | * | |
84 | * A list of all pages for a given object, | |
85 | * so they can be quickly deactivated at | |
86 | * time of deallocation. | |
87 | * | |
88 | * An ordered list of pages due for pageout. | |
89 | * | |
90 | * In addition, the structure contains the object | |
91 | * and offset to which this page belongs (for pageout), | |
92 | * and sundry status bits. | |
93 | * | |
94 | * Fields in this structure are locked either by the lock on the | |
95 | * object that the page belongs to (O) or by the lock on the page | |
96 | * queues (P). | |
97 | */ | |
98 | ||
fd76afd7 DG |
99 | #define PG_INACTIVE 0x0001 |
100 | #define PG_ACTIVE 0x0002 | |
101 | #define PG_LAUNDRY 0x0004 | |
102 | #define PG_CLEAN 0x0008 | |
103 | #define PG_BUSY 0x0010 | |
104 | #define PG_WANTED 0x0020 | |
105 | #define PG_TABLED 0x0040 | |
106 | #define PG_COPY_ON_WRITE 0x0080 | |
107 | #define PG_FICTITIOUS 0x0100 | |
108 | #define PG_ABSENT 0x0200 | |
109 | #define PG_FAKE 0x0400 | |
110 | #define PG_PAGEROWNED 0x0800 | |
111 | #define PG_PTPAGE 0x1000 | |
112 | ||
15637ed4 | 113 | struct vm_page { |
fd76afd7 DG |
114 | queue_chain_t pageq; /* queue info for FIFO */ |
115 | /* queue or free list (P) */ | |
15637ed4 RG |
116 | queue_chain_t hashq; /* hash table links (O)*/ |
117 | queue_chain_t listq; /* all pages in same object (O)*/ | |
118 | ||
119 | vm_object_t object; /* which object am I in (O,P)*/ | |
120 | vm_offset_t offset; /* offset into that object (O,P) */ | |
121 | ||
fd76afd7 | 122 | unsigned int wire_count; /* how many wired down maps use me? */ |
55768178 DG |
123 | unsigned short flags; /* bit encoded flags */ |
124 | unsigned short deact; /* deactivation count */ | |
15637ed4 RG |
125 | |
126 | vm_offset_t phys_addr; /* physical address of page */ | |
15637ed4 RG |
127 | }; |
128 | ||
129 | typedef struct vm_page *vm_page_t; | |
130 | ||
a200ca2b DG |
131 | #define DEACT_START 5 |
132 | #define DEACT_DELAY 2 | |
133 | #define DEACT_CLEAN 1 | |
134 | #define DEACT_FREE 0 | |
135 | ||
15637ed4 RG |
136 | #if VM_PAGE_DEBUG |
137 | #define VM_PAGE_CHECK(mem) { \ | |
55768178 | 138 | if ((((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \ |
15637ed4 | 139 | (((unsigned int) mem) > ((unsigned int) &vm_page_array[last_page-first_page])) || \ |
fd76afd7 | 140 | ((mem->flags & PG_ACTIVE) && (mem->flags & PG_INACTIVE)) \ |
15637ed4 RG |
141 | ) panic("vm_page_check: not valid!"); \ |
142 | } | |
bbc3f849 | 143 | #else /* VM_PAGE_DEBUG */ |
15637ed4 | 144 | #define VM_PAGE_CHECK(mem) |
bbc3f849 | 145 | #endif /* VM_PAGE_DEBUG */ |
15637ed4 RG |
146 | |
147 | #ifdef KERNEL | |
148 | /* | |
149 | * Each pageable resident page falls into one of three lists: | |
150 | * | |
151 | * free | |
152 | * Available for allocation now. | |
153 | * inactive | |
154 | * Not referenced in any map, but still has an | |
155 | * object/offset-page mapping, and may be dirty. | |
156 | * This is the list of pages that should be | |
157 | * paged out next. | |
158 | * active | |
159 | * A list of pages which have been placed in | |
160 | * at least one physical map. This list is | |
161 | * ordered, in LRU-like fashion. | |
162 | */ | |
163 | ||
164 | extern | |
165 | queue_head_t vm_page_queue_free; /* memory free queue */ | |
166 | extern | |
167 | queue_head_t vm_page_queue_active; /* active memory queue */ | |
168 | extern | |
169 | queue_head_t vm_page_queue_inactive; /* inactive memory queue */ | |
170 | ||
171 | extern | |
172 | vm_page_t vm_page_array; /* First resident page in table */ | |
173 | extern | |
174 | long first_page; /* first physical page number */ | |
175 | /* ... represented in vm_page_array */ | |
176 | extern | |
177 | long last_page; /* last physical page number */ | |
178 | /* ... represented in vm_page_array */ | |
179 | /* [INCLUSIVE] */ | |
180 | extern | |
181 | vm_offset_t first_phys_addr; /* physical address for first_page */ | |
182 | extern | |
183 | vm_offset_t last_phys_addr; /* physical address for last_page */ | |
184 | ||
185 | extern | |
186 | int vm_page_free_count; /* How many pages are free? */ | |
187 | extern | |
188 | int vm_page_active_count; /* How many pages are active? */ | |
189 | extern | |
190 | int vm_page_inactive_count; /* How many pages are inactive? */ | |
191 | extern | |
192 | int vm_page_wire_count; /* How many pages are wired? */ | |
193 | extern | |
194 | int vm_page_free_target; /* How many do we want free? */ | |
195 | extern | |
196 | int vm_page_free_min; /* When to wakeup pageout */ | |
197 | extern | |
198 | int vm_page_inactive_target;/* How many do we want inactive? */ | |
199 | extern | |
200 | int vm_page_free_reserved; /* How many pages reserved to do pageout */ | |
201 | extern | |
202 | int vm_page_laundry_count; /* How many pages being laundered? */ | |
203 | ||
204 | #define VM_PAGE_TO_PHYS(entry) ((entry)->phys_addr) | |
205 | ||
206 | #define IS_VM_PHYSADDR(pa) \ | |
207 | ((pa) >= first_phys_addr && (pa) <= last_phys_addr) | |
208 | ||
209 | #define PHYS_TO_VM_PAGE(pa) \ | |
210 | (&vm_page_array[atop(pa) - first_page ]) | |
211 | ||
212 | extern | |
213 | simple_lock_data_t vm_page_queue_lock; /* lock on active and inactive | |
214 | page queues */ | |
215 | extern | |
216 | simple_lock_data_t vm_page_queue_free_lock; | |
217 | /* lock on free page queue */ | |
218 | vm_offset_t vm_page_startup(); | |
219 | vm_page_t vm_page_lookup(); | |
220 | vm_page_t vm_page_alloc(); | |
15637ed4 RG |
221 | void vm_page_free(); |
222 | void vm_page_activate(); | |
223 | void vm_page_deactivate(); | |
224 | void vm_page_rename(); | |
225 | void vm_page_replace(); | |
226 | ||
227 | boolean_t vm_page_zero_fill(); | |
228 | void vm_page_copy(); | |
229 | ||
230 | void vm_page_wire(); | |
231 | void vm_page_unwire(); | |
232 | ||
15637ed4 RG |
233 | |
234 | /* | |
235 | * Functions implemented as macros | |
236 | */ | |
237 | ||
238 | #define PAGE_ASSERT_WAIT(m, interruptible) { \ | |
fd76afd7 | 239 | (m)->flags |= PG_WANTED; \ |
15637ed4 RG |
240 | assert_wait((int) (m), (interruptible)); \ |
241 | } | |
242 | ||
243 | #define PAGE_WAKEUP(m) { \ | |
fd76afd7 DG |
244 | (m)->flags &= ~PG_BUSY; \ |
245 | if ((m)->flags & PG_WANTED) { \ | |
246 | (m)->flags &= ~PG_WANTED; \ | |
15637ed4 RG |
247 | thread_wakeup((int) (m)); \ |
248 | } \ | |
249 | } | |
250 | ||
251 | #define vm_page_lock_queues() simple_lock(&vm_page_queue_lock) | |
252 | #define vm_page_unlock_queues() simple_unlock(&vm_page_queue_lock) | |
253 | ||
fd76afd7 | 254 | #define vm_page_set_modified(m) { (m)->flags &= ~PG_CLEAN; } |
fde1aeb2 GW |
255 | |
256 | /* Some pmap things are declared here for the convenience of other bits of | |
257 | code. */ | |
258 | extern void pmap_bootstrap(vm_offset_t, vm_offset_t); | |
259 | extern void pmap_init(vm_offset_t, vm_offset_t); | |
260 | extern vm_offset_t pmap_map(vm_offset_t, vm_offset_t, vm_offset_t, int); | |
261 | extern void pmap_remove_all(vm_offset_t); | |
262 | extern void pmap_copy_on_write(vm_offset_t); | |
263 | extern void pmap_page_protect(vm_offset_t, vm_prot_t); | |
264 | extern void pmap_update(void); | |
265 | extern void pmap_zero_page(vm_offset_t); | |
266 | extern void pmap_copy_page(vm_offset_t, vm_offset_t); | |
267 | extern void pmap_clear_modify(vm_offset_t); | |
268 | extern void pmap_clear_reference(vm_offset_t); | |
269 | extern boolean_t pmap_is_referenced(vm_offset_t); | |
270 | extern boolean_t pmap_is_modified(vm_offset_t); | |
271 | extern vm_offset_t pmap_phys_ddress(int); | |
fde1aeb2 | 272 | |
55768178 DG |
273 | |
274 | /* | |
275 | * these macros are *MUCH* faster on a 386/486 type machine | |
276 | * eventually they need to be implemented correctly and put | |
277 | * somewhere in the machine dependant stuff. | |
278 | */ | |
279 | #define vm_disable_intr() (disable_intr(), 0) | |
280 | #define vm_set_intr(spl) enable_intr() | |
281 | ||
bbc3f849 GW |
282 | #endif /* KERNEL */ |
283 | #endif /* _VM_PAGE_ */ |