FreeBSD/Linux Kernel Cross Reference
sys/vm/vm_external.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989 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 Software.Distribution@CS.CMU.EDU
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 * HISTORY
28 * $Log: vm_external.c,v $
29 * Revision 2.9 92/08/03 18:00:12 jfriedl
30 * removed silly prototypes
31 * [92/08/02 jfriedl]
32 *
33 * Revision 2.8 92/05/21 17:25:39 jfriedl
34 * tried prototypes.
35 * [92/05/20 jfriedl]
36 *
37 * Revision 2.7 91/05/14 17:48:23 mrt
38 * Correcting copyright
39 *
40 * Revision 2.6 91/02/05 17:57:44 mrt
41 * Changed to new Mach copyright
42 * [91/02/01 16:31:19 mrt]
43 *
44 * Revision 2.5 91/01/08 16:44:33 rpd
45 * Changed zchange calls to make the zones non-collectable.
46 * [90/12/29 rpd]
47 *
48 * Revision 2.4 90/12/20 17:05:13 jeffreyh
49 * Change zchange to accept new argument. Made zones collectable.
50 * [90/12/11 jeffreyh]
51 *
52 * Revision 2.3 90/05/29 18:38:33 rwd
53 * Picked up rfr changes.
54 * [90/04/12 13:46:29 rwd]
55 *
56 * Revision 2.2 90/01/11 11:47:26 dbg
57 * Add changes from mainline:
58 * Fixed off-by-one error in vm_external_create.
59 * [89/12/18 23:40:56 rpd]
60 *
61 * Keep the bitmap size info around, as it may travel across
62 * objects. Reflect this in vm_external_destroy().
63 * [89/10/16 15:32:06 af]
64 *
65 * Removed lint.
66 * [89/08/07 mwyoung]
67 *
68 * Revision 2.1 89/08/03 16:44:41 rwd
69 * Created.
70 *
71 * Revision 2.3 89/04/18 21:24:49 mwyoung
72 * Created.
73 * [89/04/18 mwyoung]
74 *
75 */
76
77 /*
78 * This module maintains information about the presence of
79 * pages not in memory. Since an external memory object
80 * must maintain a complete knowledge of its contents, this
81 * information takes the form of hints.
82 */
83
84 #include <mach/boolean.h>
85 #include <kern/zalloc.h>
86 #include <vm/vm_external.h>
87 #include <mach/vm_param.h>
88 #include <kern/assert.h>
89
90
91
92 boolean_t vm_external_unsafe = FALSE;
93
94 zone_t vm_external_zone = ZONE_NULL;
95
96 /*
97 * The implementation uses bit arrays to record whether
98 * a page has been written to external storage. For
99 * convenience, these bit arrays come in two sizes
100 * (measured in bytes).
101 */
102
103 #define SMALL_SIZE (VM_EXTERNAL_SMALL_SIZE/8)
104 #define LARGE_SIZE (VM_EXTERNAL_LARGE_SIZE/8)
105
106 zone_t vm_object_small_existence_map_zone;
107 zone_t vm_object_large_existence_map_zone;
108
109
110 vm_external_t vm_external_create(size)
111 vm_offset_t size;
112 {
113 vm_external_t result;
114 vm_size_t bytes;
115
116 if (vm_external_zone == ZONE_NULL)
117 return(VM_EXTERNAL_NULL);
118
119 result = (vm_external_t) zalloc(vm_external_zone);
120 result->existence_map = (char *) 0;
121
122 bytes = (atop(size) + 07) >> 3;
123 if (bytes <= SMALL_SIZE) {
124 result->existence_map =
125 (char *) zalloc(vm_object_small_existence_map_zone);
126 result->existence_size = SMALL_SIZE;
127 } else if (bytes <= LARGE_SIZE) {
128 result->existence_map =
129 (char *) zalloc(vm_object_large_existence_map_zone);
130 result->existence_size = LARGE_SIZE;
131 }
132 return(result);
133 }
134
135 void vm_external_destroy(e)
136 vm_external_t e;
137 {
138 if (e == VM_EXTERNAL_NULL)
139 return;
140
141 if (e->existence_map != (char *) 0) {
142 if (e->existence_size <= SMALL_SIZE) {
143 zfree(vm_object_small_existence_map_zone,
144 (vm_offset_t) e->existence_map);
145 } else {
146 zfree(vm_object_large_existence_map_zone,
147 (vm_offset_t) e->existence_map);
148 }
149 }
150 zfree(vm_external_zone, (vm_offset_t) e);
151 }
152
153 vm_external_state_t _vm_external_state_get(e, offset)
154 vm_external_t e;
155 vm_offset_t offset;
156 {
157 unsigned
158 int bit, byte;
159
160 if (vm_external_unsafe ||
161 (e == VM_EXTERNAL_NULL) ||
162 (e->existence_map == (char *) 0))
163 return(VM_EXTERNAL_STATE_UNKNOWN);
164
165 bit = atop(offset);
166 byte = bit >> 3;
167 if (byte >= e->existence_size) return (VM_EXTERNAL_STATE_UNKNOWN);
168 return( (e->existence_map[byte] & (1 << (bit & 07))) ?
169 VM_EXTERNAL_STATE_EXISTS : VM_EXTERNAL_STATE_ABSENT );
170 }
171
172 void vm_external_state_set(e, offset, state)
173 vm_external_t e;
174 vm_offset_t offset;
175 vm_external_state_t state;
176 {
177 unsigned
178 int bit, byte;
179
180 if ((e == VM_EXTERNAL_NULL) || (e->existence_map == (char *) 0))
181 return;
182
183 if (state != VM_EXTERNAL_STATE_EXISTS)
184 return;
185
186 bit = atop(offset);
187 byte = bit >> 3;
188 if (byte >= e->existence_size) return;
189 e->existence_map[byte] |= (1 << (bit & 07));
190 }
191
192 void vm_external_module_initialize()
193 {
194 vm_size_t size = (vm_size_t) sizeof(struct vm_external);
195
196 vm_external_zone = zinit(size, 16*1024*size, size,
197 FALSE, "external page bitmaps");
198
199 vm_object_small_existence_map_zone = zinit(SMALL_SIZE,
200 round_page(LARGE_SIZE * SMALL_SIZE),
201 round_page(SMALL_SIZE),
202 FALSE,
203 "object small existence maps");
204 zchange(vm_object_small_existence_map_zone, FALSE, FALSE, TRUE, FALSE);
205
206 vm_object_large_existence_map_zone = zinit(LARGE_SIZE,
207 round_page(8 * LARGE_SIZE),
208 round_page(LARGE_SIZE),
209 FALSE,
210 "object large existence maps");
211 zchange(vm_object_large_existence_map_zone, FALSE, FALSE, TRUE, FALSE);
212 }
Cache object: 3857f740ec69c3b6b3adb055998bc4e7
|