Chinaunix首页 | 论坛 | 博客
  • 博客访问: 316365
  • 博文数量: 78
  • 博客积分: 1322
  • 博客等级: 中尉
  • 技术积分: 680
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-14 13:24
文章分类
文章存档

2012年(20)

2011年(55)

2010年(3)

分类: LINUX

2011-10-12 22:43:59

 
void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
{
      void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0));
     
      return ret;
}
     函数kmem_cache_alloc作为从cache中分配对象的API,直接调用__cache_alloc函数完成实际的分配函数。__cache_alloc函数完成安全检查后调用__do_cache_alloc函数进行对象的分配。
     __do_cache_alloc调用 ____cache_alloc函数在当前节点(Node)分配对象。
static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags)
{
     void *objp;
     struct array_cache *ac;
     check_irq_off();
     ac = cpu_cache_get(cachep);
     if (likely(ac->avail))
     {
         STATS_INC_ALLOCHIT(cachep);
         ac->touched = 1;
         objp = ac->entry[--ac->avail];
     }
     else
     {
         STATS_INC_ALLOCMISS(cachep);
         objp = cache_alloc_refill(cachep, flags);
     }
     ......
     return objp;
}
    ____cache_alloc首先确保操作是在中断的环境中进行。接着判断
阅读(4831) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~