Welcome 微信登录

首页 / 操作系统 / Linux / Linux内存管理之slab机制(销毁slab)

总结完了slab创建、对象分配、对象释放,在这里再看看slab的销毁。销毁slab很简单,由函数slab_destroy()实现。相关阅读:http://www.linuxidc.com/Linux/2012-01/51241.htmhttp://www.linuxidc.com/Linux/2012-01/51240.htmhttp://www.linuxidc.com/Linux/2012-01/51239.htmhttp://www.linuxidc.com/Linux/2012-01/51242.htm
  1. /** 
  2.  * slab_destroy - destroy and release all objects in a slab 
  3.  * @cachep: cache pointer being destroyed 
  4.  * @slabp: slab pointer being destroyed 
  5.  * 
  6.  * Destroy all the objs in a slab, and release the mem back to the system. 
  7.  * Before calling the slab must have been unlinked from the cache.  The 
  8.  * cache-lock is not held/needed. 
  9.  */  
  10.  /*销毁slab,需要释放slab管理对象和slab对象。*/  
  11. static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp)  
  12. {  
  13.     /* 获得slab首页面的虚拟地址 */  
  14.     void *addr = slabp->s_mem - slabp->colouroff;  
  15.     /*调试用*/  
  16.     slab_destroy_debugcheck(cachep, slabp);  
  17.     if (unlikely(cachep->flags & SLAB_DESTROY_BY_RCU)) {  
  18.          /* rcu方式释放,暂时不做分析,主要是做并行优化 */  
  19.         struct slab_rcu *slab_rcu;  
  20.   
  21.         slab_rcu = (struct slab_rcu *)slabp;  
  22.         slab_rcu->cachep = cachep;  
  23.         slab_rcu->addr = addr;  
  24.         call_rcu(&slab_rcu->head, kmem_rcu_free);  
  25.     } else {  
  26.         /* 释放slab占用的页面到伙伴系统中。如果是内置式, 
  27.         slab管理对象和slab对象在一起,可以同时释放。*/  
  28.         kmem_freepages(cachep, addr);  
  29.         /* 外置式,还需释放slab管理对象 */  
  30.         if (OFF_SLAB(cachep))  
  31.             kmem_cache_free(cachep->slabp_cache, slabp);  
  32.     }  
  33. }  
其中,涉及到的其他函数在前面相应的地方已经做了分析。Linux内存管理之slab机制(释放对象)Linux 命令的参数顺序与执行相关资讯      Linux内存 
  • Linux内存管理精述  (01月18日)
  • 在 Linux x86-32 模式下分析内存映  (02/08/2015 07:25:25)
  • Linux下如何释放cache内存  (02/02/2015 13:36:34)
  • 在 Linux x86-64 模式下分析内存映  (02/08/2015 07:33:09)
  • Linux系统入门学习:如何检查Linux  (02/06/2015 10:36:00)
  • Linux内存映射  (04/04/2014 13:21:48)
本文评论 查看全部评论 (0)
表情: 姓名: 字数