|
|
1.1 ! root 1: /* ! 2: * Mach Operating System ! 3: * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University. ! 4: * Copyright (c) 1993,1994 The University of Utah and ! 5: * the Computer Systems Laboratory (CSL). ! 6: * All rights reserved. ! 7: * ! 8: * Permission to use, copy, modify and distribute this software and its ! 9: * documentation is hereby granted, provided that both the copyright ! 10: * notice and this permission notice appear in all copies of the ! 11: * software, derivative works or modified versions, and any portions ! 12: * thereof, and that both notices appear in supporting documentation. ! 13: * ! 14: * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF ! 15: * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY ! 16: * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF ! 17: * THIS SOFTWARE. ! 18: * ! 19: * Carnegie Mellon requests users of this software to return to ! 20: * ! 21: * Software Distribution Coordinator or [email protected] ! 22: * School of Computer Science ! 23: * Carnegie Mellon University ! 24: * Pittsburgh PA 15213-3890 ! 25: * ! 26: * any improvements or extensions that they make and grant Carnegie Mellon ! 27: * the rights to redistribute these changes. ! 28: */ ! 29: /* ! 30: * File: zalloc.h ! 31: * Author: Avadis Tevanian, Jr. ! 32: * Date: 1985 ! 33: * ! 34: */ ! 35: ! 36: #ifndef _KERN_ZALLOC_H_ ! 37: #define _KERN_ZALLOC_H_ ! 38: ! 39: #include <mach/machine/vm_types.h> ! 40: #include <kern/macro_help.h> ! 41: #include <kern/lock.h> ! 42: #include <kern/queue.h> ! 43: #include <machine/zalloc.h> ! 44: ! 45: /* ! 46: * A zone is a collection of fixed size blocks for which there ! 47: * is fast allocation/deallocation access. Kernel routines can ! 48: * use zones to manage data structures dynamically, creating a zone ! 49: * for each type of data structure to be managed. ! 50: * ! 51: */ ! 52: ! 53: struct zone { ! 54: decl_simple_lock_data(,lock) /* generic lock */ ! 55: #ifdef ZONE_COUNT ! 56: int count; /* Number of elements used now */ ! 57: #endif ! 58: vm_offset_t free_elements; ! 59: vm_size_t cur_size; /* current memory utilization */ ! 60: vm_size_t max_size; /* how large can this zone grow */ ! 61: vm_size_t elem_size; /* size of an element */ ! 62: vm_size_t alloc_size; /* size used for more memory */ ! 63: boolean_t doing_alloc; /* is zone expanding now? */ ! 64: char *zone_name; /* a name for the zone */ ! 65: unsigned int type; /* type of memory */ ! 66: lock_data_t complex_lock; /* Lock for pageable zones */ ! 67: struct zone *next_zone; /* Link for all-zones list */ ! 68: }; ! 69: typedef struct zone *zone_t; ! 70: ! 71: #define ZONE_NULL ((zone_t) 0) ! 72: ! 73: /* Exported to everyone */ ! 74: zone_t zinit(vm_size_t size, vm_size_t max, vm_size_t alloc, ! 75: unsigned int memtype, char *name); ! 76: vm_offset_t zalloc(zone_t zone); ! 77: vm_offset_t zget(zone_t zone); ! 78: void zfree(zone_t zone, vm_offset_t elem); ! 79: void zcram(zone_t zone, vm_offset_t newmem, vm_size_t size); ! 80: ! 81: /* Exported only to vm/vm_init.c */ ! 82: void zone_bootstrap(); ! 83: void zone_init(); ! 84: ! 85: /* Exported only to vm/vm_pageout.c */ ! 86: void consider_zone_gc(); ! 87: ! 88: ! 89: /* Memory type bits for zones */ ! 90: #define ZONE_PAGEABLE 0x00000001 ! 91: #define ZONE_COLLECTABLE 0x00000002 /* Garbage-collect this zone when memory runs low */ ! 92: #define ZONE_EXHAUSTIBLE 0x00000004 /* zalloc() on this zone is allowed to fail */ ! 93: #define ZONE_FIXED 0x00000008 /* Panic if zone is exhausted (XXX) */ ! 94: ! 95: /* Machine-dependent code can provide additional memory types. */ ! 96: #define ZONE_MACHINE_TYPES 0xffff0000 ! 97: ! 98: ! 99: #ifdef ZONE_COUNT ! 100: #define zone_count_up(zone) ((zone)->count++) ! 101: #define zone_count_down(zone) ((zone)->count--) ! 102: #else ! 103: #define zone_count_up(zone) ! 104: #define zone_count_down(zone) ! 105: #endif ! 106: ! 107: ! 108: ! 109: /* These quick inline versions only work for small, nonpageable zones (currently). */ ! 110: ! 111: static __inline vm_offset_t ZALLOC(zone_t zone) ! 112: { ! 113: simple_lock(&zone->lock); ! 114: if (zone->free_elements == 0) { ! 115: simple_unlock(&zone->lock); ! 116: return zalloc(zone); ! 117: } else { ! 118: vm_offset_t element = zone->free_elements; ! 119: zone->free_elements = *((vm_offset_t *)(element)); ! 120: zone_count_up(zone); ! 121: simple_unlock(&zone->lock); ! 122: return element; ! 123: } ! 124: } ! 125: ! 126: static __inline void ZFREE(zone_t zone, vm_offset_t element) ! 127: { ! 128: *((vm_offset_t *)(element)) = zone->free_elements; ! 129: zone->free_elements = (vm_offset_t) (element); ! 130: zone_count_down(zone); ! 131: } ! 132: ! 133: ! 134: ! 135: #endif _KERN_ZALLOC_H_
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.