|
|
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>
1.1.1.2 ! root 34: #include <kern/slab.h>
1.1 root 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:
1.1.1.2 ! root 43: struct kmem_cache vm_external_cache;
1.1 root 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:
1.1.1.2 ! root 55: struct kmem_cache vm_object_small_existence_map_cache;
! 56: struct kmem_cache vm_object_large_existence_map_cache;
1.1 root 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:
1.1.1.2 ! root 65: result = (vm_external_t) kmem_cache_alloc(&vm_external_cache);
1.1 root 66: result->existence_map = (char *) 0;
67:
68: bytes = (atop(size) + 07) >> 3;
69: if (bytes <= SMALL_SIZE) {
70: result->existence_map =
1.1.1.2 ! root 71: (char *) kmem_cache_alloc(&vm_object_small_existence_map_cache);
1.1 root 72: result->existence_size = SMALL_SIZE;
73: } else if (bytes <= LARGE_SIZE) {
74: result->existence_map =
1.1.1.2 ! root 75: (char *) kmem_cache_alloc(&vm_object_large_existence_map_cache);
1.1 root 76: result->existence_size = LARGE_SIZE;
77: }
78: return(result);
79: }
80:
81: void vm_external_destroy(e)
82: vm_external_t e;
83: {
84: if (e == VM_EXTERNAL_NULL)
85: return;
86:
87: if (e->existence_map != (char *) 0) {
88: if (e->existence_size <= SMALL_SIZE) {
1.1.1.2 ! root 89: kmem_cache_free(&vm_object_small_existence_map_cache,
1.1 root 90: (vm_offset_t) e->existence_map);
91: } else {
1.1.1.2 ! root 92: kmem_cache_free(&vm_object_large_existence_map_cache,
1.1 root 93: (vm_offset_t) e->existence_map);
94: }
95: }
1.1.1.2 ! root 96: kmem_cache_free(&vm_external_cache, (vm_offset_t) e);
1.1 root 97: }
98:
99: vm_external_state_t _vm_external_state_get(e, offset)
100: vm_external_t e;
101: vm_offset_t offset;
102: {
103: unsigned
104: int bit, byte;
105:
106: if (vm_external_unsafe ||
107: (e == VM_EXTERNAL_NULL) ||
108: (e->existence_map == (char *) 0))
109: return(VM_EXTERNAL_STATE_UNKNOWN);
110:
111: bit = atop(offset);
112: byte = bit >> 3;
113: if (byte >= e->existence_size) return (VM_EXTERNAL_STATE_UNKNOWN);
114: return( (e->existence_map[byte] & (1 << (bit & 07))) ?
115: VM_EXTERNAL_STATE_EXISTS : VM_EXTERNAL_STATE_ABSENT );
116: }
117:
118: void vm_external_state_set(e, offset, state)
119: vm_external_t e;
120: vm_offset_t offset;
121: vm_external_state_t state;
122: {
123: unsigned
124: int bit, byte;
125:
126: if ((e == VM_EXTERNAL_NULL) || (e->existence_map == (char *) 0))
127: return;
128:
129: if (state != VM_EXTERNAL_STATE_EXISTS)
130: return;
131:
132: bit = atop(offset);
133: byte = bit >> 3;
134: if (byte >= e->existence_size) return;
135: e->existence_map[byte] |= (1 << (bit & 07));
136: }
137:
1.1.1.2 ! root 138: void vm_external_module_initialize(void)
1.1 root 139: {
140: vm_size_t size = (vm_size_t) sizeof(struct vm_external);
141:
1.1.1.2 ! root 142: kmem_cache_init(&vm_external_cache, "vm_external", size, 0,
! 143: NULL, NULL, NULL, 0);
1.1 root 144:
1.1.1.2 ! root 145: kmem_cache_init(&vm_object_small_existence_map_cache,
! 146: "small_existence_map", SMALL_SIZE, 0,
! 147: NULL, NULL, NULL, 0);
! 148:
! 149: kmem_cache_init(&vm_object_large_existence_map_cache,
! 150: "large_existence_map", LARGE_SIZE, 0,
! 151: NULL, NULL, NULL, 0);
1.1 root 152: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.