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 | * | |
78ed81a3 | 36 | * from: @(#)vm_page.h 7.3 (Berkeley) 4/21/91 |
37 | * $Id$ | |
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 | ||
99 | struct vm_page { | |
100 | queue_chain_t pageq; /* queue info for FIFO | |
101 | * queue or free list (P) */ | |
102 | queue_chain_t hashq; /* hash table links (O)*/ | |
103 | queue_chain_t listq; /* all pages in same object (O)*/ | |
104 | ||
105 | vm_object_t object; /* which object am I in (O,P)*/ | |
106 | vm_offset_t offset; /* offset into that object (O,P) */ | |
107 | ||
108 | unsigned int wire_count:16, /* how many wired down maps use me? | |
109 | (P) */ | |
110 | /* boolean_t */ inactive:1, /* page is in inactive list (P) */ | |
111 | active:1, /* page is in active list (P) */ | |
112 | laundry:1, /* page is being cleaned now (P)*/ | |
113 | #ifdef DEBUG | |
114 | pagerowned:1, /* async paging op in progress */ | |
115 | ptpage:1, /* is a user page table page */ | |
116 | #endif | |
117 | :0; /* (force to 'long' boundary) */ | |
118 | #ifdef ns32000 | |
119 | int pad; /* extra space for ns32000 bit ops */ | |
120 | #endif ns32000 | |
121 | boolean_t clean; /* page has not been modified */ | |
122 | unsigned int | |
123 | /* boolean_t */ busy:1, /* page is in transit (O) */ | |
124 | wanted:1, /* someone is waiting for page (O) */ | |
125 | tabled:1, /* page is in VP table (O) */ | |
126 | copy_on_write:1,/* page must be copied before being | |
127 | changed (O) */ | |
128 | fictitious:1, /* physical page doesn't exist (O) */ | |
129 | absent:1, /* virtual page doesn't exist (O) */ | |
130 | fake:1, /* page is a placeholder for page-in | |
131 | (O) */ | |
132 | :0; | |
133 | ||
134 | vm_offset_t phys_addr; /* physical address of page */ | |
135 | vm_prot_t page_lock; /* Uses prohibited by data manager */ | |
136 | vm_prot_t unlock_request; /* Outstanding unlock request */ | |
137 | }; | |
138 | ||
139 | typedef struct vm_page *vm_page_t; | |
140 | ||
141 | #if VM_PAGE_DEBUG | |
142 | #define VM_PAGE_CHECK(mem) { \ | |
143 | if ( (((unsigned int) mem) < ((unsigned int) &vm_page_array[0])) || \ | |
144 | (((unsigned int) mem) > ((unsigned int) &vm_page_array[last_page-first_page])) || \ | |
145 | (mem->active && mem->inactive) \ | |
146 | ) panic("vm_page_check: not valid!"); \ | |
147 | } | |
148 | #else VM_PAGE_DEBUG | |
149 | #define VM_PAGE_CHECK(mem) | |
150 | #endif VM_PAGE_DEBUG | |
151 | ||
152 | #ifdef KERNEL | |
153 | /* | |
154 | * Each pageable resident page falls into one of three lists: | |
155 | * | |
156 | * free | |
157 | * Available for allocation now. | |
158 | * inactive | |
159 | * Not referenced in any map, but still has an | |
160 | * object/offset-page mapping, and may be dirty. | |
161 | * This is the list of pages that should be | |
162 | * paged out next. | |
163 | * active | |
164 | * A list of pages which have been placed in | |
165 | * at least one physical map. This list is | |
166 | * ordered, in LRU-like fashion. | |
167 | */ | |
168 | ||
169 | extern | |
170 | queue_head_t vm_page_queue_free; /* memory free queue */ | |
171 | extern | |
172 | queue_head_t vm_page_queue_active; /* active memory queue */ | |
173 | extern | |
174 | queue_head_t vm_page_queue_inactive; /* inactive memory queue */ | |
175 | ||
176 | extern | |
177 | vm_page_t vm_page_array; /* First resident page in table */ | |
178 | extern | |
179 | long first_page; /* first physical page number */ | |
180 | /* ... represented in vm_page_array */ | |
181 | extern | |
182 | long last_page; /* last physical page number */ | |
183 | /* ... represented in vm_page_array */ | |
184 | /* [INCLUSIVE] */ | |
185 | extern | |
186 | vm_offset_t first_phys_addr; /* physical address for first_page */ | |
187 | extern | |
188 | vm_offset_t last_phys_addr; /* physical address for last_page */ | |
189 | ||
190 | extern | |
191 | int vm_page_free_count; /* How many pages are free? */ | |
192 | extern | |
193 | int vm_page_active_count; /* How many pages are active? */ | |
194 | extern | |
195 | int vm_page_inactive_count; /* How many pages are inactive? */ | |
196 | extern | |
197 | int vm_page_wire_count; /* How many pages are wired? */ | |
198 | extern | |
199 | int vm_page_free_target; /* How many do we want free? */ | |
200 | extern | |
201 | int vm_page_free_min; /* When to wakeup pageout */ | |
202 | extern | |
203 | int vm_page_inactive_target;/* How many do we want inactive? */ | |
204 | extern | |
205 | int vm_page_free_reserved; /* How many pages reserved to do pageout */ | |
206 | extern | |
207 | int vm_page_laundry_count; /* How many pages being laundered? */ | |
208 | ||
209 | #define VM_PAGE_TO_PHYS(entry) ((entry)->phys_addr) | |
210 | ||
211 | #define IS_VM_PHYSADDR(pa) \ | |
212 | ((pa) >= first_phys_addr && (pa) <= last_phys_addr) | |
213 | ||
214 | #define PHYS_TO_VM_PAGE(pa) \ | |
215 | (&vm_page_array[atop(pa) - first_page ]) | |
216 | ||
217 | extern | |
218 | simple_lock_data_t vm_page_queue_lock; /* lock on active and inactive | |
219 | page queues */ | |
220 | extern | |
221 | simple_lock_data_t vm_page_queue_free_lock; | |
222 | /* lock on free page queue */ | |
223 | vm_offset_t vm_page_startup(); | |
224 | vm_page_t vm_page_lookup(); | |
225 | vm_page_t vm_page_alloc(); | |
226 | void vm_page_init(); | |
227 | void vm_page_free(); | |
228 | void vm_page_activate(); | |
229 | void vm_page_deactivate(); | |
230 | void vm_page_rename(); | |
231 | void vm_page_replace(); | |
232 | ||
233 | boolean_t vm_page_zero_fill(); | |
234 | void vm_page_copy(); | |
235 | ||
236 | void vm_page_wire(); | |
237 | void vm_page_unwire(); | |
238 | ||
239 | void vm_set_page_size(); | |
240 | ||
241 | /* | |
242 | * Functions implemented as macros | |
243 | */ | |
244 | ||
245 | #define PAGE_ASSERT_WAIT(m, interruptible) { \ | |
246 | (m)->wanted = TRUE; \ | |
247 | assert_wait((int) (m), (interruptible)); \ | |
248 | } | |
249 | ||
250 | #define PAGE_WAKEUP(m) { \ | |
251 | (m)->busy = FALSE; \ | |
252 | if ((m)->wanted) { \ | |
253 | (m)->wanted = FALSE; \ | |
254 | thread_wakeup((int) (m)); \ | |
255 | } \ | |
256 | } | |
257 | ||
258 | #define vm_page_lock_queues() simple_lock(&vm_page_queue_lock) | |
259 | #define vm_page_unlock_queues() simple_unlock(&vm_page_queue_lock) | |
260 | ||
261 | #define vm_page_set_modified(m) { (m)->clean = FALSE; } | |
262 | #endif KERNEL | |
263 | #endif _VM_PAGE_ |