slab.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __SLAB_H__
00036 #define __SLAB_H__
00037 
00038 #include <adt/list.h>
00039 #include <synch/spinlock.h>
00040 #include <atomic.h>
00041 #include <mm/frame.h>
00042 
00044 #define SLAB_MIN_MALLOC_W 4
00045 
00047 #define SLAB_MAX_MALLOC_W 18
00048 
00050 #define SLAB_MAG_SIZE  4
00051 
00053 #define SLAB_INSIDE_SIZE   (PAGE_SIZE >> 3)
00054 
00056 #define SLAB_MAX_BADNESS(cache)   ((PAGE_SIZE << (cache)->order) >> 2)
00057 
00058 /* slab_reclaim constants */
00059 #define SLAB_RECLAIM_ALL  0x1 
00062 /* cache_create flags */
00063 #define SLAB_CACHE_NOMAGAZINE 0x1 
00064 #define SLAB_CACHE_SLINSIDE   0x2 
00066 #define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE)
00067 
00068 typedef struct {
00069         link_t link;
00070         count_t busy;  
00071         count_t size;  
00072         void *objs[0]; 
00073 }slab_magazine_t;
00074 
00075 typedef struct {
00076         slab_magazine_t *current;
00077         slab_magazine_t *last;
00078         SPINLOCK_DECLARE(lock);
00079 }slab_mag_cache_t;
00080 
00081 
00082 typedef struct {
00083         char *name;
00084 
00085         link_t link;
00086         /* Configuration */
00087         size_t size;      
00088         int (*constructor)(void *obj, int kmflag);
00089         int (*destructor)(void *obj);
00090         int flags;        
00092         /* Computed values */
00093         __u8 order;        
00094         int objects;      
00096         /* Statistics */
00097         atomic_t allocated_slabs;
00098         atomic_t allocated_objs;
00099         atomic_t cached_objs;
00100         atomic_t magazine_counter; 
00102         /* Slabs */
00103         link_t full_slabs;     
00104         link_t partial_slabs;  
00105         SPINLOCK_DECLARE(slablock);
00106         /* Magazines  */
00107         link_t magazines;      
00108         SPINLOCK_DECLARE(maglock);
00109 
00111         slab_mag_cache_t *mag_cache;
00112 }slab_cache_t;
00113 
00114 extern slab_cache_t * slab_cache_create(char *name,
00115                                         size_t size,
00116                                         size_t align,
00117                                         int (*constructor)(void *obj, int kmflag),
00118                                         int (*destructor)(void *obj),
00119                                         int flags);
00120 extern void slab_cache_destroy(slab_cache_t *cache);
00121 
00122 extern void * slab_alloc(slab_cache_t *cache, int flags);
00123 extern void slab_free(slab_cache_t *cache, void *obj);
00124 extern count_t slab_reclaim(int flags);
00125 
00127 extern void slab_cache_init(void);
00128 extern void slab_enable_cpucache(void);
00129 
00130 /* kconsole debug */
00131 extern void slab_print_list(void);
00132 
00133 /* malloc support */
00134 extern void * malloc(unsigned int size, int flags);
00135 extern void free(void *obj);
00136 #endif
00137 

Generated on Sun Jun 18 17:28:03 2006 for HelenOS Kernel (ppc64) by  doxygen 1.4.6