Chinaunix首页 | 论坛 | 博客
  • 博客访问: 145503
  • 博文数量: 38
  • 博客积分: 1315
  • 博客等级: 准尉
  • 技术积分: 850
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-06 16:19
文章分类

全部博文(38)

文章存档

2011年(38)

分类: LINUX

2011-03-03 16:48:10

本文讲解使用完slab后,如何销毁它。

slab_destroy

销毁slab,需要释放slab管理对象和slab对象。

static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp)

{

       /* 获得slab首页面的虚拟地址 */

       void *addr = slabp->s_mem - slabp->colouroff;

 

       slab_destroy_debugcheck(cachep, slabp);

       if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) {

                      /* rcu方式释放,请参阅相关文档 */

                      struct slab_rcu *slab_rcu;

 

                      slab_rcu = (struct slab_rcu *)slabp;

                      slab_rcu->cachep = cachep;

                      slab_rcu->addr = addr;

                      call_rcu(&slab_rcu->head, kmem_rcu_free);

       } else {

/* 释放slab占用的页面。如果是内置式,slab管理对象和slab对象在一起,可以同时释放。*/

                      kmem_freepages(cachep, addr);

                      /* 外置式,还需释放slab管理对象 */

                      if (OFF_SLAB(cachep))

                                    kmem_cache_free(cachep->slabp_cache, slabp);

       }

}

 

阅读(2140) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~