Changeset c352c2e in mainline for generic/src/mm/slab.c
- Timestamp:
- 2006-02-03T23:16:27Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 81e52f2a
- Parents:
- e1888f9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/mm/slab.c
re1888f9 rc352c2e 93 93 #include <panic.h> 94 94 #include <debug.h> 95 #include <bitops.h> 95 96 96 97 SPINLOCK_INITIALIZE(slab_cache_lock); … … 109 110 */ 110 111 static slab_cache_t *slab_extern_cache; 112 /** Caches for malloc */ 113 static slab_cache_t *malloc_caches[SLAB_MAX_MALLOC_W-SLAB_MIN_MALLOC_W+1]; 114 char *malloc_names[] = { 115 "malloc-8","malloc-16","malloc-32","malloc-64","malloc-128", 116 "malloc-256","malloc-512","malloc-1K","malloc-2K", 117 "malloc-4K","malloc-8K","malloc-16K","malloc-32K", 118 "malloc-64K","malloc-128K" 119 }; 111 120 112 121 /** Slab descriptor */ … … 479 488 { 480 489 int i; 490 int pages; 481 491 482 492 memsetb((__address)cache, sizeof(*cache), 0); … … 508 518 509 519 /* Minimum slab order */ 510 cache->order = (cache->size-1) >> PAGE_WIDTH; 520 pages = ((cache->size-1) >> PAGE_WIDTH) + 1; 521 cache->order = fnzb(pages); 511 522 512 523 while (badness(cache) > SLAB_MAX_BADNESS(cache)) { … … 633 644 /* Disable interrupts to avoid deadlocks with interrupt handlers */ 634 645 ipl = interrupts_disable(); 635 636 if (!(cache->flags & SLAB_CACHE_NOMAGAZINE) )646 647 if (!(cache->flags & SLAB_CACHE_NOMAGAZINE) && CPU) 637 648 result = magazine_obj_get(cache); 638 649 … … 651 662 } 652 663 653 /** Return object to cache */654 void slab_free(slab_cache_t *cache, void *obj)664 /** Return object to cache, use slab if known */ 665 static void _slab_free(slab_cache_t *cache, void *obj, slab_t *slab) 655 666 { 656 667 ipl_t ipl; … … 659 670 660 671 if ((cache->flags & SLAB_CACHE_NOMAGAZINE) \ 672 || !CPU \ 661 673 || magazine_obj_put(cache, obj)) { 662 674 663 675 spinlock_lock(&cache->lock); 664 slab_obj_destroy(cache, obj, NULL);676 slab_obj_destroy(cache, obj, slab); 665 677 spinlock_unlock(&cache->lock); 666 678 } 667 679 interrupts_restore(ipl); 668 680 atomic_dec(&cache->allocated_objs); 681 } 682 683 /** Return slab object to cache */ 684 void slab_free(slab_cache_t *cache, void *obj) 685 { 686 _slab_free(cache,obj,NULL); 669 687 } 670 688 … … 711 729 void slab_cache_init(void) 712 730 { 731 int i, size; 732 713 733 /* Initialize magazine cache */ 714 734 _slab_cache_create(&mag_cache, … … 732 752 733 753 /* Initialize structures for malloc */ 734 } 754 for (i=0, size=(1<<SLAB_MIN_MALLOC_W); 755 i < (SLAB_MAX_MALLOC_W-SLAB_MIN_MALLOC_W+1); 756 i++, size <<= 1) { 757 malloc_caches[i] = slab_cache_create(malloc_names[i], 758 size, 0, 759 NULL,NULL,0); 760 } 761 } 762 763 /**************************************/ 764 /* kalloc/kfree functions */ 765 void * kalloc(unsigned int size, int flags) 766 { 767 int idx; 768 769 ASSERT( size && size <= (1 << SLAB_MAX_MALLOC_W)); 770 771 if (size < (1 << SLAB_MIN_MALLOC_W)) 772 size = (1 << SLAB_MIN_MALLOC_W); 773 774 idx = fnzb(size-1) - SLAB_MIN_MALLOC_W + 1; 775 776 return slab_alloc(malloc_caches[idx], flags); 777 } 778 779 780 void kfree(void *obj) 781 { 782 slab_t *slab = obj2slab(obj); 783 784 _slab_free(slab->cache, obj, slab); 785 }
Note:
See TracChangeset
for help on using the changeset viewer.