|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1993-1988 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * File: vm/vm_page.h
28: * Author: Avadis Tevanian, Jr., Michael Wayne Young
29: * Date: 1985
30: *
31: * Resident memory system definitions.
32: */
33:
34: #ifndef _VM_VM_PAGE_H_
35: #define _VM_VM_PAGE_H_
36:
37: #include <mach/boolean.h>
38: #include <mach/vm_prot.h>
39: #include <mach/vm_param.h>
40: #include <vm/vm_object.h>
1.1.1.3 root 41: #include <vm/vm_types.h>
1.1 root 42: #include <kern/queue.h>
43: #include <kern/lock.h>
44:
45: #include <kern/macro_help.h>
46: #include <kern/sched_prim.h> /* definitions of wait/wakeup */
47:
48: #if MACH_VM_DEBUG
49: #include <mach_debug/hash_info.h>
50: #endif
51:
52: /*
53: * Management of resident (logical) pages.
54: *
55: * A small structure is kept for each resident
56: * page, indexed by page number. Each structure
57: * is an element of several lists:
58: *
59: * A hash table bucket used to quickly
60: * perform object/offset lookups
61: *
62: * A list of all pages for a given object,
63: * so they can be quickly deactivated at
64: * time of deallocation.
65: *
66: * An ordered list of pages due for pageout.
67: *
68: * In addition, the structure contains the object
69: * and offset to which this page belongs (for pageout),
70: * and sundry status bits.
71: *
72: * Fields in this structure are locked either by the lock on the
73: * object that the page belongs to (O) or by the lock on the page
74: * queues (P). [Some fields require that both locks be held to
75: * change that field; holding either lock is sufficient to read.]
76: */
77:
78: struct vm_page {
79: queue_chain_t pageq; /* queue info for FIFO
80: * queue or free list (P) */
81: queue_chain_t listq; /* all pages in same object (O) */
82: struct vm_page *next; /* VP bucket link (O) */
83:
84: vm_object_t object; /* which object am I in (O,P) */
85: vm_offset_t offset; /* offset into that object (O,P) */
86:
1.1.1.4 ! root 87: unsigned int wire_count:15, /* how many wired down maps use me?
1.1 root 88: (O&P) */
89: /* boolean_t */ inactive:1, /* page is in inactive list (P) */
90: active:1, /* page is in active list (P) */
91: laundry:1, /* page is being cleaned now (P)*/
92: free:1, /* page is on free list (P) */
93: reference:1, /* page has been used (P) */
1.1.1.2 root 94: external:1, /* page considered external (P) */
1.1.1.4 ! root 95: extcounted:1, /* page counted in ext counts (P) */
! 96: busy:1, /* page is in transit (O) */
1.1 root 97: wanted:1, /* someone is waiting for page (O) */
98: tabled:1, /* page is in VP table (O) */
99: fictitious:1, /* Physical page doesn't exist (O) */
100: private:1, /* Page should not be returned to
101: * the free list (O) */
102: absent:1, /* Data has been requested, but is
103: * not yet available (O) */
104: error:1, /* Data manager was unable to provide
105: * data due to error (O) */
106: dirty:1, /* Page must be cleaned (O) */
107: precious:1, /* Page is precious; data must be
108: * returned even if clean (O) */
1.1.1.4 ! root 109: overwriting:1; /* Request to unlock has been made
1.1 root 110: * without having data. (O)
111: * [See vm_object_overwrite] */
112:
113: vm_offset_t phys_addr; /* Physical address of page, passed
114: * to pmap_enter (read-only) */
115: vm_prot_t page_lock; /* Uses prohibited by data manager (O) */
116: vm_prot_t unlock_request; /* Outstanding unlock request (O) */
117: };
118:
119: /*
120: * For debugging, this macro can be defined to perform
121: * some useful check on a page structure.
122: */
123:
124: #define VM_PAGE_CHECK(mem)
125:
126: /*
127: * Each pageable resident page falls into one of three lists:
128: *
129: * free
130: * Available for allocation now.
131: * inactive
132: * Not referenced in any map, but still has an
133: * object/offset-page mapping, and may be dirty.
134: * This is the list of pages that should be
135: * paged out next.
136: * active
137: * A list of pages which have been placed in
138: * at least one physical map. This list is
139: * ordered, in LRU-like fashion.
140: */
141:
142: extern
143: vm_page_t vm_page_queue_free; /* memory free queue */
144: extern
145: vm_page_t vm_page_queue_fictitious; /* fictitious free queue */
146: extern
147: queue_head_t vm_page_queue_active; /* active memory queue */
148: extern
149: queue_head_t vm_page_queue_inactive; /* inactive memory queue */
150:
151: extern
152: int vm_page_free_count; /* How many pages are free? */
153: extern
154: int vm_page_fictitious_count;/* How many fictitious pages are free? */
155: extern
156: int vm_page_active_count; /* How many pages are active? */
157: extern
158: int vm_page_inactive_count; /* How many pages are inactive? */
159: extern
160: int vm_page_wire_count; /* How many pages are wired? */
161: extern
162: int vm_page_free_target; /* How many do we want free? */
163: extern
164: int vm_page_free_min; /* When to wakeup pageout */
165: extern
166: int vm_page_inactive_target;/* How many do we want inactive? */
167: extern
168: int vm_page_free_reserved; /* How many pages reserved to do pageout */
169: extern
170: int vm_page_laundry_count; /* How many pages being laundered? */
1.1.1.2 root 171: extern
172: int vm_page_external_limit; /* Max number of pages for external objects */
173:
174: /* Only objects marked with the extcounted bit are included in this total.
175: Pages which we scan for possible pageout, but which are not actually
176: dirty, don't get considered against the external page limits any more
177: in this way. */
178: extern
179: int vm_page_external_count; /* How many pages for external objects? */
180:
181:
1.1 root 182:
183: decl_simple_lock_data(extern,vm_page_queue_lock)/* lock on active and inactive
184: page queues */
185: decl_simple_lock_data(extern,vm_page_queue_free_lock)
186: /* lock on free page queue */
187:
188: extern unsigned int vm_page_free_wanted;
189: /* how many threads are waiting for memory */
190:
191: extern vm_offset_t vm_page_fictitious_addr;
192: /* (fake) phys_addr of fictitious pages */
193:
194: extern void vm_page_bootstrap(
195: vm_offset_t *startp,
196: vm_offset_t *endp);
197: extern void vm_page_module_init(void);
198:
199: extern void vm_page_create(
200: vm_offset_t start,
201: vm_offset_t end);
202: extern vm_page_t vm_page_lookup(
203: vm_object_t object,
204: vm_offset_t offset);
205: extern vm_page_t vm_page_grab_fictitious(void);
206: extern void vm_page_release_fictitious(vm_page_t);
1.1.1.2 root 207: extern boolean_t vm_page_convert(vm_page_t, boolean_t);
1.1 root 208: extern void vm_page_more_fictitious(void);
1.1.1.2 root 209: extern vm_page_t vm_page_grab(boolean_t);
210: extern void vm_page_release(vm_page_t, boolean_t);
1.1 root 211: extern void vm_page_wait(void (*)(void));
212: extern vm_page_t vm_page_alloc(
213: vm_object_t object,
214: vm_offset_t offset);
215: extern void vm_page_init(
216: vm_page_t mem,
217: vm_offset_t phys_addr);
218: extern void vm_page_free(vm_page_t);
219: extern void vm_page_activate(vm_page_t);
220: extern void vm_page_deactivate(vm_page_t);
221: extern void vm_page_rename(
222: vm_page_t mem,
223: vm_object_t new_object,
224: vm_offset_t new_offset);
225: extern void vm_page_insert(
226: vm_page_t mem,
227: vm_object_t object,
228: vm_offset_t offset);
229: extern void vm_page_remove(
230: vm_page_t mem);
231:
232: extern void vm_page_zero_fill(vm_page_t);
233: extern void vm_page_copy(vm_page_t src_m, vm_page_t dest_m);
234:
235: extern void vm_page_wire(vm_page_t);
236: extern void vm_page_unwire(vm_page_t);
237:
238: #if MACH_VM_DEBUG
239: extern unsigned int vm_page_info(
240: hash_info_bucket_t *info,
241: unsigned int count);
242: #endif
243:
244: /*
245: * Functions implemented as macros
246: */
247:
248: #define PAGE_ASSERT_WAIT(m, interruptible) \
249: MACRO_BEGIN \
250: (m)->wanted = TRUE; \
251: assert_wait((event_t) (m), (interruptible)); \
252: MACRO_END
253:
254: #define PAGE_WAKEUP_DONE(m) \
255: MACRO_BEGIN \
256: (m)->busy = FALSE; \
257: if ((m)->wanted) { \
258: (m)->wanted = FALSE; \
259: thread_wakeup(((event_t) m)); \
260: } \
261: MACRO_END
262:
263: #define PAGE_WAKEUP(m) \
264: MACRO_BEGIN \
265: if ((m)->wanted) { \
266: (m)->wanted = FALSE; \
267: thread_wakeup((event_t) (m)); \
268: } \
269: MACRO_END
270:
271: #define VM_PAGE_FREE(p) \
272: MACRO_BEGIN \
273: vm_page_lock_queues(); \
274: vm_page_free(p); \
275: vm_page_unlock_queues(); \
276: MACRO_END
277:
278: /*
279: * Macro to be used in place of pmap_enter()
280: */
281:
282: #define PMAP_ENTER(pmap, virtual_address, page, protection, wired) \
283: MACRO_BEGIN \
284: pmap_enter( \
285: (pmap), \
286: (virtual_address), \
287: (page)->phys_addr, \
288: (protection) & ~(page)->page_lock, \
289: (wired) \
290: ); \
291: MACRO_END
292:
293: #define VM_PAGE_WAIT(continuation) vm_page_wait(continuation)
294:
295: #define vm_page_lock_queues() simple_lock(&vm_page_queue_lock)
296: #define vm_page_unlock_queues() simple_unlock(&vm_page_queue_lock)
297:
298: #define VM_PAGE_QUEUES_REMOVE(mem) \
299: MACRO_BEGIN \
300: if (mem->active) { \
301: queue_remove(&vm_page_queue_active, \
302: mem, vm_page_t, pageq); \
303: mem->active = FALSE; \
304: vm_page_active_count--; \
305: } \
306: \
307: if (mem->inactive) { \
308: queue_remove(&vm_page_queue_inactive, \
309: mem, vm_page_t, pageq); \
310: mem->inactive = FALSE; \
311: vm_page_inactive_count--; \
312: } \
313: MACRO_END
314:
315: #endif /* _VM_VM_PAGE_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.