xref: /original-bsd/sys/vm/vm_object.h (revision 08eb28af)
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  * %sccs.include.redist.c%
9  *
10  *	@(#)vm_object.h	7.3 (Berkeley) 04/21/91
11  *
12  *
13  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
14  * All rights reserved.
15  *
16  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
17  *
18  * Permission to use, copy, modify and distribute this software and
19  * its documentation is hereby granted, provided that both the copyright
20  * notice and this permission notice appear in all copies of the
21  * software, derivative works or modified versions, and any portions
22  * thereof, and that both notices appear in supporting documentation.
23  *
24  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
25  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
26  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
27  *
28  * Carnegie Mellon requests users of this software to return to
29  *
30  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
31  *  School of Computer Science
32  *  Carnegie Mellon University
33  *  Pittsburgh PA 15213-3890
34  *
35  * any improvements or extensions that they make and grant Carnegie the
36  * rights to redistribute these changes.
37  */
38 
39 /*
40  *	Virtual memory object module definitions.
41  */
42 
43 #ifndef	_VM_OBJECT_
44 #define	_VM_OBJECT_
45 
46 #include <vm/vm_pager.h>
47 
48 /*
49  *	Types defined:
50  *
51  *	vm_object_t		Virtual memory object.
52  */
53 
54 struct vm_object {
55 	queue_chain_t		memq;		/* Resident memory */
56 	queue_chain_t		object_list;	/* list of all objects */
57 	simple_lock_data_t	Lock;		/* Synchronization */
58 	int			LockHolder;
59 	int			ref_count;	/* How many refs?? */
60 	vm_size_t		size;		/* Object size */
61 	int			resident_page_count;
62 						/* number of resident pages */
63 	struct vm_object	*copy;		/* Object that holds copies of
64 						   my changed pages */
65 	vm_pager_t		pager;		/* Where to get data */
66 	boolean_t		pager_ready;	/* Have pager fields been filled? */
67 	vm_offset_t		paging_offset;	/* Offset into paging space */
68 	struct vm_object	*shadow;	/* My shadow */
69 	vm_offset_t		shadow_offset;	/* Offset in shadow */
70 	unsigned int
71 				paging_in_progress:16,
72 						/* Paging (in or out) - don't
73 						   collapse or destroy */
74 	/* boolean_t */		can_persist:1,	/* allow to persist */
75 	/* boolean_t */		internal:1;	/* internally created object */
76 	queue_chain_t		cached_list;	/* for persistence */
77 };
78 
79 typedef struct vm_object	*vm_object_t;
80 
81 struct vm_object_hash_entry {
82 	queue_chain_t		hash_links;	/* hash chain links */
83 	vm_object_t		object;		/* object we represent */
84 };
85 
86 typedef struct vm_object_hash_entry	*vm_object_hash_entry_t;
87 
88 #ifdef	KERNEL
89 queue_head_t	vm_object_cached_list;	/* list of objects persisting */
90 int		vm_object_cached;	/* size of cached list */
91 simple_lock_data_t	vm_cache_lock;	/* lock for object cache */
92 
93 queue_head_t	vm_object_list;		/* list of allocated objects */
94 long		vm_object_count;	/* count of all objects */
95 simple_lock_data_t	vm_object_list_lock;
96 					/* lock for object list and count */
97 
98 vm_object_t	kernel_object;		/* the single kernel object */
99 vm_object_t	kmem_object;
100 
101 #define	vm_object_cache_lock()		simple_lock(&vm_cache_lock)
102 #define	vm_object_cache_unlock()	simple_unlock(&vm_cache_lock)
103 #endif	KERNEL
104 
105 /*
106  *	Declare procedures that operate on VM objects.
107  */
108 
109 void		vm_object_init ();
110 void		vm_object_terminate();
111 vm_object_t	vm_object_allocate();
112 void		vm_object_reference();
113 void		vm_object_deallocate();
114 void		vm_object_pmap_copy();
115 void		vm_object_pmap_remove();
116 void		vm_object_page_remove();
117 void		vm_object_shadow();
118 void		vm_object_copy();
119 void		vm_object_collapse();
120 vm_object_t	vm_object_lookup();
121 void		vm_object_enter();
122 void		vm_object_setpager();
123 #define		vm_object_cache(pager)		pager_cache(vm_object_lookup(pager),TRUE)
124 #define		vm_object_uncache(pager)	pager_cache(vm_object_lookup(pager),FALSE)
125 
126 void		vm_object_cache_clear();
127 void		vm_object_print();
128 
129 #if	VM_OBJECT_DEBUG
130 #define	vm_object_lock_init(object)	{ simple_lock_init(&(object)->Lock); (object)->LockHolder = 0; }
131 #define	vm_object_lock(object)		{ simple_lock(&(object)->Lock); (object)->LockHolder = (int) current_thread(); }
132 #define	vm_object_unlock(object)	{ (object)->LockHolder = 0; simple_unlock(&(object)->Lock); }
133 #define	vm_object_lock_try(object)	(simple_lock_try(&(object)->Lock) ? ( ((object)->LockHolder = (int) current_thread()) , TRUE) : FALSE)
134 #define	vm_object_sleep(event, object, interruptible) \
135 					{ (object)->LockHolder = 0; thread_sleep((event), &(object)->Lock, (interruptible)); }
136 #else	VM_OBJECT_DEBUG
137 #define	vm_object_lock_init(object)	simple_lock_init(&(object)->Lock)
138 #define	vm_object_lock(object)		simple_lock(&(object)->Lock)
139 #define	vm_object_unlock(object)	simple_unlock(&(object)->Lock)
140 #define	vm_object_lock_try(object)	simple_lock_try(&(object)->Lock)
141 #define	vm_object_sleep(event, object, interruptible) \
142 					thread_sleep((event), &(object)->Lock, (interruptible))
143 #endif	VM_OBJECT_DEBUG
144 
145 #endif	_VM_OBJECT_
146