• /**
  •  * 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.
  •  */
  • static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp)
  • {
  •     /* slabp->s_mem记录的是slab对象的起始地址,由于着色偏移,所以需要减去colouroff指向slab首页面的地址 */
  •     void *addr = slabp->s_mem - slabp->colouroff;

  •     slab_destroy_debugcheck(cachep, slabp);
  •     /* 判断一下使用那种销毁方式,rcu是多核中的一种同步机制 */
  •     if (unlikely(cachep->flags & SLAB_DESTROY_BY_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管理对象内置的话,随着页面一起释放了 */
  •         kmem_freepages(cachep, addr);
  •         /* 如果slab管理对象是外置的花,需要单独释放一下 */
  •         if (OFF_SLAB(cachep))
  •             kmem_cache_free(cachep->slabp_cache, slabp);
  •     }
  • }