Changeset 086a600 in mainline
- Timestamp:
- 2006-02-02T23:54:42Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fb10289b
- Parents:
- 4a5b2b0e
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/mm/frame.c
r4a5b2b0e r086a600 116 116 zone_t *zone = NULL; 117 117 frame_t *frame = NULL; 118 int freed; 118 119 __address v; 119 120 … … 136 137 /* If no memory, reclaim some slab memory, 137 138 if it does not help, reclaim all */ 138 if (!zone && !(flags & FRAME_NO_RECLAIM)) 139 if (slab_reclaim(0) || slab_reclaim(SLAB_RECLAIM_ALL)) 139 if (!zone && !(flags & FRAME_NO_RECLAIM)) { 140 spinlock_unlock(&zone_head_lock); 141 freed = slab_reclaim(0); 142 spinlock_lock(&zone_head_lock); 143 if (freed) 140 144 zone = find_free_zone(order); 145 if (!zone) { 146 spinlock_unlock(&zone_head_lock); 147 freed = slab_reclaim(SLAB_RECLAIM_ALL); 148 spinlock_lock(&zone_head_lock); 149 if (freed) 150 zone = find_free_zone(order); 151 } 152 } 141 153 } 142 154 -
generic/src/mm/slab.c
r4a5b2b0e r086a600 76 76 return NULL; 77 77 } 78 if (! cache->flags & SLAB_CACHE_SLINSIDE) {78 if (! (cache->flags & SLAB_CACHE_SLINSIDE)) { 79 79 slab = malloc(sizeof(*slab)); // , flags); 80 80 if (!slab) { … … 103 103 104 104 atomic_inc(&cache->allocated_slabs); 105 106 105 return slab; 107 106 } … … 115 114 { 116 115 frame_free((__address)slab->start); 117 if (! cache->flags & SLAB_CACHE_SLINSIDE)116 if (! (cache->flags & SLAB_CACHE_SLINSIDE)) 118 117 free(slab); 119 118 … … 278 277 /* Free current magazine and take one from list */ 279 278 slab_free(&mag_cache, mag); 279 280 280 mag = list_get_instance(cache->magazines.next, 281 281 slab_magazine_t, … … 297 297 298 298 /** 299 * Put object into CPU-cache magazine 299 * Assure that the current magazine is empty, return pointer to it, or NULL if 300 * no empty magazine available and cannot be allocated 300 301 * 301 302 * We have 2 magazines bound to processor. … … 305 306 * allocate new, exchange last & current 306 307 * 308 */ 309 static slab_magazine_t * make_empty_current_mag(slab_cache_t *cache) 310 { 311 slab_magazine_t *cmag,*lastmag,*newmag; 312 313 cmag = cache->mag_cache[CPU->id].current; 314 lastmag = cache->mag_cache[CPU->id].last; 315 316 if (cmag) { 317 if (cmag->busy < cmag->size) 318 return cmag; 319 if (lastmag && lastmag->busy < lastmag->size) { 320 cache->mag_cache[CPU->id].last = cmag; 321 cache->mag_cache[CPU->id].current = lastmag; 322 return lastmag; 323 } 324 } 325 /* current | last are full | nonexistent, allocate new */ 326 /* We do not want to sleep just because of caching */ 327 /* Especially we do not want reclaiming to start, as 328 * this would deadlock */ 329 newmag = slab_alloc(&mag_cache, FRAME_ATOMIC | FRAME_NO_RECLAIM); 330 if (!newmag) 331 return NULL; 332 newmag->size = SLAB_MAG_SIZE; 333 newmag->busy = 0; 334 335 /* Flush last to magazine list */ 336 if (lastmag) 337 list_prepend(&lastmag->link, &cache->magazines); 338 /* Move current as last, save new as current */ 339 cache->mag_cache[CPU->id].last = cmag; 340 cache->mag_cache[CPU->id].current = newmag; 341 342 return newmag; 343 } 344 345 /** 346 * Put object into CPU-cache magazine 347 * 307 348 * @return 0 - success, -1 - could not get memory 308 349 */ … … 312 353 313 354 spinlock_lock(&cache->mag_cache[CPU->id].lock); 314 315 mag = cache->mag_cache[CPU->id].current; 316 if (!mag) { 317 /* We do not want to sleep just because of caching */ 318 /* Especially we do not want reclaiming to start, as 319 * this would deadlock */ 320 mag = slab_alloc(&mag_cache, FRAME_ATOMIC | FRAME_NO_RECLAIM); 321 if (!mag) /* Allocation failed, give up on caching */ 322 goto errout; 323 324 cache->mag_cache[CPU->id].current = mag; 325 mag->size = SLAB_MAG_SIZE; 326 mag->busy = 0; 327 } else if (mag->busy == mag->size) { 328 /* If the last is full | empty, allocate new */ 329 mag = cache->mag_cache[CPU->id].last; 330 if (!mag || mag->size == mag->busy) { 331 if (mag) 332 list_prepend(&mag->link, &cache->magazines); 333 334 mag = slab_alloc(&mag_cache, FRAME_ATOMIC | FRAME_NO_RECLAIM); 335 if (!mag) 336 goto errout; 337 338 mag->size = SLAB_MAG_SIZE; 339 mag->busy = 0; 340 cache->mag_cache[CPU->id].last = mag; 341 } 342 /* Exchange the 2 */ 343 cache->mag_cache[CPU->id].last = cache->mag_cache[CPU->id].current; 344 cache->mag_cache[CPU->id].current = mag; 345 } 355 356 mag = make_empty_current_mag(cache); 357 if (!mag) 358 goto errout; 359 346 360 mag->objs[mag->busy++] = obj; 347 361 … … 409 423 list_initialize(&cache->magazines); 410 424 spinlock_initialize(&cache->lock, "cachelock"); 411 if (! cache->flags & SLAB_CACHE_NOMAGAZINE) {425 if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) { 412 426 for (i=0; i< config.cpu_count; i++) 413 427 spinlock_initialize(&cache->mag_cache[i].lock, … … 458 472 * @param flags If contains SLAB_RECLAIM_ALL, do aggressive freeing 459 473 * @return Number of freed pages 460 *461 * TODO: Add light reclaim462 474 */ 463 475 static count_t _slab_reclaim(slab_cache_t *cache, int flags) … … 494 506 cur=cache->magazines.prev; 495 507 496 while (cur !=&cache->magazines) {508 while (cur != &cache->magazines) { 497 509 mag = list_get_instance(cur, slab_magazine_t, link); 498 510 499 511 cur = cur->prev; 500 list_remove(cur->next); 501 // list_remove(&mag->link); 512 list_remove(&mag->link); 502 513 frames += magazine_destroy(cache,mag); 503 514 /* If we do not do full reclaim, break … … 545 556 ipl = interrupts_disable(); 546 557 547 if (! cache->flags & SLAB_CACHE_NOMAGAZINE)558 if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) 548 559 result = magazine_obj_get(cache); 549 560 -
test/mm/slab1/test.c
r4a5b2b0e r086a600 33 33 #include <arch.h> 34 34 #include <panic.h> 35 #include <memstr.h> 35 36 36 37 #define VAL_COUNT 1024 … … 51 52 for (i=0; i < count; i++) { 52 53 data[i] = slab_alloc(cache, 0); 54 memsetb((__address)data[i], size, 0); 53 55 } 54 56 printf("done.\n"); … … 62 64 for (i=0; i < count; i++) { 63 65 data[i] = slab_alloc(cache, 0); 66 memsetb((__address)data[i], size, 0); 64 67 } 65 68 printf("done.\n"); … … 75 78 for (i=count/2; i < count; i++) { 76 79 data[i] = slab_alloc(cache, 0); 80 memsetb((__address)data[i], size, 0); 77 81 } 78 82 printf("done.\n"); -
test/mm/slab2/test.c
r4a5b2b0e r086a600 34 34 #include <panic.h> 35 35 #include <mm/frame.h> 36 #include <memstr.h> 36 37 37 38 #define ITEM_SIZE 256 … … 65 66 break; 66 67 } 67 68 memsetb((__address)data1, ITEM_SIZE, 0); 69 memsetb((__address)data2, ITEM_SIZE, 0); 68 70 *((void **)data1) = olddata1; 69 71 *((void **)data2) = olddata2; … … 89 91 panic("Incorrect memory size - use another test."); 90 92 } 93 memsetb((__address)data1, ITEM_SIZE, 0); 91 94 *((void **)data1) = olddata1; 92 95 olddata1 = data1; … … 98 101 break; 99 102 } 103 memsetb((__address)data1, ITEM_SIZE, 0); 100 104 *((void **)data1) = olddata1; 101 105 olddata1 = data1; 102 106 } 103 107 slab_print_list(); 104 108 printf("Deallocating cache1..."); 109 while (olddata1) { 110 data1 = *((void **)olddata1); 111 slab_free(cache1, olddata1); 112 olddata1 = data1; 113 } 114 printf("done.\n"); 115 slab_print_list(); 116 slab_cache_destroy(cache1); 117 slab_cache_destroy(cache2); 105 118 } 106 119 107 120 void test(void) 108 121 { 122 printf("Running reclaim test .. pass1\n"); 109 123 totalmemtest(); 124 printf("Running reclaim test .. pass2\n"); 125 totalmemtest(); 126 printf("Reclaim test OK.\n"); 110 127 }
Note:
See TracChangeset
for help on using the changeset viewer.