- 论坛徽章:
- 16
|
30可用积分
这个函数看得我的很晕,说出自己理解,希望不对的地方请高手指正- 529static struct arraycache_init initarray_cache __initdata =
- 530 { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
- 531static struct arraycache_init initarray_generic =
- 532 { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
- cache_cache.array[smp_processor_id()] = &initarray_cache.cache;
复制代码 kmem_cache_init的流程是不是:
先用一个静态定义cache即initarray_cache.cache充当cache_cache的local cache
然后create kmalloc caches使用下边一个循环- 797 while (sizes->cs_size) {
- 798 /* For performance, all the general caches are L1 aligned.
- 799 * This should be particularly beneficial on SMP boxes, as it
- 800 * eliminates "false sharing".
- 801 * Note for systems short on memory removing the alignment will
- 802 * allow tighter packing of the smaller caches. */
- 803 sizes->cs_cachep = kmem_cache_create(names->name,
- 804 sizes->cs_size, ARCH_KMALLOC_MINALIGN,
- 805 (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL);
- 806
- 807 /* Inc off-slab bufctl limit until the ceiling is hit. */
- 808 if (!(OFF_SLAB(sizes->cs_cachep))) {
- 809 offslab_limit = sizes->cs_size-sizeof(struct slab);
- 810 offslab_limit /= sizeof(kmem_bufctl_t);
- 811 }
- 812
- 813 sizes->cs_dmacachep = kmem_cache_create(names->name_dma,
- 814 sizes->cs_size, ARCH_KMALLOC_MINALIGN,
- 815 (ARCH_KMALLOC_FLAGS | SLAB_CACHE_DMA | SLAB_PANIC),
- 816 NULL, NULL);
- 817
- 818 sizes++;
- 819 names++;
- 820 }
复制代码 第一次循环中,第803行,为malloc_sizes创建各个cache,此时使用下边这个设置第一个local cache- if (g_cpucache_up == NONE) {
- 1426 /* Note: the first kmem_cache_create must create
- 1427 * the cache that's used by kmalloc(24), otherwise
- 1428 * the creation of further caches will BUG().
- 1429 */
- 1430 cachep->array[smp_processor_id()] = &initarray_generic.cache;
- 1431 g_cpucache_up = PARTIAL;
复制代码 而执行到813行的时候,已经使用kmalloc,从刚才的那个initarray_generic.cache分配描述符了:- cachep->array[smp_processor_id()] = kmalloc(sizeof(struct arraycache_init),GFP_KERNEL);
复制代码 直到while循环结束都是通过kmalloc从initarray_generic.cache分配描述符
这样用于kmalloc的普通高速缓存cache_sizes就建立好了。下一步是将刚才的那两个静态定义的local cache重新用kmalloc分配
然后调用enable_cpucache函数中为每个cache重新建立local cache |
|