總結完了slab創建、對象分配、對象釋放,在這裡再看看slab的銷毀。銷毀slab很簡單,由函數slab_destroy()實現。
相關閱讀:
http://www.linuxidc.com/Linux/2012-01/51241.htm
http://www.linuxidc.com/Linux/2012-01/51240.htm
http://www.linuxidc.com/Linux/2012-01/51239.htm
http://www.linuxidc.com/Linux/2012-01/51242.htm
- /**
- * slab_destroy - destroy and release all objects in a slab
- * @cachep: cache pointer being destroyed
- * @slabp: slab pointer being destroyed
- *
- * Destroy all the objs in a slab, and release the mem back to the system.
- * Before calling the slab must have been unlinked from the cache. The
- * cache-lock is not held/needed.
- */
- /*銷毀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);
- }
- }
其中,涉及到的其他函數在前面相應的地方已經做了分析。