|
|
1.1.1.2 root 1: /*
1.1 root 2: * Mach Operating System
3: * Copyright (c) 1993-1987 Carnegie Mellon University
4: * All Rights Reserved.
1.1.1.2 root 5: *
1.1 root 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.
1.1.1.2 root 11: *
1.1 root 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.
1.1.1.2 root 15: *
1.1 root 16: * Carnegie Mellon requests users of this software to return to
1.1.1.2 root 17: *
1.1 root 18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
1.1.1.2 root 22: *
1.1 root 23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * File: vm_object.h
28: * Author: Avadis Tevanian, Jr., Michael Wayne Young
29: * Date: 1985
30: *
31: * Virtual memory object module definitions.
32: */
33:
34: #ifndef _VM_VM_OBJECT_H_
35: #define _VM_VM_OBJECT_H_
36:
1.1.1.3 ! root 37: #include <sys/types.h>
1.1 root 38: #include <mach/kern_return.h>
39: #include <mach/boolean.h>
40: #include <mach/memory_object.h>
41: #include <mach/port.h>
42: #include <mach/vm_prot.h>
43: #include <mach/machine/vm_types.h>
44: #include <kern/queue.h>
45: #include <kern/lock.h>
46: #include <kern/assert.h>
1.1.1.3 ! root 47: #include <kern/debug.h>
1.1 root 48: #include <kern/macro_help.h>
49: #include <vm/pmap.h>
1.1.1.3 ! root 50: #include <ipc/ipc_types.h>
1.1 root 51:
52: #if MACH_PAGEMAP
53: #include <vm/vm_external.h>
54: #endif /* MACH_PAGEMAP */
55:
56: typedef struct ipc_port * pager_request_t;
57: #define PAGER_REQUEST_NULL ((pager_request_t) 0)
58:
59: /*
60: * We use "struct ipc_port *" instead of "ipc_port_t"
61: * to avoid include file circularities.
62: */
63:
64: struct vm_object {
65: queue_chain_t memq; /* Resident memory */
66: decl_simple_lock_data(, Lock) /* Synchronization */
67: #if VM_OBJECT_DEBUG
68: thread_t LockHolder; /* Thread holding Lock */
1.1.1.2 root 69: #endif /* VM_OBJECT_DEBUG */
1.1 root 70: vm_size_t size; /* Object size (only valid
71: * if internal)
72: */
73:
1.1.1.3 ! root 74: int ref_count; /* Number of references */
! 75: int resident_page_count;
1.1 root 76: /* number of resident pages */
77:
78: struct vm_object *copy; /* Object that should receive
79: * a copy of my changed pages
80: */
81: struct vm_object *shadow; /* My shadow */
82: vm_offset_t shadow_offset; /* Offset into shadow */
83:
84: struct ipc_port *pager; /* Where to get data */
85: vm_offset_t paging_offset; /* Offset into memory object */
86: pager_request_t pager_request; /* Where data comes back */
87: struct ipc_port *pager_name; /* How to identify region */
88:
89: memory_object_copy_strategy_t
90: copy_strategy; /* How to handle data copy */
91:
92: unsigned int
93: absent_count; /* The number of pages that
94: * have been requested but
95: * not filled. That is, the
96: * number of pages for which
97: * the "absent" attribute is
98: * asserted.
99: */
100:
101: unsigned int /* boolean_t array */
102: all_wanted; /* Bit array of "want to be
103: * awakened" notations. See
104: * VM_OBJECT_EVENT_* items
105: * below
106: */
107:
108: unsigned int
109: paging_in_progress:16,
110: /* The memory object ports are
111: * being used (e.g., for pagein
112: * or pageout) -- don't change any
113: * of these fields (i.e., don't
114: * collapse, destroy or terminate)
115: */
116: /* boolean_t */ pager_created:1,/* Has pager ever been created? */
117: /* boolean_t */ pager_initialized:1,/* Are fields ready to use? */
118: /* boolean_t */ pager_ready:1, /* Will manager take requests? */
119:
120: /* boolean_t */ can_persist:1, /* The kernel may keep the data
121: * for this object (and rights to
122: * the memory object) after all
123: * address map references are
124: * deallocated?
125: */
126: /* boolean_t */ internal:1, /* Created by the kernel (and
127: * therefore, managed by the
128: * default memory manger)
129: */
130: /* boolean_t */ temporary:1, /* Permanent objects may be changed
131: * externally by the memory manager,
132: * and changes made in memory must
133: * be reflected back to the memory
134: * manager. Temporary objects lack
135: * both of these characteristics.
136: */
137: /* boolean_t */ alive:1, /* Not yet terminated (debug) */
138: /* boolean_t */ lock_in_progress : 1,
139: /* Is a multi-page lock
140: * request in progress?
141: */
142: /* boolean_t */ lock_restart : 1,
143: /* Should lock request in
144: * progress restart search?
145: */
146: /* boolean_t */ use_old_pageout : 1,
1.1.1.2 root 147: /* Use old pageout primitives?
1.1 root 148: */
149: /* boolean_t */ use_shared_copy : 1,/* Use shared (i.e.,
150: * delayed) copy on write */
151: /* boolean_t */ shadowed: 1; /* Shadow may exist */
152:
153: queue_chain_t cached_list; /* Attachment point for the list
154: * of objects cached as a result
155: * of their can_persist value
156: */
157: vm_offset_t last_alloc; /* last allocation offset */
158: #if MACH_PAGEMAP
159: vm_external_t existence_info;
160: #endif /* MACH_PAGEMAP */
161: };
162:
163: extern
164: vm_object_t kernel_object; /* the single kernel object */
165:
166: /*
167: * Declare procedures that operate on VM objects.
168: */
169:
170: extern void vm_object_bootstrap(void);
171: extern void vm_object_init(void);
172: extern void vm_object_terminate(vm_object_t);
173: extern vm_object_t vm_object_allocate(vm_size_t);
174: extern void vm_object_reference(vm_object_t);
175: extern void vm_object_deallocate(vm_object_t);
176: extern void vm_object_pmap_protect(
177: vm_object_t object,
178: vm_offset_t offset,
179: vm_size_t size,
180: pmap_t pmap,
181: vm_offset_t pmap_start,
182: vm_prot_t prot);
183: extern void vm_object_pmap_remove(
184: vm_object_t object,
185: vm_offset_t start,
186: vm_offset_t end);
187: extern void vm_object_page_remove(
188: vm_object_t object,
189: vm_offset_t start,
190: vm_offset_t end);
191: extern void vm_object_shadow(
192: vm_object_t *object, /* in/out */
193: vm_offset_t *offset, /* in/out */
194: vm_size_t length);
195: extern void vm_object_collapse(vm_object_t);
196: extern vm_object_t vm_object_lookup(struct ipc_port *);
197: extern vm_object_t vm_object_lookup_name(struct ipc_port *);
198: extern struct ipc_port *vm_object_name(vm_object_t);
199: extern void vm_object_remove(vm_object_t);
200:
201: extern boolean_t vm_object_copy_temporary(
202: vm_object_t *_object, /* in/out */
203: vm_offset_t *_offset, /* in/out */
204: boolean_t *_src_needs_copy, /* out */
205: boolean_t *_dst_needs_copy); /* out */
206: extern kern_return_t vm_object_copy_strategically(
207: vm_object_t src_object,
208: vm_offset_t src_offset,
209: vm_size_t size,
210: vm_object_t *dst_object, /* out */
211: vm_offset_t *dst_offset, /* out */
212: boolean_t *dst_needs_copy); /* out */
213: extern kern_return_t vm_object_copy_slowly(
214: vm_object_t src_object,
215: vm_offset_t src_offset,
216: vm_size_t size,
217: boolean_t interruptible,
218: vm_object_t *_result_object); /* out */
219:
220: extern vm_object_t vm_object_enter(
221: struct ipc_port *pager,
222: vm_size_t size,
223: boolean_t internal);
224: extern void vm_object_pager_create(
225: vm_object_t object);
226: extern void vm_object_destroy(
227: struct ipc_port *pager);
228:
1.1.1.2 root 229: extern void vm_object_page_map(
230: vm_object_t,
231: vm_offset_t,
232: vm_size_t,
1.1 root 233: vm_offset_t (*)(void *, vm_offset_t),
234: void *);
235:
236: extern vm_object_t vm_object_request_object(struct ipc_port *);
237:
1.1.1.3 ! root 238: extern boolean_t vm_object_coalesce(
! 239: vm_object_t prev_object,
! 240: vm_object_t next_object,
! 241: vm_offset_t prev_offset,
! 242: vm_offset_t next_offset,
! 243: vm_size_t prev_size,
! 244: vm_size_t next_size);
! 245:
! 246: extern void vm_object_pager_wakeup(ipc_port_t pager);
! 247:
1.1 root 248: /*
249: * Event waiting handling
250: */
251:
252: #define VM_OBJECT_EVENT_INITIALIZED 0
253: #define VM_OBJECT_EVENT_PAGER_READY 1
254: #define VM_OBJECT_EVENT_PAGING_IN_PROGRESS 2
255: #define VM_OBJECT_EVENT_ABSENT_COUNT 3
256: #define VM_OBJECT_EVENT_LOCK_IN_PROGRESS 4
257:
258: #define vm_object_wait(object, event, interruptible) \
259: MACRO_BEGIN \
260: (object)->all_wanted |= 1 << (event); \
261: vm_object_sleep(((vm_offset_t) object) + (event), \
262: (object), \
263: (interruptible)); \
264: MACRO_END
265:
266: #define vm_object_assert_wait(object, event, interruptible) \
267: MACRO_BEGIN \
268: (object)->all_wanted |= 1 << (event); \
269: assert_wait((event_t)(((vm_offset_t) object) + (event)), (interruptible)); \
270: MACRO_END
271:
272: #define vm_object_wakeup(object, event) \
273: MACRO_BEGIN \
274: if ((object)->all_wanted & (1 << (event))) \
275: thread_wakeup((event_t)(((vm_offset_t) object) + (event))); \
276: (object)->all_wanted &= ~(1 << (event)); \
277: MACRO_END
278:
279: /*
280: * Routines implemented as macros
281: */
282:
283: #define vm_object_paging_begin(object) \
284: ((object)->paging_in_progress++)
285:
286: #define vm_object_paging_end(object) \
287: MACRO_BEGIN \
288: assert((object)->paging_in_progress != 0); \
289: if (--(object)->paging_in_progress == 0) { \
290: vm_object_wakeup(object, \
291: VM_OBJECT_EVENT_PAGING_IN_PROGRESS); \
292: } \
293: MACRO_END
294:
295: #define vm_object_paging_wait(object, interruptible) \
296: MACRO_BEGIN \
297: while ((object)->paging_in_progress != 0) { \
298: vm_object_wait( (object), \
299: VM_OBJECT_EVENT_PAGING_IN_PROGRESS, \
300: (interruptible)); \
301: vm_object_lock(object); \
302: \
303: /*XXX if ((interruptible) && */ \
304: /*XXX (current_thread()->wait_result != THREAD_AWAKENED))*/ \
305: /*XXX break; */ \
306: } \
307: MACRO_END
308:
309: #define vm_object_absent_assert_wait(object, interruptible) \
310: MACRO_BEGIN \
311: vm_object_assert_wait( (object), \
312: VM_OBJECT_EVENT_ABSENT_COUNT, \
313: (interruptible)); \
314: MACRO_END
315:
316:
317: #define vm_object_absent_release(object) \
318: MACRO_BEGIN \
319: (object)->absent_count--; \
320: vm_object_wakeup((object), \
321: VM_OBJECT_EVENT_ABSENT_COUNT); \
322: MACRO_END
323:
324: /*
325: * Object locking macros (with and without debugging)
326: */
327:
328: #if VM_OBJECT_DEBUG
329: #define vm_object_lock_init(object) \
330: MACRO_BEGIN \
331: simple_lock_init(&(object)->Lock); \
332: (object)->LockHolder = 0; \
333: MACRO_END
334: #define vm_object_lock(object) \
335: MACRO_BEGIN \
336: simple_lock(&(object)->Lock); \
337: (object)->LockHolder = current_thread(); \
338: MACRO_END
339: #define vm_object_unlock(object) \
340: MACRO_BEGIN \
341: if ((object)->LockHolder != current_thread()) \
342: panic("vm_object_unlock 0x%x", (object)); \
343: (object)->LockHolder = 0; \
344: simple_unlock(&(object)->Lock); \
345: MACRO_END
346: #define vm_object_lock_try(object) \
347: (simple_lock_try(&(object)->Lock) \
348: ? ( ((object)->LockHolder = current_thread()) , TRUE) \
349: : FALSE)
350: #define vm_object_sleep(event, object, interruptible) \
351: MACRO_BEGIN \
352: if ((object)->LockHolder != current_thread()) \
353: panic("vm_object_sleep %#x", (object)); \
354: (object)->LockHolder = 0; \
355: thread_sleep((event_t)(event), simple_lock_addr((object)->Lock), \
356: (interruptible)); \
357: MACRO_END
358: #define vm_object_lock_taken(object) \
359: ((object)->LockHolder == current_thread())
360: #else /* VM_OBJECT_DEBUG */
361: #define vm_object_lock_init(object) simple_lock_init(&(object)->Lock)
362: #define vm_object_lock(object) simple_lock(&(object)->Lock)
363: #define vm_object_unlock(object) simple_unlock(&(object)->Lock)
364: #define vm_object_lock_try(object) simple_lock_try(&(object)->Lock)
365: #define vm_object_sleep(event, object, interruptible) \
366: thread_sleep((event_t)(event), simple_lock_addr((object)->Lock), \
367: (interruptible))
368: #define vm_object_lock_taken(object) simple_lock_taken(&(object)->Lock)
369: #endif /* VM_OBJECT_DEBUG */
370:
1.1.1.3 ! root 371: /*
! 372: * Page cache accounting.
! 373: *
! 374: * The number of cached objects and pages can be read
! 375: * without holding any lock.
! 376: */
! 377:
! 378: extern int vm_object_cached_count;
! 379:
! 380: extern int vm_object_cached_pages;
! 381: decl_simple_lock_data(extern,vm_object_cached_pages_lock_data)
! 382:
! 383: #define vm_object_cached_pages_update(page_count) \
! 384: MACRO_BEGIN \
! 385: simple_lock(&vm_object_cached_pages_lock_data); \
! 386: vm_object_cached_pages += (page_count); \
! 387: simple_unlock(&vm_object_cached_pages_lock_data); \
! 388: MACRO_END
! 389:
1.1 root 390: #endif /* _VM_VM_OBJECT_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.