Annotation of Gnu-Mach/vm/vm_external.c, revision 1.1.1.3

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: 
1.1.1.3 ! root       59: vm_external_t  vm_external_create(vm_offset_t size)
1.1       root       60: {
                     61:        vm_external_t   result;
                     62:        vm_size_t       bytes;
                     63:        
1.1.1.2   root       64:        result = (vm_external_t) kmem_cache_alloc(&vm_external_cache);
1.1       root       65:        result->existence_map = (char *) 0;
                     66: 
                     67:        bytes = (atop(size) + 07) >> 3;
                     68:        if (bytes <= SMALL_SIZE) {
                     69:                result->existence_map =
1.1.1.2   root       70:                 (char *) kmem_cache_alloc(&vm_object_small_existence_map_cache);
1.1       root       71:                result->existence_size = SMALL_SIZE;
                     72:        } else if (bytes <= LARGE_SIZE) {
                     73:                result->existence_map =
1.1.1.2   root       74:                 (char *) kmem_cache_alloc(&vm_object_large_existence_map_cache);
1.1       root       75:                result->existence_size = LARGE_SIZE;
                     76:        }
                     77:        return(result);
                     78: }
                     79: 
1.1.1.3 ! root       80: void           vm_external_destroy(vm_external_t e)
1.1       root       81: {
                     82:        if (e == VM_EXTERNAL_NULL)
                     83:                return;
                     84: 
                     85:        if (e->existence_map != (char *) 0) {
                     86:                if (e->existence_size <= SMALL_SIZE) {
1.1.1.2   root       87:                        kmem_cache_free(&vm_object_small_existence_map_cache,
1.1       root       88:                                (vm_offset_t) e->existence_map);
                     89:                } else {
1.1.1.2   root       90:                        kmem_cache_free(&vm_object_large_existence_map_cache,
1.1       root       91:                                (vm_offset_t) e->existence_map);
                     92:                }
                     93:        }
1.1.1.2   root       94:        kmem_cache_free(&vm_external_cache, (vm_offset_t) e);
1.1       root       95: }
                     96: 
                     97: vm_external_state_t _vm_external_state_get(e, offset)
1.1.1.3 ! root       98:        const vm_external_t     e;
        !            99:        vm_offset_t             offset;
1.1       root      100: {
                    101:        unsigned
                    102:        int             bit, byte;
                    103: 
                    104:        if (vm_external_unsafe ||
                    105:            (e == VM_EXTERNAL_NULL) ||
                    106:            (e->existence_map == (char *) 0))
                    107:                return(VM_EXTERNAL_STATE_UNKNOWN);
                    108: 
                    109:        bit = atop(offset);
                    110:        byte = bit >> 3;
                    111:        if (byte >= e->existence_size) return (VM_EXTERNAL_STATE_UNKNOWN);
                    112:        return( (e->existence_map[byte] & (1 << (bit & 07))) ?
                    113:                VM_EXTERNAL_STATE_EXISTS : VM_EXTERNAL_STATE_ABSENT );
                    114: }
                    115: 
1.1.1.3 ! root      116: void           vm_external_state_set(
        !           117:        vm_external_t           e,
        !           118:        vm_offset_t             offset,
        !           119:        vm_external_state_t     state)
1.1       root      120: {
                    121:        unsigned
                    122:        int             bit, byte;
                    123: 
                    124:        if ((e == VM_EXTERNAL_NULL) || (e->existence_map == (char *) 0))
                    125:                return;
                    126: 
                    127:        if (state != VM_EXTERNAL_STATE_EXISTS)
                    128:                return;
                    129: 
                    130:        bit = atop(offset);
                    131:        byte = bit >> 3;
                    132:        if (byte >= e->existence_size) return;
                    133:        e->existence_map[byte] |= (1 << (bit & 07));
                    134: }
                    135: 
1.1.1.2   root      136: void           vm_external_module_initialize(void)
1.1       root      137: {
                    138:        vm_size_t       size = (vm_size_t) sizeof(struct vm_external);
                    139: 
1.1.1.2   root      140:        kmem_cache_init(&vm_external_cache, "vm_external", size, 0,
                    141:                        NULL, NULL, NULL, 0);
1.1       root      142: 
1.1.1.2   root      143:        kmem_cache_init(&vm_object_small_existence_map_cache,
                    144:                        "small_existence_map", SMALL_SIZE, 0,
                    145:                        NULL, NULL, NULL, 0);
                    146: 
                    147:        kmem_cache_init(&vm_object_large_existence_map_cache,
                    148:                        "large_existence_map", LARGE_SIZE, 0,
                    149:                        NULL, NULL, NULL, 0);
1.1       root      150: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.