|
|
1.1 root 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 [email protected]
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: * This module maintains information about the presence of
28: * pages not in memory. Since an external memory object
29: * must maintain a complete knowledge of its contents, this
30: * information takes the form of hints.
31: */
32:
33: #include <mach/boolean.h>
34: #include <kern/zalloc.h>
35: #include <vm/vm_external.h>
36: #include <mach/vm_param.h>
37: #include <kern/assert.h>
38:
39:
40:
41: boolean_t vm_external_unsafe = FALSE;
42:
43: zone_t vm_external_zone = ZONE_NULL;
44:
45: /*
46: * The implementation uses bit arrays to record whether
47: * a page has been written to external storage. For
48: * convenience, these bit arrays come in two sizes
49: * (measured in bytes).
50: */
51:
52: #define SMALL_SIZE (VM_EXTERNAL_SMALL_SIZE/8)
53: #define LARGE_SIZE (VM_EXTERNAL_LARGE_SIZE/8)
54:
55: zone_t vm_object_small_existence_map_zone;
56: zone_t vm_object_large_existence_map_zone;
57:
58:
59: vm_external_t vm_external_create(size)
60: vm_offset_t size;
61: {
62: vm_external_t result;
63: vm_size_t bytes;
64:
65: if (vm_external_zone == ZONE_NULL)
66: return(VM_EXTERNAL_NULL);
67:
68: result = (vm_external_t) zalloc(vm_external_zone);
69: result->existence_map = (char *) 0;
70:
71: bytes = (atop(size) + 07) >> 3;
72: if (bytes <= SMALL_SIZE) {
73: result->existence_map =
74: (char *) zalloc(vm_object_small_existence_map_zone);
75: result->existence_size = SMALL_SIZE;
76: } else if (bytes <= LARGE_SIZE) {
77: result->existence_map =
78: (char *) zalloc(vm_object_large_existence_map_zone);
79: result->existence_size = LARGE_SIZE;
80: }
81: return(result);
82: }
83:
84: void vm_external_destroy(e)
85: vm_external_t e;
86: {
87: if (e == VM_EXTERNAL_NULL)
88: return;
89:
90: if (e->existence_map != (char *) 0) {
91: if (e->existence_size <= SMALL_SIZE) {
92: zfree(vm_object_small_existence_map_zone,
93: (vm_offset_t) e->existence_map);
94: } else {
95: zfree(vm_object_large_existence_map_zone,
96: (vm_offset_t) e->existence_map);
97: }
98: }
99: zfree(vm_external_zone, (vm_offset_t) e);
100: }
101:
102: vm_external_state_t _vm_external_state_get(e, offset)
103: vm_external_t e;
104: vm_offset_t offset;
105: {
106: unsigned
107: int bit, byte;
108:
109: if (vm_external_unsafe ||
110: (e == VM_EXTERNAL_NULL) ||
111: (e->existence_map == (char *) 0))
112: return(VM_EXTERNAL_STATE_UNKNOWN);
113:
114: bit = atop(offset);
115: byte = bit >> 3;
116: if (byte >= e->existence_size) return (VM_EXTERNAL_STATE_UNKNOWN);
117: return( (e->existence_map[byte] & (1 << (bit & 07))) ?
118: VM_EXTERNAL_STATE_EXISTS : VM_EXTERNAL_STATE_ABSENT );
119: }
120:
121: void vm_external_state_set(e, offset, state)
122: vm_external_t e;
123: vm_offset_t offset;
124: vm_external_state_t state;
125: {
126: unsigned
127: int bit, byte;
128:
129: if ((e == VM_EXTERNAL_NULL) || (e->existence_map == (char *) 0))
130: return;
131:
132: if (state != VM_EXTERNAL_STATE_EXISTS)
133: return;
134:
135: bit = atop(offset);
136: byte = bit >> 3;
137: if (byte >= e->existence_size) return;
138: e->existence_map[byte] |= (1 << (bit & 07));
139: }
140:
141: void vm_external_module_initialize()
142: {
143: vm_size_t size = (vm_size_t) sizeof(struct vm_external);
144:
145: vm_external_zone = zinit(size, 16*1024*size, size,
146: 0, "external page bitmaps");
147:
148: vm_object_small_existence_map_zone = zinit(SMALL_SIZE,
149: round_page(LARGE_SIZE * SMALL_SIZE),
150: round_page(SMALL_SIZE),
151: ZONE_EXHAUSTIBLE,
152: "object small existence maps");
153:
154: vm_object_large_existence_map_zone = zinit(LARGE_SIZE,
155: round_page(8 * LARGE_SIZE),
156: round_page(LARGE_SIZE),
157: ZONE_EXHAUSTIBLE,
158: "object large existence maps");
159: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.