|
|
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.1.4 ! root 248: void memory_object_release(
! 249: ipc_port_t pager,
! 250: pager_request_t pager_request,
! 251: ipc_port_t pager_name);
! 252:
! 253: void vm_object_deactivate_pages(vm_object_t);
! 254:
! 255: vm_object_t vm_object_copy_delayed(
! 256: vm_object_t src_object);
! 257:
1.1 root 258: /*
259: * Event waiting handling
260: */
261:
262: #define VM_OBJECT_EVENT_INITIALIZED 0
263: #define VM_OBJECT_EVENT_PAGER_READY 1
264: #define VM_OBJECT_EVENT_PAGING_IN_PROGRESS 2
265: #define VM_OBJECT_EVENT_ABSENT_COUNT 3
266: #define VM_OBJECT_EVENT_LOCK_IN_PROGRESS 4
267:
268: #define vm_object_wait(object, event, interruptible) \
269: MACRO_BEGIN \
270: (object)->all_wanted |= 1 << (event); \
271: vm_object_sleep(((vm_offset_t) object) + (event), \
272: (object), \
273: (interruptible)); \
274: MACRO_END
275:
276: #define vm_object_assert_wait(object, event, interruptible) \
277: MACRO_BEGIN \
278: (object)->all_wanted |= 1 << (event); \
279: assert_wait((event_t)(((vm_offset_t) object) + (event)), (interruptible)); \
280: MACRO_END
281:
282: #define vm_object_wakeup(object, event) \
283: MACRO_BEGIN \
284: if ((object)->all_wanted & (1 << (event))) \
285: thread_wakeup((event_t)(((vm_offset_t) object) + (event))); \
286: (object)->all_wanted &= ~(1 << (event)); \
287: MACRO_END
288:
289: /*
290: * Routines implemented as macros
291: */
292:
293: #define vm_object_paging_begin(object) \
294: ((object)->paging_in_progress++)
295:
296: #define vm_object_paging_end(object) \
297: MACRO_BEGIN \
298: assert((object)->paging_in_progress != 0); \
299: if (--(object)->paging_in_progress == 0) { \
300: vm_object_wakeup(object, \
301: VM_OBJECT_EVENT_PAGING_IN_PROGRESS); \
302: } \
303: MACRO_END
304:
305: #define vm_object_paging_wait(object, interruptible) \
306: MACRO_BEGIN \
307: while ((object)->paging_in_progress != 0) { \
308: vm_object_wait( (object), \
309: VM_OBJECT_EVENT_PAGING_IN_PROGRESS, \
310: (interruptible)); \
311: vm_object_lock(object); \
312: \
313: /*XXX if ((interruptible) && */ \
314: /*XXX (current_thread()->wait_result != THREAD_AWAKENED))*/ \
315: /*XXX break; */ \
316: } \
317: MACRO_END
318:
319: #define vm_object_absent_assert_wait(object, interruptible) \
320: MACRO_BEGIN \
321: vm_object_assert_wait( (object), \
322: VM_OBJECT_EVENT_ABSENT_COUNT, \
323: (interruptible)); \
324: MACRO_END
325:
326:
327: #define vm_object_absent_release(object) \
328: MACRO_BEGIN \
329: (object)->absent_count--; \
330: vm_object_wakeup((object), \
331: VM_OBJECT_EVENT_ABSENT_COUNT); \
332: MACRO_END
333:
334: /*
335: * Object locking macros (with and without debugging)
336: */
337:
338: #if VM_OBJECT_DEBUG
339: #define vm_object_lock_init(object) \
340: MACRO_BEGIN \
341: simple_lock_init(&(object)->Lock); \
342: (object)->LockHolder = 0; \
343: MACRO_END
344: #define vm_object_lock(object) \
345: MACRO_BEGIN \
346: simple_lock(&(object)->Lock); \
347: (object)->LockHolder = current_thread(); \
348: MACRO_END
349: #define vm_object_unlock(object) \
350: MACRO_BEGIN \
351: if ((object)->LockHolder != current_thread()) \
352: panic("vm_object_unlock 0x%x", (object)); \
353: (object)->LockHolder = 0; \
354: simple_unlock(&(object)->Lock); \
355: MACRO_END
356: #define vm_object_lock_try(object) \
357: (simple_lock_try(&(object)->Lock) \
358: ? ( ((object)->LockHolder = current_thread()) , TRUE) \
359: : FALSE)
360: #define vm_object_sleep(event, object, interruptible) \
361: MACRO_BEGIN \
362: if ((object)->LockHolder != current_thread()) \
363: panic("vm_object_sleep %#x", (object)); \
364: (object)->LockHolder = 0; \
365: thread_sleep((event_t)(event), simple_lock_addr((object)->Lock), \
366: (interruptible)); \
367: MACRO_END
368: #define vm_object_lock_taken(object) \
369: ((object)->LockHolder == current_thread())
370: #else /* VM_OBJECT_DEBUG */
371: #define vm_object_lock_init(object) simple_lock_init(&(object)->Lock)
372: #define vm_object_lock(object) simple_lock(&(object)->Lock)
373: #define vm_object_unlock(object) simple_unlock(&(object)->Lock)
374: #define vm_object_lock_try(object) simple_lock_try(&(object)->Lock)
375: #define vm_object_sleep(event, object, interruptible) \
376: thread_sleep((event_t)(event), simple_lock_addr((object)->Lock), \
377: (interruptible))
378: #define vm_object_lock_taken(object) simple_lock_taken(&(object)->Lock)
379: #endif /* VM_OBJECT_DEBUG */
380:
1.1.1.3 root 381: /*
382: * Page cache accounting.
383: *
384: * The number of cached objects and pages can be read
385: * without holding any lock.
386: */
387:
388: extern int vm_object_cached_count;
389:
390: extern int vm_object_cached_pages;
391: decl_simple_lock_data(extern,vm_object_cached_pages_lock_data)
392:
393: #define vm_object_cached_pages_update(page_count) \
394: MACRO_BEGIN \
395: simple_lock(&vm_object_cached_pages_lock_data); \
396: vm_object_cached_pages += (page_count); \
397: simple_unlock(&vm_object_cached_pages_lock_data); \
398: MACRO_END
399:
1.1 root 400: #endif /* _VM_VM_OBJECT_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.