Rev 766 | Rev 768 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 766 | Rev 767 | ||
---|---|---|---|
Line 94... | Line 94... | ||
94 | } |
94 | } |
95 | 95 | ||
96 | slab->start = data; |
96 | slab->start = data; |
97 | slab->available = cache->objects; |
97 | slab->available = cache->objects; |
98 | slab->nextavail = 0; |
98 | slab->nextavail = 0; |
- | 99 | slab->cache = cache; |
|
99 | 100 | ||
100 | for (i=0; i<cache->objects;i++) |
101 | for (i=0; i<cache->objects;i++) |
101 | *((int *) (slab->start + i*cache->size)) = i+1; |
102 | *((int *) (slab->start + i*cache->size)) = i+1; |
102 | 103 | ||
103 | atomic_inc(&cache->allocated_slabs); |
104 | atomic_inc(&cache->allocated_slabs); |
Line 149... | Line 150... | ||
149 | count_t frames = 0; |
150 | count_t frames = 0; |
150 | 151 | ||
151 | if (!slab) |
152 | if (!slab) |
152 | slab = obj2slab(obj); |
153 | slab = obj2slab(obj); |
153 | 154 | ||
- | 155 | ASSERT(slab->cache == cache); |
|
- | 156 | ||
154 | *((int *)obj) = slab->nextavail; |
157 | *((int *)obj) = slab->nextavail; |
155 | slab->nextavail = (obj - slab->start)/cache->size; |
158 | slab->nextavail = (obj - slab->start)/cache->size; |
156 | slab->available++; |
159 | slab->available++; |
157 | 160 | ||
158 | /* Move it to correct list */ |
161 | /* Move it to correct list */ |
Line 228... | Line 231... | ||
228 | slab_magazine_t *mag) |
231 | slab_magazine_t *mag) |
229 | { |
232 | { |
230 | int i; |
233 | int i; |
231 | count_t frames = 0; |
234 | count_t frames = 0; |
232 | 235 | ||
233 | for (i=0;i < mag->busy; i++) |
236 | for (i=0;i < mag->busy; i++) { |
234 | frames += slab_obj_destroy(cache, mag->objs[i], NULL); |
237 | frames += slab_obj_destroy(cache, mag->objs[i], NULL); |
- | 238 | atomic_dec(&cache->cached_objs); |
|
- | 239 | } |
|
235 | 240 | ||
236 | slab_free(&mag_cache, mag); |
241 | slab_free(&mag_cache, mag); |
237 | 242 | ||
238 | return frames; |
243 | return frames; |
239 | } |
244 | } |
Line 244... | Line 249... | ||
244 | * @return Pointer to object or NULL if not available |
249 | * @return Pointer to object or NULL if not available |
245 | */ |
250 | */ |
246 | static void * magazine_obj_get(slab_cache_t *cache) |
251 | static void * magazine_obj_get(slab_cache_t *cache) |
247 | { |
252 | { |
248 | slab_magazine_t *mag; |
253 | slab_magazine_t *mag; |
- | 254 | void *obj; |
|
249 | 255 | ||
250 | spinlock_lock(&cache->mag_cache[CPU->id].lock); |
256 | spinlock_lock(&cache->mag_cache[CPU->id].lock); |
251 | 257 | ||
252 | mag = cache->mag_cache[CPU->id].current; |
258 | mag = cache->mag_cache[CPU->id].current; |
253 | if (!mag) |
259 | if (!mag) |
Line 277... | Line 283... | ||
277 | list_remove(&mag->link); |
283 | list_remove(&mag->link); |
278 | 284 | ||
279 | spinlock_unlock(&cache->lock); |
285 | spinlock_unlock(&cache->lock); |
280 | } |
286 | } |
281 | gotit: |
287 | gotit: |
- | 288 | obj = mag->objs[--mag->busy]; |
|
282 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
289 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
- | 290 | atomic_dec(&cache->cached_objs); |
|
- | 291 | ||
283 | return mag->objs[--mag->busy]; |
292 | return obj; |
284 | out: |
293 | out: |
285 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
294 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
286 | return NULL; |
295 | return NULL; |
287 | } |
296 | } |
288 | 297 | ||
Line 335... | Line 344... | ||
335 | cache->mag_cache[CPU->id].current = mag; |
344 | cache->mag_cache[CPU->id].current = mag; |
336 | } |
345 | } |
337 | mag->objs[mag->busy++] = obj; |
346 | mag->objs[mag->busy++] = obj; |
338 | 347 | ||
339 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
348 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
- | 349 | atomic_inc(&cache->cached_objs); |
|
340 | return 0; |
350 | return 0; |
341 | errout: |
351 | errout: |
342 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
352 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
343 | return -1; |
353 | return -1; |
344 | } |
354 | } |
Line 465... | Line 475... | ||
465 | spinlock_lock(&cache->mag_cache[i].lock); |
475 | spinlock_lock(&cache->mag_cache[i].lock); |
466 | spinlock_lock(&cache->lock); |
476 | spinlock_lock(&cache->lock); |
467 | 477 | ||
468 | if (flags & SLAB_RECLAIM_ALL) { |
478 | if (flags & SLAB_RECLAIM_ALL) { |
469 | /* Aggressive memfree */ |
479 | /* Aggressive memfree */ |
470 | - | ||
471 | /* Destroy CPU magazines */ |
480 | /* Destroy CPU magazines */ |
472 | for (i=0; i<config.cpu_count; i++) { |
481 | for (i=0; i<config.cpu_count; i++) { |
473 | mag = cache->mag_cache[i].current; |
482 | mag = cache->mag_cache[i].current; |
474 | if (mag) |
483 | if (mag) |
475 | frames += magazine_destroy(cache, mag); |
484 | frames += magazine_destroy(cache, mag); |
Line 481... | Line 490... | ||
481 | cache->mag_cache[i].last = NULL; |
490 | cache->mag_cache[i].last = NULL; |
482 | } |
491 | } |
483 | } |
492 | } |
484 | /* Destroy full magazines */ |
493 | /* Destroy full magazines */ |
485 | cur=cache->magazines.prev; |
494 | cur=cache->magazines.prev; |
- | 495 | ||
486 | while (cur!=&cache->magazines) { |
496 | while (cur!=&cache->magazines) { |
487 | mag = list_get_instance(cur, slab_magazine_t, link); |
497 | mag = list_get_instance(cur, slab_magazine_t, link); |
488 | 498 | ||
489 | cur = cur->prev; |
499 | cur = cur->prev; |
490 | list_remove(cur->next); |
500 | list_remove(cur->next); |
- | 501 | // list_remove(&mag->link); |
|
491 | frames += magazine_destroy(cache,mag); |
502 | frames += magazine_destroy(cache,mag); |
492 | /* If we do not do full reclaim, break |
503 | /* If we do not do full reclaim, break |
493 | * as soon as something is freed */ |
504 | * as soon as something is freed */ |
494 | if (!(flags & SLAB_RECLAIM_ALL) && frames) |
505 | if (!(flags & SLAB_RECLAIM_ALL) && frames) |
495 | break; |
506 | break; |
Line 594... | Line 605... | ||
594 | { |
605 | { |
595 | slab_cache_t *cache; |
606 | slab_cache_t *cache; |
596 | link_t *cur; |
607 | link_t *cur; |
597 | 608 | ||
598 | spinlock_lock(&slab_cache_lock); |
609 | spinlock_lock(&slab_cache_lock); |
599 | printf("SLAB name\tOsize\tPages\tOcnt\tSlabs\tAllocobjs\tCtl\n"); |
610 | printf("SLAB name\tOsize\tPages\tObj/pg\tSlabs\tCached\tAllocobjs\tCtl\n"); |
600 | for (cur = slab_cache_list.next;cur!=&slab_cache_list; cur=cur->next) { |
611 | for (cur = slab_cache_list.next;cur!=&slab_cache_list; cur=cur->next) { |
601 | cache = list_get_instance(cur, slab_cache_t, link); |
612 | cache = list_get_instance(cur, slab_cache_t, link); |
602 | printf("%s\t%d\t%d\t%d\t%d\t%d\t\t%s\n", cache->name, cache->size, |
613 | printf("%s\t%d\t%d\t%d\t%d\t%d\t%d\t\t%s\n", cache->name, cache->size, |
603 | (1 << cache->order), cache->objects, |
614 | (1 << cache->order), cache->objects, |
604 | atomic_get(&cache->allocated_slabs), |
615 | atomic_get(&cache->allocated_slabs), |
- | 616 | atomic_get(&cache->cached_objs), |
|
605 | atomic_get(&cache->allocated_objs), |
617 | atomic_get(&cache->allocated_objs), |
606 | cache->flags & SLAB_CACHE_SLINSIDE ? "In" : "Out"); |
618 | cache->flags & SLAB_CACHE_SLINSIDE ? "In" : "Out"); |
607 | } |
619 | } |
608 | spinlock_unlock(&slab_cache_lock); |
620 | spinlock_unlock(&slab_cache_lock); |
609 | } |
621 | } |