Changeset ce8aed1 in mainline for kernel/generic/src/mm/slab.c
- Timestamp:
- 2007-02-11T18:15:09Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bd1deed
- Parents:
- 3c771149
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/slab.c
r3c771149 rce8aed1 112 112 #include <debug.h> 113 113 #include <bitops.h> 114 #include <macros.h> 114 115 115 116 SPINLOCK_INITIALIZE(slab_cache_lock); … … 128 129 static slab_cache_t *slab_extern_cache; 129 130 /** Caches for malloc */ 130 static slab_cache_t *malloc_caches[SLAB_MAX_MALLOC_W -SLAB_MIN_MALLOC_W+1];131 static slab_cache_t *malloc_caches[SLAB_MAX_MALLOC_W - SLAB_MIN_MALLOC_W + 1]; 131 132 char *malloc_names[] = { 132 "malloc-16","malloc-32","malloc-64","malloc-128", 133 "malloc-256","malloc-512","malloc-1K","malloc-2K", 134 "malloc-4K","malloc-8K","malloc-16K","malloc-32K", 135 "malloc-64K","malloc-128K","malloc-256K" 133 "malloc-16", 134 "malloc-32", 135 "malloc-64", 136 "malloc-128", 137 "malloc-256", 138 "malloc-512", 139 "malloc-1K", 140 "malloc-2K", 141 "malloc-4K", 142 "malloc-8K", 143 "malloc-16K", 144 "malloc-32K", 145 "malloc-64K", 146 "malloc-128K", 147 "malloc-256K" 136 148 }; 137 149 … … 143 155 count_t available; /**< Count of available items in this slab. */ 144 156 index_t nextavail; /**< The index of next available item. */ 145 } slab_t;157 } slab_t; 146 158 147 159 #ifdef CONFIG_DEBUG … … 214 226 static slab_t * obj2slab(void *obj) 215 227 { 216 return (slab_t *) frame_get_parent(ADDR2PFN(KA2PA(obj)), 0);228 return (slab_t *) frame_get_parent(ADDR2PFN(KA2PA(obj)), 0); 217 229 } 218 230 … … 761 773 void slab_free(slab_cache_t *cache, void *obj) 762 774 { 763 _slab_free(cache, obj,NULL);775 _slab_free(cache, obj, NULL); 764 776 } 765 777 … … 879 891 void * malloc(unsigned int size, int flags) 880 892 { 881 int idx;882 883 893 ASSERT(_slab_initialized); 884 894 ASSERT(size && size <= (1 << SLAB_MAX_MALLOC_W)); … … 887 897 size = (1 << SLAB_MIN_MALLOC_W); 888 898 889 i dx = fnzb(size-1) - SLAB_MIN_MALLOC_W + 1;899 int idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1; 890 900 891 901 return slab_alloc(malloc_caches[idx], flags); 892 902 } 893 903 894 void free(void *obj) 895 { 896 slab_t *slab; 897 898 if (!obj) 904 void * realloc(void *ptr, unsigned int size, int flags) 905 { 906 ASSERT(_slab_initialized); 907 ASSERT(size <= (1 << SLAB_MAX_MALLOC_W)); 908 909 void *new_ptr; 910 911 if (size > 0) { 912 if (size < (1 << SLAB_MIN_MALLOC_W)) 913 size = (1 << SLAB_MIN_MALLOC_W); 914 int idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1; 915 916 new_ptr = slab_alloc(malloc_caches[idx], flags); 917 } else 918 new_ptr = NULL; 919 920 if ((new_ptr != NULL) && (ptr != NULL)) { 921 slab_t *slab = obj2slab(ptr); 922 memcpy(new_ptr, ptr, min(size, slab->cache->size)); 923 } 924 925 if (ptr != NULL) 926 free(ptr); 927 928 return new_ptr; 929 } 930 931 void free(void *ptr) 932 { 933 if (!ptr) 899 934 return; 900 935 901 slab = obj2slab(obj);902 _slab_free(slab->cache, obj, slab);936 slab_t *slab = obj2slab(ptr); 937 _slab_free(slab->cache, ptr, slab); 903 938 } 904 939
Note:
See TracChangeset
for help on using the changeset viewer.