admin管理员组文章数量:1660216
/* Cal the num objs, wastage, and bytes left over for a given slab size. */
在页的阶为 gfporder,每个对象大小为size的条件下:
本函数负责计算对象的数目,浪费的空间,以及在所给的slab中剩余的空间。
计算出来后,外层函数评估此时对象个数,浪费的大小是否能够接受,如果不能接受,则
需要调整gfporder,重新调用此函数进行计算。
static void kmem_cache_estimate (unsigned long gfporder, size_t size,int flags, size_t *left_over, unsigned int *num)
{
int i;
size_t wastage = PAGE_SIZE<<gfporder;
size_t extra = 0;
size_t base = 0;
if(!(flags & CFLGS_OFF_SLAB)) {
base = sizeof(slab_t);
extra = sizeof(kmem_bufctl_t);
}
i = 0;
/*-- L1_CACHE_ALIGN 是计算L1 CACHE对齐的
L1_CACHE 有许多线( cache line )每一个线可以同时传输多个字节,比如16,32
如果进行L1 CACHE对齐可以使得对象不占用过多的线,不知道是否可以加快速度??
*/
while(i*size + L1_CACHE_ALIGN(base+i*extra) <= wastage)
i++;
if(i > 0)
i--;
if(i > SLAB_LIMIT)
i = SLAB_LIMIT;
*num = i;
wastage -= i*size;
wastage -= L1_CACHE_ALIGN(base+i*extra);
*left_over = wastage;计算出来的浪费的空间
}
本文标签: cacheestimate
版权声明:本文标题:cache_estimate 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729850249a1215313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论