手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux Slab分配器(七)--销毁缓存

[日期:2012-06-19] 来源:Linux社区  作者:vanbreaker [字体:大 中 小]

drain_cpu_caches()的最终落脚在free_block()函数上,该函数在前面已做过分析,在此不再列出

  1. static int drain_freelist(struct kmem_cache *cache,  
  2.             struct kmem_list3 *l3, int tofree)  
  3. {  
  4.     struct list_head *p;  
  5.     int nr_freed;  
  6.     struct slab *slabp;  
  7.   
  8.     nr_freed = 0;  
  9.     /*slab中的对象还未释放完并且free链表不为空*/  
  10.     while (nr_freed < tofree && !list_empty(&l3->slabs_free)) {  
  11.   
  12.         spin_lock_irq(&l3->list_lock);  
  13.         p = l3->slabs_free.prev;  
  14.         if (p == &l3->slabs_free) {/*链表中已无元素*/  
  15.             spin_unlock_irq(&l3->list_lock);  
  16.             goto out;  
  17.         }  
  18.         /*从free链表中取出一个slab*/  
  19.         slabp = list_entry(p, struct slab, list);  
  20. #if DEBUG   
  21.         BUG_ON(slabp->inuse);  
  22. #endif   
  23.         /*从链表中删除*/  
  24.         list_del(&slabp->list);  
  25.         /* 
  26.          * Safe to drop the lock. The slab is no longer linked 
  27.          * to the cache. 
  28.          */  
  29.          /*空闲对象数量总数减去num*/  
  30.         l3->free_objects -= cache->num;  
  31.         spin_unlock_irq(&l3->list_lock);  
  32.         /*销毁slab*/  
  33.         slab_destroy(cache, slabp);  
  34.         nr_freed++;  
  35.     }  
  36. out:  
  37.     return nr_freed;  
  38. }  

slab_destroy()函数已在前文中分析

  1. static void __kmem_cache_destroy(struct kmem_cache *cachep)  
  2. {  
  3.     int i;  
  4.     struct kmem_list3 *l3;  
  5.   
  6.     /*释放存储本地高速缓存描述符的对象*/  
  7.     for_each_online_cpu(i)  
  8.         kfree(cachep->array[i]);  
  9.   
  10.     /* NUMA: free the list3 structures */  
  11.     for_each_online_node(i) {  
  12.         l3 = cachep->nodelists[i];  
  13.         if (l3) {  
  14.             /*释放存储共享本地高速缓存描述符的对象*/  
  15.             kfree(l3->shared);  
  16.             /*释放存储alien本地高速缓存描述符的对象*/  
  17.             free_alien_cache(l3->alien);  
  18.             /*释放存储kmem_list3描述符的对象*/  
  19.             kfree(l3);  
  20.         }  
  21.     }  
  22.     /*释放存储缓存描述符的对象*/  
  23.     kmem_cache_free(&cache_cache, cachep);  
  24. }  
linux
相关资讯       Linux内存管理 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款