Changeset 8e1ea655 in mainline for generic/src/mm/slab.c
- Timestamp:
- 2006-02-05T21:51:19Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c585827
- Parents:
- 5c9a08b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/mm/slab.c
r5c9a08b r8e1ea655 113 113 /** Cache for cache descriptors */ 114 114 static slab_cache_t slab_cache_cache; 115 115 /** Cache for magcache structure from cache_t */ 116 static slab_cache_t *cpu_cache = NULL; 116 117 /** Cache for external slab descriptors 117 118 * This time we want per-cpu cache, so do not make it static … … 235 236 236 237 ASSERT(slab->cache == cache); 237 ASSERT(slab->available < cache->objects);238 238 239 239 if (cache->destructor) … … 241 241 242 242 spinlock_lock(&cache->slablock); 243 ASSERT(slab->available < cache->objects); 243 244 244 245 *((int *)obj) = slab->nextavail; … … 537 538 } 538 539 540 /** 541 * Initialize mag_cache structure in slab cache 542 */ 543 static void make_magcache(slab_cache_t *cache) 544 { 545 int i; 546 547 ASSERT(cpu_cache); 548 cache->mag_cache = slab_alloc(cpu_cache, 0); 549 for (i=0; i < config.cpu_count; i++) { 550 memsetb((__address)&cache->mag_cache[i], 551 sizeof(cache->mag_cache[i]), 0); 552 spinlock_initialize(&cache->mag_cache[i].lock, 553 "slab_maglock_cpu"); 554 } 555 } 556 539 557 /** Initialize allocated memory as a slab cache */ 540 558 static void … … 547 565 int flags) 548 566 { 549 int i;550 567 int pages; 551 568 ipl_t ipl; … … 569 586 spinlock_initialize(&cache->slablock, "slab_lock"); 570 587 spinlock_initialize(&cache->maglock, "slab_maglock"); 571 if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) { 572 for (i=0; i < config.cpu_count; i++) { 573 memsetb((__address)&cache->mag_cache[i], 574 sizeof(cache->mag_cache[i]), 0); 575 spinlock_initialize(&cache->mag_cache[i].lock, 576 "slab_maglock_cpu"); 577 } 578 } 588 if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) 589 make_magcache(cache); 579 590 580 591 /* Compute slab sizes, object counts in slabs etc. */ … … 697 708 panic("Destroying cache that is not empty."); 698 709 710 if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) 711 slab_free(cpu_cache, cache->mag_cache); 699 712 slab_free(&slab_cache_cache, cache); 700 713 } … … 811 824 _slab_cache_create(&slab_cache_cache, 812 825 "slab_cache", 813 sizeof(slab_cache_cache) + config.cpu_count*sizeof(slab_cache_cache.mag_cache[0]),826 sizeof(slab_cache_cache), 814 827 sizeof(__address), 815 828 NULL, NULL, … … 819 832 sizeof(slab_t), 820 833 0, NULL, NULL, 821 SLAB_CACHE_SLINSIDE );834 SLAB_CACHE_SLINSIDE | SLAB_CACHE_MAGDEFERRED); 822 835 823 836 /* Initialize structures for malloc */ … … 827 840 malloc_caches[i] = slab_cache_create(malloc_names[i], 828 841 size, 0, 829 NULL,NULL, 0);842 NULL,NULL, SLAB_CACHE_MAGDEFERRED); 830 843 } 831 844 #ifdef CONFIG_DEBUG … … 834 847 } 835 848 849 /** Enable cpu_cache 850 * 851 * Kernel calls this function, when it knows the real number of 852 * processors. 853 * Allocate slab for cpucache and enable it on all existing 854 * slabs that are SLAB_CACHE_MAGDEFERRED 855 */ 856 void slab_enable_cpucache(void) 857 { 858 link_t *cur; 859 slab_cache_t *s; 860 861 cpu_cache = slab_cache_create("magcpucache", 862 sizeof(slab_mag_cache_t) * config.cpu_count, 863 0, NULL, NULL, 864 SLAB_CACHE_NOMAGAZINE); 865 spinlock_lock(&slab_cache_lock); 866 867 for (cur=slab_cache_list.next; cur != &slab_cache_list;cur=cur->next){ 868 s = list_get_instance(cur, slab_cache_t, link); 869 if ((s->flags & SLAB_CACHE_MAGDEFERRED) != SLAB_CACHE_MAGDEFERRED) 870 continue; 871 make_magcache(s); 872 s->flags &= ~SLAB_CACHE_MAGDEFERRED; 873 } 874 875 spinlock_unlock(&slab_cache_lock); 876 } 877 836 878 /**************************************/ 837 879 /* kalloc/kfree functions */
Note:
See TracChangeset
for help on using the changeset viewer.