免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2909 | 回复: 1
打印 上一主题 下一主题

kmem_cache_init函数问题 [复制链接]

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-09 22:31 |只看该作者 |倒序浏览
30可用积分
这个函数看得我的很晕,说出自己理解,希望不对的地方请高手指正
  1. 529static struct arraycache_init initarray_cache __initdata =
  2. 530        { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
  3. 531static struct arraycache_init initarray_generic =
  4. 532        { { 0, BOOT_CPUCACHE_ENTRIES, 1, 0} };


  5. cache_cache.array[smp_processor_id()] = &initarray_cache.cache;
复制代码
kmem_cache_init的流程是不是:

先用一个静态定义cache即initarray_cache.cache充当cache_cache的local cache

然后create kmalloc caches使用下边一个循环
  1. 797        while (sizes->cs_size) {
  2. 798                /* For performance, all the general caches are L1 aligned.
  3. 799                 * This should be particularly beneficial on SMP boxes, as it
  4. 800                 * eliminates "false sharing".
  5. 801                 * Note for systems short on memory removing the alignment will
  6. 802                 * allow tighter packing of the smaller caches. */
  7. 803                sizes->cs_cachep = kmem_cache_create(names->name,
  8. 804                        sizes->cs_size, ARCH_KMALLOC_MINALIGN,
  9. 805                        (ARCH_KMALLOC_FLAGS | SLAB_PANIC), NULL, NULL);
  10. 806
  11. 807                /* Inc off-slab bufctl limit until the ceiling is hit. */
  12. 808                if (!(OFF_SLAB(sizes->cs_cachep))) {
  13. 809                        offslab_limit = sizes->cs_size-sizeof(struct slab);
  14. 810                        offslab_limit /= sizeof(kmem_bufctl_t);
  15. 811                }
  16. 812
  17. 813                sizes->cs_dmacachep = kmem_cache_create(names->name_dma,
  18. 814                        sizes->cs_size, ARCH_KMALLOC_MINALIGN,
  19. 815                        (ARCH_KMALLOC_FLAGS | SLAB_CACHE_DMA | SLAB_PANIC),
  20. 816                        NULL, NULL);
  21. 817
  22. 818                sizes++;
  23. 819                names++;
  24. 820        }
复制代码
第一次循环中,第803行,为malloc_sizes创建各个cache,此时使用下边这个设置第一个local cache
  1. if (g_cpucache_up == NONE) {
  2. 1426          /* Note: the first kmem_cache_create must create
  3. 1427           * the cache that's used by kmalloc(24), otherwise
  4. 1428           * the creation of further caches will BUG().
  5. 1429           */
  6. 1430        cachep->array[smp_processor_id()] = &initarray_generic.cache;
  7. 1431        g_cpucache_up = PARTIAL;
复制代码
而执行到813行的时候,已经使用kmalloc,从刚才的那个initarray_generic.cache分配描述符了:
  1. 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

论坛徽章:
0
2 [报告]
发表于 2011-11-09 22:41 |只看该作者
  1. /*
  2. * Initialisation.  Called after the page allocator have been initialised and
  3. * before smp_init().
  4. */
  5. void __init kmem_cache_init(void)
  6. {
  7.         ***
  8.         /* Bootstrap is tricky, because several objects are allocated
  9.          * from caches that do not exist yet:
  10.          * 1) initialize the cache_cache cache: it contains the struct
  11.          *    kmem_cache structures of all caches, except cache_cache itself:
  12.          *    cache_cache is statically allocated.
  13.          *    Initially an __init data area is used for the head array and the
  14.          *    kmem_list3 structures, it's replaced with a kmalloc allocated
  15.          *    array at the end of the bootstrap.
  16.          * 2) Create the first kmalloc cache.
  17.          *    The struct kmem_cache for the new cache is allocated normally.
  18.          *    An __init data area is used for the head array.
  19.          * 3) Create the remaining kmalloc caches, with minimally sized
  20.          *    head arrays.
  21.          * 4) Replace the __init data head arrays for cache_cache and the first
  22.          *    kmalloc cache with kmalloc allocated arrays.
  23.          * 5) Replace the __init data for kmem_list3 for cache_cache and
  24.          *    the other cache's with kmalloc allocated memory.
  25.          * 6) Resize the head arrays of the kmalloc caches to their final sizes.
  26.          */
复制代码
2.6.35.7代码中的注释,其后还有一个
  1. void __init kmem_cache_init_late(void)
复制代码
函数
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP