Annotation of OSKit-Mach/kern/zalloc.h, revision 1.1.1.1

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: 
                     44: /*
                     45:  *     A zone is a collection of fixed size blocks for which there
                     46:  *     is fast allocation/deallocation access.  Kernel routines can
                     47:  *     use zones to manage data structures dynamically, creating a zone
                     48:  *     for each type of data structure to be managed.
                     49:  *
                     50:  */
                     51: 
                     52: struct zone {
                     53:        decl_simple_lock_data(,lock)    /* generic lock */
                     54: #ifdef ZONE_COUNT
                     55:        int             count;          /* Number of elements used now */
                     56: #endif
                     57:        vm_offset_t     free_elements;
                     58:        vm_size_t       cur_size;       /* current memory utilization */
                     59:        vm_size_t       max_size;       /* how large can this zone grow */
                     60:        vm_size_t       elem_size;      /* size of an element */
                     61:        vm_size_t       alloc_size;     /* size used for more memory */
                     62:        boolean_t       doing_alloc;    /* is zone expanding now? */
                     63:        char            *zone_name;     /* a name for the zone */
                     64:        unsigned int    type;           /* type of memory */
                     65:        lock_data_t     complex_lock;   /* Lock for pageable zones */
                     66:        struct zone     *next_zone;     /* Link for all-zones list */
                     67: };
                     68: typedef struct zone *zone_t;
                     69: 
                     70: #define                ZONE_NULL       ((zone_t) 0)
                     71: 
                     72: /* Exported to everyone */
                     73: zone_t         zinit(vm_size_t size, vm_size_t max, vm_size_t alloc,
                     74:                      unsigned int memtype, char *name);
                     75: vm_offset_t    zalloc(zone_t zone);
                     76: vm_offset_t    zget(zone_t zone);
                     77: void           zfree(zone_t zone, vm_offset_t elem);
                     78: void           zcram(zone_t zone, vm_offset_t newmem, vm_size_t size);
                     79: 
                     80: /* Exported only to vm/vm_init.c */
                     81: void           zone_bootstrap();
                     82: void           zone_init();
                     83: 
                     84: /* Exported only to vm/vm_pageout.c */
                     85: void           consider_zone_gc();
                     86: 
                     87: 
                     88: /* Memory type bits for zones */
                     89: #define ZONE_PAGEABLE          0x00000001
                     90: #define ZONE_COLLECTABLE       0x00000002      /* Garbage-collect this zone when memory runs low */
                     91: #define ZONE_EXHAUSTIBLE       0x00000004      /* zalloc() on this zone is allowed to fail */
                     92: #define ZONE_FIXED             0x00000008      /* Panic if zone is exhausted (XXX) */
                     93: 
                     94: /* Machine-dependent code can provide additional memory types.  */
                     95: #define ZONE_MACHINE_TYPES     0xffff0000
                     96: 
                     97: 
                     98: #ifdef ZONE_COUNT
                     99: #define zone_count_up(zone) ((zone)->count++)
                    100: #define zone_count_down(zone) ((zone)->count--)
                    101: #else
                    102: #define zone_count_up(zone)
                    103: #define zone_count_down(zone)
                    104: #endif
                    105: 
                    106: 
                    107: 
                    108: /* These quick inline versions only work for small, nonpageable zones (currently).  */
                    109: 
                    110: static __inline vm_offset_t ZALLOC(zone_t zone)
                    111: {
                    112:        simple_lock(&zone->lock);
                    113:        if (zone->free_elements == 0) {
                    114:                simple_unlock(&zone->lock);
                    115:                return zalloc(zone);
                    116:        } else {
                    117:                vm_offset_t element = zone->free_elements;
                    118:                zone->free_elements = *((vm_offset_t *)(element));
                    119:                zone_count_up(zone);
                    120:                simple_unlock(&zone->lock);
                    121:                return element;
                    122:        }
                    123: }
                    124: 
                    125: static __inline void ZFREE(zone_t zone, vm_offset_t element)
                    126: {
                    127:        *((vm_offset_t *)(element)) = zone->free_elements;
                    128:        zone->free_elements = (vm_offset_t) (element);
                    129:        zone_count_down(zone);
                    130: }
                    131: 
                    132: 
                    133: 
                    134: #endif /* _KERN_ZALLOC_H_ */

unix.superglobalmegacorp.com

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