1 /* 2 * Copyright (c) 1985, Avadis Tevanian, Jr., Michael Wayne Young 3 * Copyright (c) 1987 Carnegie-Mellon University 4 * Copyright (c) 1991 Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * The Mach Operating System project at Carnegie-Mellon University. 9 * 10 * The CMU software License Agreement specifies the terms and conditions 11 * for use and redistribution. 12 * 13 * @(#)vm_object.h 7.2 (Berkeley) 04/20/91 14 */ 15 16 /* 17 * Virtual memory object module definitions. 18 */ 19 20 #ifndef _VM_OBJECT_ 21 #define _VM_OBJECT_ 22 23 #include <vm/vm_pager.h> 24 25 /* 26 * Types defined: 27 * 28 * vm_object_t Virtual memory object. 29 */ 30 31 struct vm_object { 32 queue_chain_t memq; /* Resident memory */ 33 queue_chain_t object_list; /* list of all objects */ 34 simple_lock_data_t Lock; /* Synchronization */ 35 int LockHolder; 36 int ref_count; /* How many refs?? */ 37 vm_size_t size; /* Object size */ 38 int resident_page_count; 39 /* number of resident pages */ 40 struct vm_object *copy; /* Object that holds copies of 41 my changed pages */ 42 vm_pager_t pager; /* Where to get data */ 43 boolean_t pager_ready; /* Have pager fields been filled? */ 44 vm_offset_t paging_offset; /* Offset into paging space */ 45 struct vm_object *shadow; /* My shadow */ 46 vm_offset_t shadow_offset; /* Offset in shadow */ 47 unsigned int 48 paging_in_progress:16, 49 /* Paging (in or out) - don't 50 collapse or destroy */ 51 /* boolean_t */ can_persist:1, /* allow to persist */ 52 /* boolean_t */ internal:1; /* internally created object */ 53 queue_chain_t cached_list; /* for persistence */ 54 }; 55 56 typedef struct vm_object *vm_object_t; 57 58 struct vm_object_hash_entry { 59 queue_chain_t hash_links; /* hash chain links */ 60 vm_object_t object; /* object we represent */ 61 }; 62 63 typedef struct vm_object_hash_entry *vm_object_hash_entry_t; 64 65 #ifdef KERNEL 66 queue_head_t vm_object_cached_list; /* list of objects persisting */ 67 int vm_object_cached; /* size of cached list */ 68 simple_lock_data_t vm_cache_lock; /* lock for object cache */ 69 70 queue_head_t vm_object_list; /* list of allocated objects */ 71 long vm_object_count; /* count of all objects */ 72 simple_lock_data_t vm_object_list_lock; 73 /* lock for object list and count */ 74 75 vm_object_t kernel_object; /* the single kernel object */ 76 vm_object_t kmem_object; 77 78 #define vm_object_cache_lock() simple_lock(&vm_cache_lock) 79 #define vm_object_cache_unlock() simple_unlock(&vm_cache_lock) 80 #endif KERNEL 81 82 /* 83 * Declare procedures that operate on VM objects. 84 */ 85 86 void vm_object_init (); 87 void vm_object_terminate(); 88 vm_object_t vm_object_allocate(); 89 void vm_object_reference(); 90 void vm_object_deallocate(); 91 void vm_object_pmap_copy(); 92 void vm_object_pmap_remove(); 93 void vm_object_page_remove(); 94 void vm_object_shadow(); 95 void vm_object_copy(); 96 void vm_object_collapse(); 97 vm_object_t vm_object_lookup(); 98 void vm_object_enter(); 99 void vm_object_setpager(); 100 #define vm_object_cache(pager) pager_cache(vm_object_lookup(pager),TRUE) 101 #define vm_object_uncache(pager) pager_cache(vm_object_lookup(pager),FALSE) 102 103 void vm_object_cache_clear(); 104 void vm_object_print(); 105 106 #if VM_OBJECT_DEBUG 107 #define vm_object_lock_init(object) { simple_lock_init(&(object)->Lock); (object)->LockHolder = 0; } 108 #define vm_object_lock(object) { simple_lock(&(object)->Lock); (object)->LockHolder = (int) current_thread(); } 109 #define vm_object_unlock(object) { (object)->LockHolder = 0; simple_unlock(&(object)->Lock); } 110 #define vm_object_lock_try(object) (simple_lock_try(&(object)->Lock) ? ( ((object)->LockHolder = (int) current_thread()) , TRUE) : FALSE) 111 #define vm_object_sleep(event, object, interruptible) \ 112 { (object)->LockHolder = 0; thread_sleep((event), &(object)->Lock, (interruptible)); } 113 #else VM_OBJECT_DEBUG 114 #define vm_object_lock_init(object) simple_lock_init(&(object)->Lock) 115 #define vm_object_lock(object) simple_lock(&(object)->Lock) 116 #define vm_object_unlock(object) simple_unlock(&(object)->Lock) 117 #define vm_object_lock_try(object) simple_lock_try(&(object)->Lock) 118 #define vm_object_sleep(event, object, interruptible) \ 119 thread_sleep((event), &(object)->Lock, (interruptible)) 120 #endif VM_OBJECT_DEBUG 121 122 #endif _VM_OBJECT_ 123