Changeset 14e5d88 in mainline
- Timestamp:
- 2006-02-02T21:46:47Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4a5b2b0e
- Parents:
- 086d4fd
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/mm/slab.h
r086d4fd r14e5d88 38 38 39 39 /** If object size is less, store control structure inside SLAB */ 40 #define SLAB_INSIDE_SIZE (PAGE_SIZE / 6)40 #define SLAB_INSIDE_SIZE (PAGE_SIZE >> 3) 41 41 42 42 /** Maximum wasted space we allow for cache */ 43 #define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order ) / 4)43 #define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order >> 2)) 44 44 45 45 /* slab_reclaim constants */ -
generic/src/mm/slab.c
r086d4fd r14e5d88 89 89 /* Fill in slab structures */ 90 90 /* TODO: some better way of accessing the frame */ 91 for (i=0; i < (1<<cache->order); i++) {91 for (i=0; i < (1 << cache->order); i++) { 92 92 frame = ADDR2FRAME(zone, KA2PA((__address)(data+i*PAGE_SIZE))); 93 93 frame->parent = slab; … … 107 107 108 108 /** 109 * Free space associated with SLAB109 * Deallocate space associated with SLAB 110 110 * 111 111 * @return number of freed frames … … 151 151 if (!slab) 152 152 slab = obj2slab(obj); 153 154 spinlock_lock(&cache->lock);155 153 156 154 *((int *)obj) = slab->nextavail; … … 172 170 spinlock_lock(&cache->lock); 173 171 } 174 175 spinlock_unlock(&cache->lock);176 172 177 173 return frames; … … 389 385 cache->name = name; 390 386 391 if (align) 392 size = ALIGN_UP(size, align); 387 if (align < sizeof(__native)) 388 align = sizeof(__native); 389 size = ALIGN_UP(size, align); 390 393 391 cache->size = size; 394 392 … … 412 410 413 411 /* Minimum slab order */ 414 cache->order = (cache->size >> PAGE_WIDTH) + 1;415 412 cache->order = (cache->size-1) >> PAGE_WIDTH; 413 416 414 while (badness(cache) > SLAB_MAX_BADNESS(cache)) { 417 415 cache->order += 1; 418 416 } 419 420 417 cache->objects = comp_objects(cache); 418 /* If info fits in, put it inside */ 419 if (badness(cache) > sizeof(slab_t)) 420 cache->flags |= SLAB_CACHE_SLINSIDE; 421 421 422 422 spinlock_lock(&slab_cache_lock); … … 597 597 598 598 spinlock_lock(&slab_cache_lock); 599 printf("SLAB name\tOsize\t Order\tOcnt\tSlabs\tAllocobjs\n");599 printf("SLAB name\tOsize\tPages\tOcnt\tSlabs\tAllocobjs\tCtl\n"); 600 600 for (cur = slab_cache_list.next;cur!=&slab_cache_list; cur=cur->next) { 601 601 cache = list_get_instance(cur, slab_cache_t, link); 602 printf("%s\t%d\t%d\t%d\t%d\t%d\ n", cache->name, cache->size,603 cache->order, cache->objects,602 printf("%s\t%d\t%d\t%d\t%d\t%d\t\t%s\n", cache->name, cache->size, 603 (1 << cache->order), cache->objects, 604 604 atomic_get(&cache->allocated_slabs), 605 atomic_get(&cache->allocated_objs)); 605 atomic_get(&cache->allocated_objs), 606 cache->flags & SLAB_CACHE_SLINSIDE ? "In" : "Out"); 606 607 } 607 608 spinlock_unlock(&slab_cache_lock); -
test/mm/slab1/test.c
r086d4fd r14e5d88 30 30 #include <mm/slab.h> 31 31 #include <print.h> 32 #include <proc/thread.h> 33 #include <arch.h> 34 #include <panic.h> 32 35 33 #define VAL_SIZE 12834 36 #define VAL_COUNT 1024 35 37 36 void * data[ 16384];38 void * data[VAL_COUNT]; 37 39 38 void test(void)40 static void testit(int size, int count) 39 41 { 40 42 slab_cache_t *cache; 41 43 int i; 42 44 43 44 printf("Creating cache.\n"); 45 cache = slab_cache_create("test_cache", VAL_SIZE, 0, NULL, NULL, SLAB_CACHE_NOMAGAZINE); 46 printf("Destroying cache.\n"); 47 slab_cache_destroy(cache); 48 49 printf("Creating cache.\n"); 50 cache = slab_cache_create("test_cache", VAL_SIZE, 0, NULL, NULL, 45 printf("Creating cache, object size: %d.\n", size); 46 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 51 47 SLAB_CACHE_NOMAGAZINE); 48 slab_print_list(); 52 49 53 printf("Allocating %d items...", VAL_COUNT);54 for (i=0; i < VAL_COUNT; i++) {50 printf("Allocating %d items...", count); 51 for (i=0; i < count; i++) { 55 52 data[i] = slab_alloc(cache, 0); 56 53 } 57 54 printf("done.\n"); 58 printf("Freeing %d items...", VAL_COUNT);59 for (i=0; i < VAL_COUNT; i++) {55 printf("Freeing %d items...", count); 56 for (i=0; i < count; i++) { 60 57 slab_free(cache, data[i]); 61 58 } 62 59 printf("done.\n"); 63 60 64 printf("Allocating %d items...", VAL_COUNT);65 for (i=0; i < VAL_COUNT; i++) {61 printf("Allocating %d items...", count); 62 for (i=0; i < count; i++) { 66 63 data[i] = slab_alloc(cache, 0); 67 64 } … … 69 66 70 67 slab_print_list(); 71 printf("Freeing %d items...", VAL_COUNT/2);72 for (i= VAL_COUNT-1; i >= VAL_COUNT/2; i--) {68 printf("Freeing %d items...", count/2); 69 for (i=count-1; i >= count/2; i--) { 73 70 slab_free(cache, data[i]); 74 71 } 75 72 printf("done.\n"); 76 73 77 printf("Allocating %d items...", VAL_COUNT/2);78 for (i= VAL_COUNT/2; i < VAL_COUNT; i++) {74 printf("Allocating %d items...", count/2); 75 for (i=count/2; i < count; i++) { 79 76 data[i] = slab_alloc(cache, 0); 80 77 } 81 78 printf("done.\n"); 82 printf("Freeing %d items...", VAL_COUNT);83 for (i=0; i < VAL_COUNT; i++) {79 printf("Freeing %d items...", count); 80 for (i=0; i < count; i++) { 84 81 slab_free(cache, data[i]); 85 82 } 86 83 printf("done.\n"); 87 slab_print_list();88 84 slab_cache_destroy(cache); 89 85 90 86 printf("Test complete.\n"); 91 87 } 88 89 static void testsimple(void) 90 { 91 testit(100, VAL_COUNT); 92 testit(200, VAL_COUNT); 93 testit(1024, VAL_COUNT); 94 testit(2048, 512); 95 testit(4000, 128); 96 testit(8192, 128); 97 testit(16384, 128); 98 testit(16385, 128); 99 } 100 101 102 #define THREADS 6 103 #define THR_MEM_COUNT 1024 104 #define THR_MEM_SIZE 128 105 106 void * thr_data[THREADS][THR_MEM_COUNT]; 107 slab_cache_t *thr_cache; 108 semaphore_t thr_sem; 109 110 static void thread(void *data) 111 { 112 int offs = (int)(__native) data; 113 int i,j; 114 115 printf("Starting thread #%d...\n",THREAD->tid); 116 for (j=0; j<10; j++) { 117 for (i=0; i<THR_MEM_COUNT; i++) 118 thr_data[offs][i] = slab_alloc(thr_cache,0); 119 for (i=0; i<THR_MEM_COUNT/2; i++) 120 slab_free(thr_cache, thr_data[offs][i]); 121 for (i=0; i< THR_MEM_COUNT/2; i++) 122 thr_data[offs][i] = slab_alloc(thr_cache, 0); 123 for (i=0; i<THR_MEM_COUNT;i++) 124 slab_free(thr_cache, thr_data[offs][i]); 125 } 126 printf("Thread #%d finished\n", THREAD->tid); 127 slab_print_list(); 128 semaphore_up(&thr_sem); 129 } 130 131 static void testthreads(void) 132 { 133 thread_t *t; 134 int i; 135 136 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, 137 NULL, NULL, 138 SLAB_CACHE_NOMAGAZINE); 139 semaphore_initialize(&thr_sem,0); 140 for (i=0; i<THREADS; i++) { 141 if (!(t = thread_create(thread, (void *)(__native)i, TASK, 0))) 142 panic("could not create thread\n"); 143 thread_ready(t); 144 } 145 146 for (i=0; i<THREADS; i++) 147 semaphore_down(&thr_sem); 148 149 slab_cache_destroy(thr_cache); 150 printf("Test complete.\n"); 151 152 } 153 154 void test(void) 155 { 156 testsimple(); 157 testthreads(); 158 }
Note:
See TracChangeset
for help on using the changeset viewer.