LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 695|回复: 0

关于内存分配中的一个疑点(2.4.30),请指教,谢谢。

[复制链接]
发表于 2005-8-31 12:26:04 | 显示全部楼层 |阅读模式
在2.4.30的版本中的slab算法中
定义了cache_size的结构如下
static cache_sizes_t cache_sizes[] = {
#if PAGE_SIZE == 4096
        {    32,        NULL, NULL},
#endif
        {    64,        NULL, NULL},
        {   128,        NULL, NULL},
        {   256,        NULL, NULL},
        {   512,        NULL, NULL},
        {  1024,        NULL, NULL},
        {  2048,        NULL, NULL},
        {  4096,        NULL, NULL},
        {  8192,        NULL, NULL},
        { 16384,        NULL, NULL},
        { 32768,        NULL, NULL},
        { 65536,        NULL, NULL},
        {131072,        NULL, NULL},
        {     0,        NULL, NULL}
};
从中我们可以看到最大的对象为131072,需要32页
但是在建立缓存的函数中
kmem_cache_t *
kmem_cache_create (const char *name, size_t size, size_t offset,
        unsigned long flags, void (*ctor)(void*, kmem_cache_t *, unsigned long),
        void (*dtor)(void*, kmem_cache_t *, unsigned long))
{
……

        /* Cal size (in pages) of slabs, and the num of objs per slab.
         * This could be made much more intelligent.  For now, try to avoid
         * using high page-orders for slabs.  When the gfp() funcs are more
         * friendly towards high-order requests, this should be changed.
         */
        do {
                unsigned int break_flag = 0;
cal_wastage:
                kmem_cache_estimate(cachep->gfporder, size, flags,
                                                &left_over, &cachep->num);
                if (break_flag)
                        break;
                if (cachep->gfporder >= MAX_GFP_ORDER)
                        break;
                if (!cachep->num)
                        goto next;
                if (flags & CFLGS_OFF_SLAB && cachep->num > offslab_limit) {
                        /* Oops, this num of objs will cause problems. */
                        cachep->gfporder--;
                        break_flag++;
                        goto cal_wastage;
                }

                /*
                 * Large num of objs is good, but v. large slabs are currently
                 * bad for the gfp()s.
                 */
                if (cachep->gfporder >= slab_break_gfp_order)
                        break;

                if ((left_over*8) <= (PAGE_SIZE<<cachep->gfporder))
                        break;        /* Acceptable internal fragmentation. */
next:
                cachep->gfporder++;
        } while (1);
……
}
再上面的语句中有
                if (cachep->gfporder >= slab_break_gfp_order)
                        break;
也就是cachep->gfporder 的值根据系统内存是否大于32M取
#define        BREAK_GFP_ORDER_HI        2
#define        BREAK_GFP_ORDER_LO        1
static int slab_break_gfp_order = BREAK_GFP_ORDER_LO;
???
如何分配对象为131072的cache????此时cachep->gfporder 的值为5啊。
如何分配页???
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表